@bouko/ts 0.2.3 → 0.2.4
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.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/math.d.ts +12 -0
- package/dist/types/math.js +9 -0
- package/dist/utils/formatters.d.ts +1 -0
- package/dist/utils/formatters.js +7 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for math/numbers.
|
|
3
|
+
*
|
|
4
|
+
* - `Range`: Object with `min` and `max` properties.
|
|
5
|
+
*
|
|
6
|
+
* They are intended to facilitate math utilities
|
|
7
|
+
* such as clamping, normalization, etc.
|
|
8
|
+
**/
|
|
9
|
+
export declare type Range = {
|
|
10
|
+
min: number;
|
|
11
|
+
max: number;
|
|
12
|
+
};
|
package/dist/utils/formatters.js
CHANGED
|
@@ -3,3 +3,10 @@ export const shortenStr = (str) => {
|
|
|
3
3
|
return str;
|
|
4
4
|
return `${str.slice(0, 3)}...${str.slice(-3)}`;
|
|
5
5
|
};
|
|
6
|
+
export const shortenNum = (x) => {
|
|
7
|
+
if (x < 1000)
|
|
8
|
+
return x.toString();
|
|
9
|
+
if (x < 1_000_000)
|
|
10
|
+
return `${Math.floor(x / 1000)}k`;
|
|
11
|
+
return `${Math.floor(x / 1_000_000)}m`;
|
|
12
|
+
};
|