@shop-on/theme-runtime 0.5.0 → 0.6.0
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/bytes.d.ts +18 -0
- package/dist/bytes.js +33 -0
- package/package.json +3 -2
package/dist/bytes.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/bytes.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Binary (1024-step) sizes, one decimal, with a bare `.0` trimmed off.
|
|
4
|
+
*
|
|
5
|
+
* The GB tier is not optional decoration: plan storage ceilings are 5 GiB and
|
|
6
|
+
* 50 GiB, and without it a plan card would advertise "5120.0 MB". The trim
|
|
7
|
+
* matches the API's own copy — `plan_limit_error` formats the same ceilings
|
|
8
|
+
* with `number_to_human_size`, which says "5 GB", so a "5.0 GB" here would
|
|
9
|
+
* contradict the refusal toast the merchant is reading it next to. A real
|
|
10
|
+
* fraction keeps its digit ("1.5 GB").
|
|
11
|
+
*
|
|
12
|
+
* The unit is picked from the ROUNDED value, not the raw one. Deciding the tier
|
|
13
|
+
* first lets any size within half a rounding step of a boundary print a unit
|
|
14
|
+
* that already carried: 1048575 B is under 1 MiB, but at one decimal it is
|
|
15
|
+
* "1024.0 KB" — a KB figure no one writes.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatBytes(bytes: number): string;
|
|
18
|
+
//#endregion
|
package/dist/bytes.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/bytes.ts
|
|
2
|
+
const BYTE_UNITS = [
|
|
3
|
+
"B",
|
|
4
|
+
"KB",
|
|
5
|
+
"MB",
|
|
6
|
+
"GB"
|
|
7
|
+
];
|
|
8
|
+
/**
|
|
9
|
+
* Binary (1024-step) sizes, one decimal, with a bare `.0` trimmed off.
|
|
10
|
+
*
|
|
11
|
+
* The GB tier is not optional decoration: plan storage ceilings are 5 GiB and
|
|
12
|
+
* 50 GiB, and without it a plan card would advertise "5120.0 MB". The trim
|
|
13
|
+
* matches the API's own copy — `plan_limit_error` formats the same ceilings
|
|
14
|
+
* with `number_to_human_size`, which says "5 GB", so a "5.0 GB" here would
|
|
15
|
+
* contradict the refusal toast the merchant is reading it next to. A real
|
|
16
|
+
* fraction keeps its digit ("1.5 GB").
|
|
17
|
+
*
|
|
18
|
+
* The unit is picked from the ROUNDED value, not the raw one. Deciding the tier
|
|
19
|
+
* first lets any size within half a rounding step of a boundary print a unit
|
|
20
|
+
* that already carried: 1048575 B is under 1 MiB, but at one decimal it is
|
|
21
|
+
* "1024.0 KB" — a KB figure no one writes.
|
|
22
|
+
*/
|
|
23
|
+
function formatBytes(bytes) {
|
|
24
|
+
let value = bytes;
|
|
25
|
+
let unit = 0;
|
|
26
|
+
while (unit < BYTE_UNITS.length - 1 && Number(value.toFixed(1)) >= 1024) {
|
|
27
|
+
value /= 1024;
|
|
28
|
+
unit += 1;
|
|
29
|
+
}
|
|
30
|
+
return `${value.toFixed(1).replace(/\.0$/, "")} ${BYTE_UNITS[unit]}`;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { formatBytes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shop-on/theme-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "SEE LICENSE IN dist/LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./dist/index.js",
|
|
11
11
|
"./badge-tags": "./dist/badge-tags.js",
|
|
12
|
+
"./bytes": "./dist/bytes.js",
|
|
12
13
|
"./cart-discounts": "./dist/cart-discounts.js",
|
|
13
14
|
"./cart-note": "./dist/cart-note.js",
|
|
14
15
|
"./color": "./dist/color.js",
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"thumbhash": "0.1.1",
|
|
38
|
-
"@shop-on/theme-contract": "0.
|
|
39
|
+
"@shop-on/theme-contract": "0.6.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/node": "26.6.5",
|