@zag-js/i18n-utils 1.25.0 → 1.26.1

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.js CHANGED
@@ -83,9 +83,17 @@ var formatBytes = (bytes, locale = "en-US", options = {}) => {
83
83
  const { unitSystem = "decimal", precision = 3, unit = "byte", unitDisplay = "short" } = options;
84
84
  const factor = unitSystem === "binary" ? 1024 : 1e3;
85
85
  const prefix = unit === "bit" ? bitPrefixes : bytePrefixes;
86
- const index = Math.max(0, Math.min(Math.floor(Math.log10(bytes) / 3), prefix.length - 1));
87
- const v = parseFloat((bytes / Math.pow(factor, index)).toPrecision(precision));
88
- return formatNumber(v, locale, {
86
+ const isNegative = bytes < 0;
87
+ const absoluteBytes = Math.abs(bytes);
88
+ let value = absoluteBytes;
89
+ let index = 0;
90
+ while (value >= factor && index < prefix.length - 1) {
91
+ value /= factor;
92
+ index++;
93
+ }
94
+ const v = parseFloat(value.toPrecision(precision));
95
+ const finalValue = isNegative ? -v : v;
96
+ return formatNumber(finalValue, locale, {
89
97
  style: "unit",
90
98
  unit: prefix[index] + unit,
91
99
  unitDisplay
package/dist/index.mjs CHANGED
@@ -81,9 +81,17 @@ var formatBytes = (bytes, locale = "en-US", options = {}) => {
81
81
  const { unitSystem = "decimal", precision = 3, unit = "byte", unitDisplay = "short" } = options;
82
82
  const factor = unitSystem === "binary" ? 1024 : 1e3;
83
83
  const prefix = unit === "bit" ? bitPrefixes : bytePrefixes;
84
- const index = Math.max(0, Math.min(Math.floor(Math.log10(bytes) / 3), prefix.length - 1));
85
- const v = parseFloat((bytes / Math.pow(factor, index)).toPrecision(precision));
86
- return formatNumber(v, locale, {
84
+ const isNegative = bytes < 0;
85
+ const absoluteBytes = Math.abs(bytes);
86
+ let value = absoluteBytes;
87
+ let index = 0;
88
+ while (value >= factor && index < prefix.length - 1) {
89
+ value /= factor;
90
+ index++;
91
+ }
92
+ const v = parseFloat(value.toPrecision(precision));
93
+ const finalValue = isNegative ? -v : v;
94
+ return formatNumber(finalValue, locale, {
87
95
  style: "unit",
88
96
  unit: prefix[index] + unit,
89
97
  unitDisplay
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/i18n-utils",
3
- "version": "1.25.0",
3
+ "version": "1.26.1",
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.25.0"
27
+ "@zag-js/dom-query": "1.26.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "clean-package": "2.2.0",