@wallarm-org/design-system 1.2.0 → 1.4.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/components/FormatNumber/FormatNumber.d.ts +32 -0
- package/dist/components/FormatNumber/FormatNumber.js +122 -0
- package/dist/components/FormatNumber/index.d.ts +1 -0
- package/dist/components/FormatNumber/index.js +1 -0
- package/dist/components/Indicator/Indicator.d.ts +12 -0
- package/dist/components/Indicator/Indicator.js +14 -0
- package/dist/components/Indicator/classes.d.ts +4 -0
- package/dist/components/Indicator/classes.js +22 -0
- package/dist/components/Indicator/index.d.ts +1 -0
- package/dist/components/Indicator/index.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/metadata/components.json +788 -127
- package/dist/utils/abbreviateNumber.d.ts +18 -2
- package/dist/utils/abbreviateNumber.js +62 -4
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Abbreviate a number for table cells: `12042` → `"12k"`, `59614283` → `"59.
|
|
2
|
+
* Abbreviate a number for table cells: `12042` → `"12k"`, `59614283` → `"59.6M"`.
|
|
3
3
|
*
|
|
4
4
|
* Rules (from the Number display & abbreviation guide):
|
|
5
|
-
* - Suffixes: k (10³),
|
|
5
|
+
* - Suffixes: k (10³), M (10⁶), B (10⁹), T (10¹²) — k lowercase, rest uppercase, no space
|
|
6
6
|
* - Boundary: moves to next suffix when rounding would reach 1000×
|
|
7
7
|
* - Precision: ≥100 → 0 decimals; 10–99 → 1 decimal (drop .0); 1–9.9 → 1 decimal
|
|
8
8
|
* - Negative numbers supported
|
|
@@ -12,3 +12,19 @@ export declare const abbreviateNumber: (value: number) => string;
|
|
|
12
12
|
* Format a number with thousand separators for tooltips: `59614283` → `"59,614,283"`.
|
|
13
13
|
*/
|
|
14
14
|
export declare const formatFullNumber: (value: number) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Format a percentage with boundary safety:
|
|
17
|
+
* - Never show 100% when real value < 100 → ">99%" (or ">99.9%" etc.)
|
|
18
|
+
* - Never show 0% when real value > 0 → "<1%" (or "<0.1%" etc.)
|
|
19
|
+
* - `decimals` controls fractional precision (default 0)
|
|
20
|
+
*/
|
|
21
|
+
export declare const formatPercent: (value: number, decimals?: number) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Format bytes using decimal (SI) units: 512 B, 3.4 KB, 12.7 MB, 2.3 GB, 1.1 TB.
|
|
24
|
+
* Same decimal precision rules as abbreviateNumber.
|
|
25
|
+
* Returns `{ display, full }` where `full` = "2,345,678,901 bytes".
|
|
26
|
+
*/
|
|
27
|
+
export declare const formatBytes: (value: number) => {
|
|
28
|
+
display: string;
|
|
29
|
+
full: string;
|
|
30
|
+
};
|
|
@@ -2,17 +2,17 @@ const tiers = [
|
|
|
2
2
|
[
|
|
3
3
|
999500000000,
|
|
4
4
|
1e12,
|
|
5
|
-
'
|
|
5
|
+
'T'
|
|
6
6
|
],
|
|
7
7
|
[
|
|
8
8
|
999500000,
|
|
9
9
|
1e9,
|
|
10
|
-
'
|
|
10
|
+
'B'
|
|
11
11
|
],
|
|
12
12
|
[
|
|
13
13
|
999500,
|
|
14
14
|
1e6,
|
|
15
|
-
'
|
|
15
|
+
'M'
|
|
16
16
|
],
|
|
17
17
|
[
|
|
18
18
|
1000,
|
|
@@ -36,4 +36,62 @@ const abbreviateNumber = (value)=>{
|
|
|
36
36
|
return `${sign}${formatted}${suffix}`;
|
|
37
37
|
};
|
|
38
38
|
const formatFullNumber = (value)=>fullFormatter.format(value);
|
|
39
|
-
|
|
39
|
+
const formatPercent = (value, decimals = 0)=>{
|
|
40
|
+
if (0 === value) return '0%';
|
|
41
|
+
if (100 === value) return '100%';
|
|
42
|
+
const factor = 10 ** decimals;
|
|
43
|
+
const rounded = Math.round(value * factor) / factor;
|
|
44
|
+
if (value > 0 && 0 === rounded) {
|
|
45
|
+
const threshold = 1 / factor;
|
|
46
|
+
return `<${threshold}%`;
|
|
47
|
+
}
|
|
48
|
+
if (value < 100 && 100 === rounded) {
|
|
49
|
+
const max = 100 - 1 / factor;
|
|
50
|
+
return `>${decimals > 0 ? max.toFixed(decimals) : String(max)}%`;
|
|
51
|
+
}
|
|
52
|
+
return `${decimals > 0 ? rounded.toFixed(decimals) : String(rounded)}%`;
|
|
53
|
+
};
|
|
54
|
+
const byteTiers = [
|
|
55
|
+
[
|
|
56
|
+
999500000000,
|
|
57
|
+
1e12,
|
|
58
|
+
'TB'
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
999500000,
|
|
62
|
+
1e9,
|
|
63
|
+
'GB'
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
999500,
|
|
67
|
+
1e6,
|
|
68
|
+
'MB'
|
|
69
|
+
],
|
|
70
|
+
[
|
|
71
|
+
1000,
|
|
72
|
+
1e3,
|
|
73
|
+
'KB'
|
|
74
|
+
]
|
|
75
|
+
];
|
|
76
|
+
const formatBytes = (value)=>{
|
|
77
|
+
const full = `${fullFormatter.format(value)} bytes`;
|
|
78
|
+
if (value < 1000) return {
|
|
79
|
+
display: `${value} B`,
|
|
80
|
+
full
|
|
81
|
+
};
|
|
82
|
+
const tier = byteTiers.find(([threshold])=>value >= threshold);
|
|
83
|
+
if (!tier) return {
|
|
84
|
+
display: `${value} B`,
|
|
85
|
+
full
|
|
86
|
+
};
|
|
87
|
+
const [, divisor, suffix] = tier;
|
|
88
|
+
const scaled = value / divisor;
|
|
89
|
+
const precision = scaled >= 100 ? 0 : 1;
|
|
90
|
+
const rounded = Math.round(scaled * 10 ** precision) / 10 ** precision;
|
|
91
|
+
const formatted = rounded % 1 === 0 ? String(rounded) : rounded.toFixed(1);
|
|
92
|
+
return {
|
|
93
|
+
display: `${formatted} ${suffix}`,
|
|
94
|
+
full
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
export { abbreviateNumber, formatBytes, formatFullNumber, formatPercent };
|