zek 19.0.22 → 19.0.23
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/fesm2022/zek.mjs +23 -1
- package/fesm2022/zek.mjs.map +1 -1
- package/lib/utils/math-helper.d.ts +1 -0
- package/package.json +1 -1
package/fesm2022/zek.mjs
CHANGED
|
@@ -1281,8 +1281,14 @@ class JwtHelper {
|
|
|
1281
1281
|
}
|
|
1282
1282
|
|
|
1283
1283
|
class MathHelper {
|
|
1284
|
+
// static round(value: number, decimals: number = 0): number {
|
|
1285
|
+
// return Math.round(Number(value) * Math.pow(10, decimals)) / (Math.pow(10, decimals));
|
|
1286
|
+
// }
|
|
1284
1287
|
static round(value, decimals = 0) {
|
|
1285
|
-
|
|
1288
|
+
if (!Number.isFinite(value))
|
|
1289
|
+
return NaN;
|
|
1290
|
+
const factor = 10 ** decimals;
|
|
1291
|
+
return Math.round((value + Number.EPSILON) * factor) / factor;
|
|
1286
1292
|
}
|
|
1287
1293
|
static clamp(v, min, max) {
|
|
1288
1294
|
return Math.max(min, Math.min(max, v));
|
|
@@ -1297,6 +1303,22 @@ class MathHelper {
|
|
|
1297
1303
|
}
|
|
1298
1304
|
return sum;
|
|
1299
1305
|
}
|
|
1306
|
+
static format(num, digits = 2) {
|
|
1307
|
+
if (num === null || num === undefined || isNaN(num))
|
|
1308
|
+
return '0';
|
|
1309
|
+
// If less than 1000, display normally
|
|
1310
|
+
if (Math.abs(num) < 1000) {
|
|
1311
|
+
return num.toString();
|
|
1312
|
+
}
|
|
1313
|
+
const suffixes = ['k', 'M', 'G', 'T', 'P', 'E'];
|
|
1314
|
+
// Calculate the index of the suffix
|
|
1315
|
+
// e.g. 1,000 -> index 0 ('k'), 1,000,000 -> index 1 ('M')
|
|
1316
|
+
const exp = Math.floor(Math.log(Math.abs(num)) / Math.log(1000));
|
|
1317
|
+
const value = num / Math.pow(1000, exp);
|
|
1318
|
+
const rounded = this.round(value, digits);
|
|
1319
|
+
// Return with suffix (subtract 1 because index 0 is 'k', not '1')
|
|
1320
|
+
return rounded + suffixes[exp - 1];
|
|
1321
|
+
}
|
|
1300
1322
|
}
|
|
1301
1323
|
|
|
1302
1324
|
class PagerHelper {
|