@oh-my-pi/pi-utils 18.13.0 → 18.13.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/CHANGELOG.md +6 -0
- package/dist/types/format.d.ts +2 -1
- package/package.json +2 -2
- package/src/format.ts +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [18.13.1] - 2026-10-27
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Added an optional `maxFractionDigits` to `formatNumber()` that caps decimals on values below 1,000 ([#16973](https://github.com/can1357/oh-my-pi/pull/16973) by [@DusKing1](https://github.com/DusKing1))
|
|
10
|
+
|
|
5
11
|
## [18.13.0] - 2026-10-26
|
|
6
12
|
|
|
7
13
|
### Added
|
package/dist/types/format.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export declare function formatDuration(ms: number): string;
|
|
|
6
6
|
/**
|
|
7
7
|
* Format a number with K/M/B suffix for compact display.
|
|
8
8
|
* Uses 1 decimal for small leading digits when non-zero, rounded otherwise.
|
|
9
|
+
* Values below 1,000 print as-is unless `maxFractionDigits` caps their decimals.
|
|
9
10
|
* Examples: "999", "1K", "1.5K", "25K", "1M", "1.5M", "25M", "1.5B"
|
|
10
11
|
*/
|
|
11
|
-
export declare function formatNumber(n: number): string;
|
|
12
|
+
export declare function formatNumber(n: number, maxFractionDigits?: number): string;
|
|
12
13
|
/**
|
|
13
14
|
* Format a byte count to a human-readable string.
|
|
14
15
|
* Examples: "512B", "1.5KB", "2.3MB", "1.2GB"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/pi-utils",
|
|
3
|
-
"version": "18.13.
|
|
3
|
+
"version": "18.13.1",
|
|
4
4
|
"description": "Shared utilities for pi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@oh-my-pi/pi-natives": "18.13.
|
|
60
|
+
"@oh-my-pi/pi-natives": "18.13.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/bun": "^1.3.14"
|
package/src/format.ts
CHANGED
|
@@ -33,10 +33,14 @@ export function formatDuration(ms: number): string {
|
|
|
33
33
|
/**
|
|
34
34
|
* Format a number with K/M/B suffix for compact display.
|
|
35
35
|
* Uses 1 decimal for small leading digits when non-zero, rounded otherwise.
|
|
36
|
+
* Values below 1,000 print as-is unless `maxFractionDigits` caps their decimals.
|
|
36
37
|
* Examples: "999", "1K", "1.5K", "25K", "1M", "1.5M", "25M", "1.5B"
|
|
37
38
|
*/
|
|
38
|
-
export function formatNumber(n: number): string {
|
|
39
|
-
if (n < 1_000)
|
|
39
|
+
export function formatNumber(n: number, maxFractionDigits?: number): string {
|
|
40
|
+
if (n < 1_000) {
|
|
41
|
+
if (maxFractionDigits === undefined || Number.isInteger(n)) return n.toString();
|
|
42
|
+
return Number(n.toFixed(maxFractionDigits)).toString();
|
|
43
|
+
}
|
|
40
44
|
if (n < 10_000) return `${trim1(n / 1_000)}K`;
|
|
41
45
|
if (n < 1_000_000) return `${Math.round(n / 1_000)}K`;
|
|
42
46
|
if (n < 10_000_000) return `${trim1(n / 1_000_000)}M`;
|