@zag-js/i18n-utils 1.24.1 → 1.24.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +6 -7
- package/dist/index.mjs +6 -7
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -11,7 +11,32 @@ interface FilterOptions extends Intl.CollatorOptions {
|
|
|
11
11
|
declare function createFilter(options?: FilterOptions): FilterReturn;
|
|
12
12
|
|
|
13
13
|
interface FormatBytesOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The number of significant digits to include in the formatted output.
|
|
16
|
+
* @default 3
|
|
17
|
+
*/
|
|
18
|
+
precision?: number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The unit system to use for calculations.
|
|
21
|
+
* - "binary": Uses 1024 as the base (e.g., 1 KiB = 1024 bytes)
|
|
22
|
+
* - "decimal": Uses 1000 as the base (e.g., 1 KB = 1000 bytes)
|
|
23
|
+
* @default "decimal"
|
|
24
|
+
*/
|
|
25
|
+
unitSystem?: "binary" | "decimal" | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The type of unit to format the value as.
|
|
28
|
+
* - "bit": Format as bits (b)
|
|
29
|
+
* - "byte": Format as bytes (B)
|
|
30
|
+
* @default "byte"
|
|
31
|
+
*/
|
|
14
32
|
unit?: "bit" | "byte" | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The display style for the unit.
|
|
35
|
+
* - "long": Full unit name (e.g., "kilobytes")
|
|
36
|
+
* - "short": Abbreviated unit (e.g., "KB")
|
|
37
|
+
* - "narrow": Compact unit (e.g., "K")
|
|
38
|
+
* @default "short"
|
|
39
|
+
*/
|
|
15
40
|
unitDisplay?: "long" | "short" | "narrow" | undefined;
|
|
16
41
|
}
|
|
17
42
|
declare const formatBytes: (bytes: number, locale?: string, options?: FormatBytesOptions) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,32 @@ interface FilterOptions extends Intl.CollatorOptions {
|
|
|
11
11
|
declare function createFilter(options?: FilterOptions): FilterReturn;
|
|
12
12
|
|
|
13
13
|
interface FormatBytesOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The number of significant digits to include in the formatted output.
|
|
16
|
+
* @default 3
|
|
17
|
+
*/
|
|
18
|
+
precision?: number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The unit system to use for calculations.
|
|
21
|
+
* - "binary": Uses 1024 as the base (e.g., 1 KiB = 1024 bytes)
|
|
22
|
+
* - "decimal": Uses 1000 as the base (e.g., 1 KB = 1000 bytes)
|
|
23
|
+
* @default "decimal"
|
|
24
|
+
*/
|
|
25
|
+
unitSystem?: "binary" | "decimal" | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The type of unit to format the value as.
|
|
28
|
+
* - "bit": Format as bits (b)
|
|
29
|
+
* - "byte": Format as bytes (B)
|
|
30
|
+
* @default "byte"
|
|
31
|
+
*/
|
|
14
32
|
unit?: "bit" | "byte" | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The display style for the unit.
|
|
35
|
+
* - "long": Full unit name (e.g., "kilobytes")
|
|
36
|
+
* - "short": Abbreviated unit (e.g., "KB")
|
|
37
|
+
* - "narrow": Compact unit (e.g., "K")
|
|
38
|
+
* @default "short"
|
|
39
|
+
*/
|
|
15
40
|
unitDisplay?: "long" | "short" | "narrow" | undefined;
|
|
16
41
|
}
|
|
17
42
|
declare const formatBytes: (bytes: number, locale?: string, options?: FormatBytesOptions) => string;
|
package/dist/index.js
CHANGED
|
@@ -78,18 +78,17 @@ function formatNumber(v, locale, options = {}) {
|
|
|
78
78
|
var bitPrefixes = ["", "kilo", "mega", "giga", "tera"];
|
|
79
79
|
var bytePrefixes = ["", "kilo", "mega", "giga", "tera", "peta"];
|
|
80
80
|
var formatBytes = (bytes, locale = "en-US", options = {}) => {
|
|
81
|
-
if (isNaN(bytes)) return "";
|
|
81
|
+
if (Number.isNaN(bytes)) return "";
|
|
82
82
|
if (bytes === 0) return "0 B";
|
|
83
|
-
const { unit = "byte", unitDisplay = "short" } = options;
|
|
83
|
+
const { unitSystem = "decimal", precision = 3, unit = "byte", unitDisplay = "short" } = options;
|
|
84
|
+
const factor = unitSystem === "binary" ? 1024 : 1e3;
|
|
84
85
|
const prefix = unit === "bit" ? bitPrefixes : bytePrefixes;
|
|
85
86
|
const index = Math.max(0, Math.min(Math.floor(Math.log10(bytes) / 3), prefix.length - 1));
|
|
86
|
-
const
|
|
87
|
-
const _unitDisplay = unitDisplay || "short";
|
|
88
|
-
const v = parseFloat((bytes / Math.pow(1e3, index)).toPrecision(3));
|
|
87
|
+
const v = parseFloat((bytes / Math.pow(factor, index)).toPrecision(precision));
|
|
89
88
|
return formatNumber(v, locale, {
|
|
90
89
|
style: "unit",
|
|
91
|
-
unit:
|
|
92
|
-
unitDisplay
|
|
90
|
+
unit: prefix[index] + unit,
|
|
91
|
+
unitDisplay
|
|
93
92
|
});
|
|
94
93
|
};
|
|
95
94
|
|
package/dist/index.mjs
CHANGED
|
@@ -76,18 +76,17 @@ function formatNumber(v, locale, options = {}) {
|
|
|
76
76
|
var bitPrefixes = ["", "kilo", "mega", "giga", "tera"];
|
|
77
77
|
var bytePrefixes = ["", "kilo", "mega", "giga", "tera", "peta"];
|
|
78
78
|
var formatBytes = (bytes, locale = "en-US", options = {}) => {
|
|
79
|
-
if (isNaN(bytes)) return "";
|
|
79
|
+
if (Number.isNaN(bytes)) return "";
|
|
80
80
|
if (bytes === 0) return "0 B";
|
|
81
|
-
const { unit = "byte", unitDisplay = "short" } = options;
|
|
81
|
+
const { unitSystem = "decimal", precision = 3, unit = "byte", unitDisplay = "short" } = options;
|
|
82
|
+
const factor = unitSystem === "binary" ? 1024 : 1e3;
|
|
82
83
|
const prefix = unit === "bit" ? bitPrefixes : bytePrefixes;
|
|
83
84
|
const index = Math.max(0, Math.min(Math.floor(Math.log10(bytes) / 3), prefix.length - 1));
|
|
84
|
-
const
|
|
85
|
-
const _unitDisplay = unitDisplay || "short";
|
|
86
|
-
const v = parseFloat((bytes / Math.pow(1e3, index)).toPrecision(3));
|
|
85
|
+
const v = parseFloat((bytes / Math.pow(factor, index)).toPrecision(precision));
|
|
87
86
|
return formatNumber(v, locale, {
|
|
88
87
|
style: "unit",
|
|
89
|
-
unit:
|
|
90
|
-
unitDisplay
|
|
88
|
+
unit: prefix[index] + unit,
|
|
89
|
+
unitDisplay
|
|
91
90
|
});
|
|
92
91
|
};
|
|
93
92
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/i18n-utils",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.2",
|
|
4
4
|
"description": "Interationalization utilities for Zag.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"clean-package": "../../../clean-package.config.json",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@zag-js/dom-query": "1.24.
|
|
27
|
+
"@zag-js/dom-query": "1.24.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"clean-package": "2.2.0",
|