@chopkola/common 1.0.51 → 1.0.53
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/build/helpers/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertStringDurationToMs = void 0;
|
|
3
|
+
exports.abbreviateNumber = exports.convertStringDurationToMs = void 0;
|
|
4
4
|
const validators_1 = require("../validators");
|
|
5
5
|
const convertStringDurationToMs = (value) => {
|
|
6
6
|
const match = value.match(validators_1.stringDurationToMsRegex);
|
|
@@ -21,3 +21,14 @@ const convertStringDurationToMs = (value) => {
|
|
|
21
21
|
return amount * unitMap[unit];
|
|
22
22
|
};
|
|
23
23
|
exports.convertStringDurationToMs = convertStringDurationToMs;
|
|
24
|
+
const abbreviateNumber = (number, decimals = 1) => {
|
|
25
|
+
if (number == null || isNaN(number))
|
|
26
|
+
return '0'; // fallback for null/undefined/NaN
|
|
27
|
+
// Reusable formatter with dynamic decimals
|
|
28
|
+
const formatter = new Intl.NumberFormat('en', {
|
|
29
|
+
notation: 'compact',
|
|
30
|
+
maximumFractionDigits: decimals,
|
|
31
|
+
});
|
|
32
|
+
return formatter.format(number);
|
|
33
|
+
};
|
|
34
|
+
exports.abbreviateNumber = abbreviateNumber;
|
package/build/types/user.d.ts
CHANGED