@choksheak/ts-utils 0.3.3 → 0.3.5
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/README.md +9 -3
- package/asNumber.cjs +6 -6
- package/asNumber.d.mts +1 -1
- package/asNumber.d.ts +1 -1
- package/asNumber.min.cjs +1 -1
- package/asNumber.min.cjs.map +1 -1
- package/asNumber.min.mjs +1 -1
- package/asNumber.min.mjs.map +1 -1
- package/asNumber.mjs +6 -6
- package/capLength.cjs +80 -0
- package/capLength.d.mts +3 -0
- package/capLength.d.ts +3 -0
- package/capLength.min.cjs +6 -0
- package/capLength.min.cjs.map +1 -0
- package/capLength.min.mjs +6 -0
- package/capLength.min.mjs.map +1 -0
- package/capLength.mjs +53 -0
- package/{iterators.cjs → concatIterators.cjs} +4 -4
- package/{iterators.min.cjs → concatIterators.min.cjs} +1 -1
- package/concatIterators.min.cjs.map +1 -0
- package/{iterators.min.mjs → concatIterators.min.mjs} +1 -1
- package/concatIterators.min.mjs.map +1 -0
- package/{iterators.mjs → concatIterators.mjs} +1 -1
- package/duration.min.cjs +1 -1
- package/duration.min.mjs +1 -1
- package/kvStore.cjs +230 -239
- package/kvStore.d.mts +142 -44
- package/kvStore.d.ts +142 -44
- package/kvStore.min.cjs +1 -1
- package/kvStore.min.cjs.map +1 -1
- package/kvStore.min.mjs +1 -1
- package/kvStore.min.mjs.map +1 -1
- package/kvStore.mjs +229 -237
- package/localStore.cjs +187 -186
- package/localStore.d.mts +135 -34
- package/localStore.d.ts +135 -34
- package/localStore.min.cjs +1 -1
- package/localStore.min.cjs.map +1 -1
- package/localStore.min.mjs +1 -1
- package/localStore.min.mjs.map +1 -1
- package/localStore.mjs +186 -184
- package/mean.cjs +6 -6
- package/mean.min.cjs +1 -1
- package/mean.min.cjs.map +1 -1
- package/mean.min.mjs +1 -1
- package/mean.min.mjs.map +1 -1
- package/mean.mjs +6 -6
- package/median.cjs +7 -7
- package/median.min.cjs +1 -1
- package/median.min.cjs.map +1 -1
- package/median.min.mjs +1 -1
- package/median.min.mjs.map +1 -1
- package/median.mjs +7 -7
- package/package.json +67 -82
- package/round.cjs +2 -10
- package/round.d.mts +2 -8
- package/round.d.ts +2 -8
- package/round.min.cjs +1 -1
- package/round.min.cjs.map +1 -1
- package/round.min.mjs +1 -1
- package/round.min.mjs.map +1 -1
- package/round.mjs +1 -8
- package/{safeParseInt.cjs → roundToString.cjs} +19 -9
- package/roundToString.d.mts +8 -0
- package/roundToString.d.ts +8 -0
- package/roundToString.min.cjs +2 -0
- package/roundToString.min.cjs.map +1 -0
- package/roundToString.min.mjs +2 -0
- package/roundToString.min.mjs.map +1 -0
- package/roundToString.mjs +16 -0
- package/safeBtoa.d.mts +7 -0
- package/safeBtoa.d.ts +7 -0
- package/safeBtoa.min.cjs.map +1 -1
- package/safeBtoa.min.mjs.map +1 -1
- package/sum.cjs +6 -6
- package/sum.min.cjs +1 -1
- package/sum.min.cjs.map +1 -1
- package/sum.min.mjs +1 -1
- package/sum.min.mjs.map +1 -1
- package/sum.mjs +6 -6
- package/timer.cjs +19 -24
- package/timer.d.mts +9 -6
- package/timer.d.ts +9 -6
- package/timer.min.cjs +1 -1
- package/timer.min.cjs.map +1 -1
- package/timer.min.mjs +1 -1
- package/timer.min.mjs.map +1 -1
- package/timer.mjs +19 -23
- package/toReadableString.cjs +69 -0
- package/toReadableString.d.mts +10 -0
- package/toReadableString.d.ts +10 -0
- package/toReadableString.min.cjs +6 -0
- package/toReadableString.min.cjs.map +1 -0
- package/toReadableString.min.mjs +6 -0
- package/toReadableString.min.mjs.map +1 -0
- package/toReadableString.mjs +44 -0
- package/average.cjs +0 -55
- package/average.d.mts +0 -7
- package/average.d.ts +0 -7
- package/average.min.cjs +0 -2
- package/average.min.cjs.map +0 -1
- package/average.min.mjs +0 -2
- package/average.min.mjs.map +0 -1
- package/average.mjs +0 -28
- package/iterators.min.cjs.map +0 -1
- package/iterators.min.mjs.map +0 -1
- package/logging.cjs +0 -47
- package/logging.d.mts +0 -4
- package/logging.d.ts +0 -4
- package/logging.min.cjs +0 -2
- package/logging.min.cjs.map +0 -1
- package/logging.min.mjs +0 -2
- package/logging.min.mjs.map +0 -1
- package/logging.mjs +0 -21
- package/safeParseFloat.cjs +0 -33
- package/safeParseFloat.d.mts +0 -6
- package/safeParseFloat.d.ts +0 -6
- package/safeParseFloat.min.cjs +0 -2
- package/safeParseFloat.min.cjs.map +0 -1
- package/safeParseFloat.min.mjs +0 -2
- package/safeParseFloat.min.mjs.map +0 -1
- package/safeParseFloat.mjs +0 -8
- package/safeParseInt.d.mts +0 -6
- package/safeParseInt.d.ts +0 -6
- package/safeParseInt.min.cjs +0 -2
- package/safeParseInt.min.cjs.map +0 -1
- package/safeParseInt.min.mjs +0 -2
- package/safeParseInt.min.mjs.map +0 -1
- package/safeParseInt.mjs +0 -8
- /package/{iterators.d.mts → concatIterators.d.mts} +0 -0
- /package/{iterators.d.ts → concatIterators.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@choksheak/ts-utils",
|
|
3
3
|
"license": "The Unlicense",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.5",
|
|
5
5
|
"description": "Random Typescript utilities with support for full tree-shaking",
|
|
6
6
|
"private": false,
|
|
7
|
+
"sideEffects": false,
|
|
7
8
|
"scripts": {
|
|
8
9
|
"lint": "eslint .",
|
|
9
10
|
"fix": "eslint . --fix",
|
|
@@ -13,7 +14,7 @@
|
|
|
13
14
|
"test:watch": "vitest",
|
|
14
15
|
"ci": "npm run lint && npm run tsc && npm run build && npm run test",
|
|
15
16
|
"ls": "lint-staged",
|
|
16
|
-
"docs": "
|
|
17
|
+
"docs": "typedoc",
|
|
17
18
|
"clean": "rm -rf dist",
|
|
18
19
|
"build": "tsup src/*",
|
|
19
20
|
"gen-types": "tsc --emitDeclarationOnly --declaration",
|
|
@@ -124,19 +125,6 @@
|
|
|
124
125
|
"default": "./assert.cjs"
|
|
125
126
|
}
|
|
126
127
|
},
|
|
127
|
-
"./average": {
|
|
128
|
-
"types": "./average.d.ts",
|
|
129
|
-
"import": {
|
|
130
|
-
"production": "./average.min.mjs",
|
|
131
|
-
"development": "./average.mjs",
|
|
132
|
-
"default": "./average.mjs"
|
|
133
|
-
},
|
|
134
|
-
"require": {
|
|
135
|
-
"production": "./average.min.cjs",
|
|
136
|
-
"development": "./average.cjs",
|
|
137
|
-
"default": "./average.cjs"
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
128
|
"./base64Url": {
|
|
141
129
|
"types": "./base64Url.d.ts",
|
|
142
130
|
"import": {
|
|
@@ -150,6 +138,32 @@
|
|
|
150
138
|
"default": "./base64Url.cjs"
|
|
151
139
|
}
|
|
152
140
|
},
|
|
141
|
+
"./capLength": {
|
|
142
|
+
"types": "./capLength.d.ts",
|
|
143
|
+
"import": {
|
|
144
|
+
"production": "./capLength.min.mjs",
|
|
145
|
+
"development": "./capLength.mjs",
|
|
146
|
+
"default": "./capLength.mjs"
|
|
147
|
+
},
|
|
148
|
+
"require": {
|
|
149
|
+
"production": "./capLength.min.cjs",
|
|
150
|
+
"development": "./capLength.cjs",
|
|
151
|
+
"default": "./capLength.cjs"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"./concatIterators": {
|
|
155
|
+
"types": "./concatIterators.d.ts",
|
|
156
|
+
"import": {
|
|
157
|
+
"production": "./concatIterators.min.mjs",
|
|
158
|
+
"development": "./concatIterators.mjs",
|
|
159
|
+
"default": "./concatIterators.mjs"
|
|
160
|
+
},
|
|
161
|
+
"require": {
|
|
162
|
+
"production": "./concatIterators.min.cjs",
|
|
163
|
+
"development": "./concatIterators.cjs",
|
|
164
|
+
"default": "./concatIterators.cjs"
|
|
165
|
+
}
|
|
166
|
+
},
|
|
153
167
|
"./dateTimeStr": {
|
|
154
168
|
"types": "./dateTimeStr.d.ts",
|
|
155
169
|
"import": {
|
|
@@ -202,19 +216,6 @@
|
|
|
202
216
|
"default": "./isPromise.cjs"
|
|
203
217
|
}
|
|
204
218
|
},
|
|
205
|
-
"./iterators": {
|
|
206
|
-
"types": "./iterators.d.ts",
|
|
207
|
-
"import": {
|
|
208
|
-
"production": "./iterators.min.mjs",
|
|
209
|
-
"development": "./iterators.mjs",
|
|
210
|
-
"default": "./iterators.mjs"
|
|
211
|
-
},
|
|
212
|
-
"require": {
|
|
213
|
-
"production": "./iterators.min.cjs",
|
|
214
|
-
"development": "./iterators.cjs",
|
|
215
|
-
"default": "./iterators.cjs"
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
219
|
"./kvStore": {
|
|
219
220
|
"types": "./kvStore.d.ts",
|
|
220
221
|
"import": {
|
|
@@ -241,19 +242,6 @@
|
|
|
241
242
|
"default": "./localStore.cjs"
|
|
242
243
|
}
|
|
243
244
|
},
|
|
244
|
-
"./logging": {
|
|
245
|
-
"types": "./logging.d.ts",
|
|
246
|
-
"import": {
|
|
247
|
-
"production": "./logging.min.mjs",
|
|
248
|
-
"development": "./logging.mjs",
|
|
249
|
-
"default": "./logging.mjs"
|
|
250
|
-
},
|
|
251
|
-
"require": {
|
|
252
|
-
"production": "./logging.min.cjs",
|
|
253
|
-
"development": "./logging.cjs",
|
|
254
|
-
"default": "./logging.cjs"
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
245
|
"./mean": {
|
|
258
246
|
"types": "./mean.d.ts",
|
|
259
247
|
"import": {
|
|
@@ -319,6 +307,19 @@
|
|
|
319
307
|
"default": "./round.cjs"
|
|
320
308
|
}
|
|
321
309
|
},
|
|
310
|
+
"./roundToString": {
|
|
311
|
+
"types": "./roundToString.d.ts",
|
|
312
|
+
"import": {
|
|
313
|
+
"production": "./roundToString.min.mjs",
|
|
314
|
+
"development": "./roundToString.mjs",
|
|
315
|
+
"default": "./roundToString.mjs"
|
|
316
|
+
},
|
|
317
|
+
"require": {
|
|
318
|
+
"production": "./roundToString.min.cjs",
|
|
319
|
+
"development": "./roundToString.cjs",
|
|
320
|
+
"default": "./roundToString.cjs"
|
|
321
|
+
}
|
|
322
|
+
},
|
|
322
323
|
"./safeBtoa": {
|
|
323
324
|
"types": "./safeBtoa.d.ts",
|
|
324
325
|
"import": {
|
|
@@ -332,32 +333,6 @@
|
|
|
332
333
|
"default": "./safeBtoa.cjs"
|
|
333
334
|
}
|
|
334
335
|
},
|
|
335
|
-
"./safeParseFloat": {
|
|
336
|
-
"types": "./safeParseFloat.d.ts",
|
|
337
|
-
"import": {
|
|
338
|
-
"production": "./safeParseFloat.min.mjs",
|
|
339
|
-
"development": "./safeParseFloat.mjs",
|
|
340
|
-
"default": "./safeParseFloat.mjs"
|
|
341
|
-
},
|
|
342
|
-
"require": {
|
|
343
|
-
"production": "./safeParseFloat.min.cjs",
|
|
344
|
-
"development": "./safeParseFloat.cjs",
|
|
345
|
-
"default": "./safeParseFloat.cjs"
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
"./safeParseInt": {
|
|
349
|
-
"types": "./safeParseInt.d.ts",
|
|
350
|
-
"import": {
|
|
351
|
-
"production": "./safeParseInt.min.mjs",
|
|
352
|
-
"development": "./safeParseInt.mjs",
|
|
353
|
-
"default": "./safeParseInt.mjs"
|
|
354
|
-
},
|
|
355
|
-
"require": {
|
|
356
|
-
"production": "./safeParseInt.min.cjs",
|
|
357
|
-
"development": "./safeParseInt.cjs",
|
|
358
|
-
"default": "./safeParseInt.cjs"
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
336
|
"./sha256": {
|
|
362
337
|
"types": "./sha256.d.ts",
|
|
363
338
|
"import": {
|
|
@@ -435,6 +410,19 @@
|
|
|
435
410
|
"development": "./timer.cjs",
|
|
436
411
|
"default": "./timer.cjs"
|
|
437
412
|
}
|
|
413
|
+
},
|
|
414
|
+
"./toReadableString": {
|
|
415
|
+
"types": "./toReadableString.d.ts",
|
|
416
|
+
"import": {
|
|
417
|
+
"production": "./toReadableString.min.mjs",
|
|
418
|
+
"development": "./toReadableString.mjs",
|
|
419
|
+
"default": "./toReadableString.mjs"
|
|
420
|
+
},
|
|
421
|
+
"require": {
|
|
422
|
+
"production": "./toReadableString.min.cjs",
|
|
423
|
+
"development": "./toReadableString.cjs",
|
|
424
|
+
"default": "./toReadableString.cjs"
|
|
425
|
+
}
|
|
438
426
|
}
|
|
439
427
|
},
|
|
440
428
|
"typesVersions": {
|
|
@@ -448,12 +436,15 @@
|
|
|
448
436
|
"assert": [
|
|
449
437
|
"./assert.d.ts"
|
|
450
438
|
],
|
|
451
|
-
"average": [
|
|
452
|
-
"./average.d.ts"
|
|
453
|
-
],
|
|
454
439
|
"base64Url": [
|
|
455
440
|
"./base64Url.d.ts"
|
|
456
441
|
],
|
|
442
|
+
"capLength": [
|
|
443
|
+
"./capLength.d.ts"
|
|
444
|
+
],
|
|
445
|
+
"concatIterators": [
|
|
446
|
+
"./concatIterators.d.ts"
|
|
447
|
+
],
|
|
457
448
|
"dateTimeStr": [
|
|
458
449
|
"./dateTimeStr.d.ts"
|
|
459
450
|
],
|
|
@@ -466,18 +457,12 @@
|
|
|
466
457
|
"isPromise": [
|
|
467
458
|
"./isPromise.d.ts"
|
|
468
459
|
],
|
|
469
|
-
"iterators": [
|
|
470
|
-
"./iterators.d.ts"
|
|
471
|
-
],
|
|
472
460
|
"kvStore": [
|
|
473
461
|
"./kvStore.d.ts"
|
|
474
462
|
],
|
|
475
463
|
"localStore": [
|
|
476
464
|
"./localStore.d.ts"
|
|
477
465
|
],
|
|
478
|
-
"logging": [
|
|
479
|
-
"./logging.d.ts"
|
|
480
|
-
],
|
|
481
466
|
"mean": [
|
|
482
467
|
"./mean.d.ts"
|
|
483
468
|
],
|
|
@@ -493,15 +478,12 @@
|
|
|
493
478
|
"round": [
|
|
494
479
|
"./round.d.ts"
|
|
495
480
|
],
|
|
481
|
+
"roundToString": [
|
|
482
|
+
"./roundToString.d.ts"
|
|
483
|
+
],
|
|
496
484
|
"safeBtoa": [
|
|
497
485
|
"./safeBtoa.d.ts"
|
|
498
486
|
],
|
|
499
|
-
"safeParseFloat": [
|
|
500
|
-
"./safeParseFloat.d.ts"
|
|
501
|
-
],
|
|
502
|
-
"safeParseInt": [
|
|
503
|
-
"./safeParseInt.d.ts"
|
|
504
|
-
],
|
|
505
487
|
"sha256": [
|
|
506
488
|
"./sha256.d.ts"
|
|
507
489
|
],
|
|
@@ -519,6 +501,9 @@
|
|
|
519
501
|
],
|
|
520
502
|
"timer": [
|
|
521
503
|
"./timer.d.ts"
|
|
504
|
+
],
|
|
505
|
+
"toReadableString": [
|
|
506
|
+
"./toReadableString.d.ts"
|
|
522
507
|
]
|
|
523
508
|
}
|
|
524
509
|
}
|
package/round.cjs
CHANGED
|
@@ -20,22 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/round.ts
|
|
21
21
|
var round_exports = {};
|
|
22
22
|
__export(round_exports, {
|
|
23
|
-
round: () => round
|
|
24
|
-
roundS: () => roundS
|
|
23
|
+
round: () => round
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(round_exports);
|
|
27
26
|
function round(n, numDecimalPlaces = 0) {
|
|
28
27
|
const multipler = Math.pow(10, numDecimalPlaces);
|
|
29
28
|
return Math.round(n * multipler) / multipler;
|
|
30
29
|
}
|
|
31
|
-
function roundS(n, numDecimalPlaces = 0) {
|
|
32
|
-
return round(n, numDecimalPlaces).toLocaleString("en-US", {
|
|
33
|
-
minimumFractionDigits: numDecimalPlaces,
|
|
34
|
-
maximumFractionDigits: numDecimalPlaces
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
31
|
0 && (module.exports = {
|
|
39
|
-
round
|
|
40
|
-
roundS
|
|
32
|
+
round
|
|
41
33
|
});
|
package/round.d.mts
CHANGED
|
@@ -2,14 +2,8 @@
|
|
|
2
2
|
* Simplifies rounding of floating point numbers. Note that if your number ends
|
|
3
3
|
* with zeros, and you convert the number to string, you will lose the zeroes
|
|
4
4
|
* at the end. To show the exact number of decimal places, you'll need to use
|
|
5
|
-
* toFixed(). E.g. round(1.20, 2).toFixed(2).
|
|
5
|
+
* roundToString() or toFixed(). E.g. round(1.20, 2).toFixed(2).
|
|
6
6
|
*/
|
|
7
7
|
declare function round(n: number, numDecimalPlaces?: number): number;
|
|
8
|
-
/**
|
|
9
|
-
* Returns a string with the number in the exact number of decimal places
|
|
10
|
-
* specified, in case the number ends with zeroes, and adding commas for each
|
|
11
|
-
* group of 3 significant digits.
|
|
12
|
-
*/
|
|
13
|
-
declare function roundS(n: number, numDecimalPlaces?: number): string;
|
|
14
8
|
|
|
15
|
-
export { round
|
|
9
|
+
export { round };
|
package/round.d.ts
CHANGED
|
@@ -2,14 +2,8 @@
|
|
|
2
2
|
* Simplifies rounding of floating point numbers. Note that if your number ends
|
|
3
3
|
* with zeros, and you convert the number to string, you will lose the zeroes
|
|
4
4
|
* at the end. To show the exact number of decimal places, you'll need to use
|
|
5
|
-
* toFixed(). E.g. round(1.20, 2).toFixed(2).
|
|
5
|
+
* roundToString() or toFixed(). E.g. round(1.20, 2).toFixed(2).
|
|
6
6
|
*/
|
|
7
7
|
declare function round(n: number, numDecimalPlaces?: number): number;
|
|
8
|
-
/**
|
|
9
|
-
* Returns a string with the number in the exact number of decimal places
|
|
10
|
-
* specified, in case the number ends with zeroes, and adding commas for each
|
|
11
|
-
* group of 3 significant digits.
|
|
12
|
-
*/
|
|
13
|
-
declare function roundS(n: number, numDecimalPlaces?: number): string;
|
|
14
8
|
|
|
15
|
-
export { round
|
|
9
|
+
export { round };
|
package/round.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var b=(r,n)=>{for(var t in n)o(r,t,{get:n[t],enumerable:!0})},c=(r,n,t,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let u of p(n))!a.call(r,u)&&u!==t&&o(r,u,{get:()=>n[u],enumerable:!(e=m(n,u))||e.enumerable});return r};var d=r=>c(o({},"__esModule",{value:!0}),r);var i={};b(i,{round:()=>h});module.exports=d(i);function h(r,n=0){let t=Math.pow(10,n);return Math.round(r*t)/t}0&&(module.exports={round});
|
|
2
2
|
//# sourceMappingURL=round.min.cjs.map
|
package/round.min.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/round.ts"],"sourcesContent":["/**\n * Simplifies rounding of floating point numbers. Note that if your number ends\n * with zeros, and you convert the number to string, you will lose the zeroes\n * at the end. To show the exact number of decimal places, you'll need to use\n * toFixed(). E.g. round(1.20, 2).toFixed(2).\n */\nexport function round(n: number, numDecimalPlaces = 0): number {\n const multipler = Math.pow(10, numDecimalPlaces);\n return Math.round(n * multipler) / multipler;\n}\n
|
|
1
|
+
{"version":3,"sources":["../src/round.ts"],"sourcesContent":["/**\n * Simplifies rounding of floating point numbers. Note that if your number ends\n * with zeros, and you convert the number to string, you will lose the zeroes\n * at the end. To show the exact number of decimal places, you'll need to use\n * roundToString() or toFixed(). E.g. round(1.20, 2).toFixed(2).\n */\nexport function round(n: number, numDecimalPlaces = 0): number {\n const multipler = Math.pow(10, numDecimalPlaces);\n return Math.round(n * multipler) / multipler;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,IAAA,eAAAC,EAAAH,GAMO,SAASE,EAAME,EAAWC,EAAmB,EAAW,CAC7D,IAAMC,EAAY,KAAK,IAAI,GAAID,CAAgB,EAC/C,OAAO,KAAK,MAAMD,EAAIE,CAAS,EAAIA,CACrC","names":["round_exports","__export","round","__toCommonJS","n","numDecimalPlaces","multipler"]}
|
package/round.min.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function u(r,t=0){let n=Math.pow(10,t);return Math.round(r*n)/n}export{u as round};
|
|
2
2
|
//# sourceMappingURL=round.min.mjs.map
|
package/round.min.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/round.ts"],"sourcesContent":["/**\n * Simplifies rounding of floating point numbers. Note that if your number ends\n * with zeros, and you convert the number to string, you will lose the zeroes\n * at the end. To show the exact number of decimal places, you'll need to use\n * toFixed(). E.g. round(1.20, 2).toFixed(2).\n */\nexport function round(n: number, numDecimalPlaces = 0): number {\n const multipler = Math.pow(10, numDecimalPlaces);\n return Math.round(n * multipler) / multipler;\n}\n
|
|
1
|
+
{"version":3,"sources":["../src/round.ts"],"sourcesContent":["/**\n * Simplifies rounding of floating point numbers. Note that if your number ends\n * with zeros, and you convert the number to string, you will lose the zeroes\n * at the end. To show the exact number of decimal places, you'll need to use\n * roundToString() or toFixed(). E.g. round(1.20, 2).toFixed(2).\n */\nexport function round(n: number, numDecimalPlaces = 0): number {\n const multipler = Math.pow(10, numDecimalPlaces);\n return Math.round(n * multipler) / multipler;\n}\n"],"mappings":"AAMO,SAASA,EAAMC,EAAWC,EAAmB,EAAW,CAC7D,IAAMC,EAAY,KAAK,IAAI,GAAID,CAAgB,EAC/C,OAAO,KAAK,MAAMD,EAAIE,CAAS,EAAIA,CACrC","names":["round","n","numDecimalPlaces","multipler"]}
|
package/round.mjs
CHANGED
|
@@ -3,13 +3,6 @@ function round(n, numDecimalPlaces = 0) {
|
|
|
3
3
|
const multipler = Math.pow(10, numDecimalPlaces);
|
|
4
4
|
return Math.round(n * multipler) / multipler;
|
|
5
5
|
}
|
|
6
|
-
function roundS(n, numDecimalPlaces = 0) {
|
|
7
|
-
return round(n, numDecimalPlaces).toLocaleString("en-US", {
|
|
8
|
-
minimumFractionDigits: numDecimalPlaces,
|
|
9
|
-
maximumFractionDigits: numDecimalPlaces
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
6
|
export {
|
|
13
|
-
round
|
|
14
|
-
roundS
|
|
7
|
+
round
|
|
15
8
|
};
|
|
@@ -17,17 +17,27 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
|
|
20
|
+
// src/roundToString.ts
|
|
21
|
+
var roundToString_exports = {};
|
|
22
|
+
__export(roundToString_exports, {
|
|
23
|
+
roundToString: () => roundToString
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
module.exports = __toCommonJS(roundToString_exports);
|
|
26
|
+
|
|
27
|
+
// src/round.ts
|
|
28
|
+
function round(n, numDecimalPlaces = 0) {
|
|
29
|
+
const multipler = Math.pow(10, numDecimalPlaces);
|
|
30
|
+
return Math.round(n * multipler) / multipler;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/roundToString.ts
|
|
34
|
+
function roundToString(n, numDecimalPlaces = 0) {
|
|
35
|
+
return round(n, numDecimalPlaces).toLocaleString("en-US", {
|
|
36
|
+
minimumFractionDigits: numDecimalPlaces,
|
|
37
|
+
maximumFractionDigits: numDecimalPlaces
|
|
38
|
+
});
|
|
29
39
|
}
|
|
30
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
41
|
0 && (module.exports = {
|
|
32
|
-
|
|
42
|
+
roundToString
|
|
33
43
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a string with the number in the exact number of decimal places
|
|
3
|
+
* specified, in case the number ends with zeroes, and adding commas for each
|
|
4
|
+
* group of 3 significant digits.
|
|
5
|
+
*/
|
|
6
|
+
declare function roundToString(n: number, numDecimalPlaces?: number): string;
|
|
7
|
+
|
|
8
|
+
export { roundToString };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a string with the number in the exact number of decimal places
|
|
3
|
+
* specified, in case the number ends with zeroes, and adding commas for each
|
|
4
|
+
* group of 3 significant digits.
|
|
5
|
+
*/
|
|
6
|
+
declare function roundToString(n: number, numDecimalPlaces?: number): string;
|
|
7
|
+
|
|
8
|
+
export { roundToString };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var e=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(n,r)=>{for(var t in r)i(n,t,{get:r[t],enumerable:!0})},b=(n,r,t,u)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of g(r))!p.call(n,o)&&o!==t&&i(n,o,{get:()=>r[o],enumerable:!(u=e(r,o))||u.enumerable});return n};var f=n=>b(i({},"__esModule",{value:!0}),n);var S={};d(S,{roundToString:()=>x});module.exports=f(S);function m(n,r=0){let t=Math.pow(10,r);return Math.round(n*t)/t}function x(n,r=0){return m(n,r).toLocaleString("en-US",{minimumFractionDigits:r,maximumFractionDigits:r})}0&&(module.exports={roundToString});
|
|
2
|
+
//# sourceMappingURL=roundToString.min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/roundToString.ts","../src/round.ts"],"sourcesContent":["import { round } from \"./round\";\n\n/**\n * Returns a string with the number in the exact number of decimal places\n * specified, in case the number ends with zeroes, and adding commas for each\n * group of 3 significant digits.\n */\nexport function roundToString(n: number, numDecimalPlaces = 0): string {\n return round(n, numDecimalPlaces).toLocaleString(\"en-US\", {\n minimumFractionDigits: numDecimalPlaces,\n maximumFractionDigits: numDecimalPlaces,\n });\n}\n","/**\n * Simplifies rounding of floating point numbers. Note that if your number ends\n * with zeros, and you convert the number to string, you will lose the zeroes\n * at the end. To show the exact number of decimal places, you'll need to use\n * roundToString() or toFixed(). E.g. round(1.20, 2).toFixed(2).\n */\nexport function round(n: number, numDecimalPlaces = 0): number {\n const multipler = Math.pow(10, numDecimalPlaces);\n return Math.round(n * multipler) / multipler;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GCMO,SAASI,EAAM,EAAWC,EAAmB,EAAW,CAC7D,IAAMC,EAAY,KAAK,IAAI,GAAID,CAAgB,EAC/C,OAAO,KAAK,MAAM,EAAIC,CAAS,EAAIA,CACrC,CDFO,SAASC,EAAc,EAAWC,EAAmB,EAAW,CACrE,OAAOC,EAAM,EAAGD,CAAgB,EAAE,eAAe,QAAS,CACxD,sBAAuBA,EACvB,sBAAuBA,CACzB,CAAC,CACH","names":["roundToString_exports","__export","roundToString","__toCommonJS","round","numDecimalPlaces","multipler","roundToString","numDecimalPlaces","round"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/round.ts","../src/roundToString.ts"],"sourcesContent":["/**\n * Simplifies rounding of floating point numbers. Note that if your number ends\n * with zeros, and you convert the number to string, you will lose the zeroes\n * at the end. To show the exact number of decimal places, you'll need to use\n * roundToString() or toFixed(). E.g. round(1.20, 2).toFixed(2).\n */\nexport function round(n: number, numDecimalPlaces = 0): number {\n const multipler = Math.pow(10, numDecimalPlaces);\n return Math.round(n * multipler) / multipler;\n}\n","import { round } from \"./round\";\n\n/**\n * Returns a string with the number in the exact number of decimal places\n * specified, in case the number ends with zeroes, and adding commas for each\n * group of 3 significant digits.\n */\nexport function roundToString(n: number, numDecimalPlaces = 0): string {\n return round(n, numDecimalPlaces).toLocaleString(\"en-US\", {\n minimumFractionDigits: numDecimalPlaces,\n maximumFractionDigits: numDecimalPlaces,\n });\n}\n"],"mappings":"AAMO,SAASA,EAAM,EAAWC,EAAmB,EAAW,CAC7D,IAAMC,EAAY,KAAK,IAAI,GAAID,CAAgB,EAC/C,OAAO,KAAK,MAAM,EAAIC,CAAS,EAAIA,CACrC,CCFO,SAASC,EAAc,EAAWC,EAAmB,EAAW,CACrE,OAAOC,EAAM,EAAGD,CAAgB,EAAE,eAAe,QAAS,CACxD,sBAAuBA,EACvB,sBAAuBA,CACzB,CAAC,CACH","names":["round","numDecimalPlaces","multipler","roundToString","numDecimalPlaces","round"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/round.ts
|
|
2
|
+
function round(n, numDecimalPlaces = 0) {
|
|
3
|
+
const multipler = Math.pow(10, numDecimalPlaces);
|
|
4
|
+
return Math.round(n * multipler) / multipler;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// src/roundToString.ts
|
|
8
|
+
function roundToString(n, numDecimalPlaces = 0) {
|
|
9
|
+
return round(n, numDecimalPlaces).toLocaleString("en-US", {
|
|
10
|
+
minimumFractionDigits: numDecimalPlaces,
|
|
11
|
+
maximumFractionDigits: numDecimalPlaces
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
roundToString
|
|
16
|
+
};
|
package/safeBtoa.d.mts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base 64 encode the given input string, but safely.
|
|
3
|
+
*
|
|
4
|
+
* Why using btoa() directly might not always work:
|
|
5
|
+
* btoa() expects a "binary string" where each character is represented by a
|
|
6
|
+
* single byte (0-255). Modern JavaScript strings, however, are encoded in
|
|
7
|
+
* UTF-16 and can contain characters that require more than one byte (i.e.,
|
|
8
|
+
* characters outside the Latin-1 range, such as those with code points greater
|
|
9
|
+
* than 255).
|
|
3
10
|
*/
|
|
4
11
|
declare function safeBtoa(input: string): string;
|
|
5
12
|
|
package/safeBtoa.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base 64 encode the given input string, but safely.
|
|
3
|
+
*
|
|
4
|
+
* Why using btoa() directly might not always work:
|
|
5
|
+
* btoa() expects a "binary string" where each character is represented by a
|
|
6
|
+
* single byte (0-255). Modern JavaScript strings, however, are encoded in
|
|
7
|
+
* UTF-16 and can contain characters that require more than one byte (i.e.,
|
|
8
|
+
* characters outside the Latin-1 range, such as those with code points greater
|
|
9
|
+
* than 255).
|
|
3
10
|
*/
|
|
4
11
|
declare function safeBtoa(input: string): string;
|
|
5
12
|
|
package/safeBtoa.min.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/safeBtoa.ts"],"sourcesContent":["/**\n * Base 64 encode the given input string, but safely.\n */\nexport function safeBtoa(input: string): string {\n // Convert the string to a UTF-8 encoded binary-safe string\n const utf8Bytes = new TextEncoder().encode(input);\n\n // Convert the binary data to a string for btoa\n const binaryString = Array.from(utf8Bytes)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Use btoa to encode the binary-safe string\n return btoa(binaryString);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,
|
|
1
|
+
{"version":3,"sources":["../src/safeBtoa.ts"],"sourcesContent":["/**\n * Base 64 encode the given input string, but safely.\n *\n * Why using btoa() directly might not always work:\n * btoa() expects a \"binary string\" where each character is represented by a\n * single byte (0-255). Modern JavaScript strings, however, are encoded in\n * UTF-16 and can contain characters that require more than one byte (i.e.,\n * characters outside the Latin-1 range, such as those with code points greater\n * than 255).\n */\nexport function safeBtoa(input: string): string {\n // Convert the string to a UTF-8 encoded binary-safe string\n const utf8Bytes = new TextEncoder().encode(input);\n\n // Convert the binary data to a string for btoa\n const binaryString = Array.from(utf8Bytes)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Use btoa to encode the binary-safe string\n return btoa(binaryString);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GAUO,SAASE,EAASE,EAAuB,CAE9C,IAAMC,EAAY,IAAI,YAAY,EAAE,OAAOD,CAAK,EAG1CE,EAAe,MAAM,KAAKD,CAAS,EACtC,IAAKE,GAAS,OAAO,cAAcA,CAAI,CAAC,EACxC,KAAK,EAAE,EAGV,OAAO,KAAKD,CAAY,CAC1B","names":["safeBtoa_exports","__export","safeBtoa","__toCommonJS","input","utf8Bytes","binaryString","byte"]}
|
package/safeBtoa.min.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/safeBtoa.ts"],"sourcesContent":["/**\n * Base 64 encode the given input string, but safely.\n */\nexport function safeBtoa(input: string): string {\n // Convert the string to a UTF-8 encoded binary-safe string\n const utf8Bytes = new TextEncoder().encode(input);\n\n // Convert the binary data to a string for btoa\n const binaryString = Array.from(utf8Bytes)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Use btoa to encode the binary-safe string\n return btoa(binaryString);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/safeBtoa.ts"],"sourcesContent":["/**\n * Base 64 encode the given input string, but safely.\n *\n * Why using btoa() directly might not always work:\n * btoa() expects a \"binary string\" where each character is represented by a\n * single byte (0-255). Modern JavaScript strings, however, are encoded in\n * UTF-16 and can contain characters that require more than one byte (i.e.,\n * characters outside the Latin-1 range, such as those with code points greater\n * than 255).\n */\nexport function safeBtoa(input: string): string {\n // Convert the string to a UTF-8 encoded binary-safe string\n const utf8Bytes = new TextEncoder().encode(input);\n\n // Convert the binary data to a string for btoa\n const binaryString = Array.from(utf8Bytes)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Use btoa to encode the binary-safe string\n return btoa(binaryString);\n}\n"],"mappings":"AAUO,SAASA,EAASC,EAAuB,CAE9C,IAAMC,EAAY,IAAI,YAAY,EAAE,OAAOD,CAAK,EAG1CE,EAAe,MAAM,KAAKD,CAAS,EACtC,IAAKE,GAAS,OAAO,cAAcA,CAAI,CAAC,EACxC,KAAK,EAAE,EAGV,OAAO,KAAKD,CAAY,CAC1B","names":["safeBtoa","input","utf8Bytes","binaryString","byte"]}
|
package/sum.cjs
CHANGED
|
@@ -25,15 +25,15 @@ __export(sum_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(sum_exports);
|
|
26
26
|
|
|
27
27
|
// src/asNumber.ts
|
|
28
|
-
function asNumber(u) {
|
|
28
|
+
function asNumber(u, defaultValue = 0) {
|
|
29
|
+
if (typeof u === "number") {
|
|
30
|
+
return isFinite(u) ? u : defaultValue;
|
|
31
|
+
}
|
|
32
|
+
u = Number(u);
|
|
29
33
|
if (typeof u === "number" && isFinite(u)) {
|
|
30
34
|
return u;
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
if (typeof n === "number" && isFinite(n)) {
|
|
34
|
-
return n;
|
|
35
|
-
}
|
|
36
|
-
return 0;
|
|
36
|
+
return defaultValue;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// src/sum.ts
|
package/sum.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var p=(n,r)=>{for(var e in r)i(n,e,{get:r[e],enumerable:!0})},s=(n,r,e,m)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of b(r))!f.call(n,t)&&t!==e&&i(n,t,{get:()=>r[t],enumerable:!(m=u(r,t))||m.enumerable});return n};var c=n=>s(i({},"__esModule",{value:!0}),n);var w={};p(w,{sum:()=>k});module.exports=c(w);function o(n,r=0){return typeof n=="number"?isFinite(n)?n:r:(n=Number(n),typeof n=="number"&&isFinite(n)?n:r)}function k(n){return n.reduce((r,e)=>r+o(e),0)}0&&(module.exports={sum});
|
|
2
2
|
//# sourceMappingURL=sum.min.cjs.map
|
package/sum.min.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sum.ts","../src/asNumber.ts"],"sourcesContent":["import { asNumber } from \"./asNumber\";\n\n/**\n * Add all the numbers together in the given array.\n * Non-numbers will be coerced into numbers if possible.\n */\nexport function sum(numbers: unknown[]): number {\n return numbers.reduce((accumulated: number, current: unknown) => {\n return accumulated + asNumber(current);\n }, 0);\n}\n","/**\n * Coerce `u` into a number if possible, otherwise just return 0.\n */\nexport function asNumber(u: unknown): number {\n //
|
|
1
|
+
{"version":3,"sources":["../src/sum.ts","../src/asNumber.ts"],"sourcesContent":["import { asNumber } from \"./asNumber\";\n\n/**\n * Add all the numbers together in the given array.\n * Non-numbers will be coerced into numbers if possible.\n */\nexport function sum(numbers: unknown[]): number {\n return numbers.reduce((accumulated: number, current: unknown) => {\n return accumulated + asNumber(current);\n }, 0);\n}\n","/**\n * Coerce `u` into a number if possible, otherwise just return 0.\n */\nexport function asNumber(u: unknown, defaultValue = 0): number {\n // If u is a valid number, return it.\n if (typeof u === \"number\") {\n return isFinite(u) ? u : defaultValue;\n }\n\n // Try to make into a number if not already a number.\n u = Number(u);\n\n // If u is a valid number, return it.\n if (typeof u === \"number\" && isFinite(u)) {\n return u;\n }\n\n // Return `defaultValue` for everything else. This is usually ok if want to\n // just ignore all other noise.\n return defaultValue;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,IAAA,eAAAC,EAAAH,GCGO,SAASI,EAASC,EAAYC,EAAe,EAAW,CAE7D,OAAI,OAAOD,GAAM,SACR,SAASA,CAAC,EAAIA,EAAIC,GAI3BD,EAAI,OAAOA,CAAC,EAGR,OAAOA,GAAM,UAAY,SAASA,CAAC,EAC9BA,EAKFC,EACT,CDdO,SAASC,EAAIC,EAA4B,CAC9C,OAAOA,EAAQ,OAAO,CAACC,EAAqBC,IACnCD,EAAcE,EAASD,CAAO,EACpC,CAAC,CACN","names":["sum_exports","__export","sum","__toCommonJS","asNumber","u","defaultValue","sum","numbers","accumulated","current","asNumber"]}
|
package/sum.min.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(n){
|
|
1
|
+
function e(n,r=0){return typeof n=="number"?isFinite(n)?n:r:(n=Number(n),typeof n=="number"&&isFinite(n)?n:r)}function o(n){return n.reduce((r,t)=>r+e(t),0)}export{o as sum};
|
|
2
2
|
//# sourceMappingURL=sum.min.mjs.map
|
package/sum.min.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/asNumber.ts","../src/sum.ts"],"sourcesContent":["/**\n * Coerce `u` into a number if possible, otherwise just return 0.\n */\nexport function asNumber(u: unknown): number {\n //
|
|
1
|
+
{"version":3,"sources":["../src/asNumber.ts","../src/sum.ts"],"sourcesContent":["/**\n * Coerce `u` into a number if possible, otherwise just return 0.\n */\nexport function asNumber(u: unknown, defaultValue = 0): number {\n // If u is a valid number, return it.\n if (typeof u === \"number\") {\n return isFinite(u) ? u : defaultValue;\n }\n\n // Try to make into a number if not already a number.\n u = Number(u);\n\n // If u is a valid number, return it.\n if (typeof u === \"number\" && isFinite(u)) {\n return u;\n }\n\n // Return `defaultValue` for everything else. This is usually ok if want to\n // just ignore all other noise.\n return defaultValue;\n}\n","import { asNumber } from \"./asNumber\";\n\n/**\n * Add all the numbers together in the given array.\n * Non-numbers will be coerced into numbers if possible.\n */\nexport function sum(numbers: unknown[]): number {\n return numbers.reduce((accumulated: number, current: unknown) => {\n return accumulated + asNumber(current);\n }, 0);\n}\n"],"mappings":"AAGO,SAASA,EAASC,EAAYC,EAAe,EAAW,CAE7D,OAAI,OAAOD,GAAM,SACR,SAASA,CAAC,EAAIA,EAAIC,GAI3BD,EAAI,OAAOA,CAAC,EAGR,OAAOA,GAAM,UAAY,SAASA,CAAC,EAC9BA,EAKFC,EACT,CCdO,SAASC,EAAIC,EAA4B,CAC9C,OAAOA,EAAQ,OAAO,CAACC,EAAqBC,IACnCD,EAAcE,EAASD,CAAO,EACpC,CAAC,CACN","names":["asNumber","u","defaultValue","sum","numbers","accumulated","current","asNumber"]}
|
package/sum.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// src/asNumber.ts
|
|
2
|
-
function asNumber(u) {
|
|
2
|
+
function asNumber(u, defaultValue = 0) {
|
|
3
|
+
if (typeof u === "number") {
|
|
4
|
+
return isFinite(u) ? u : defaultValue;
|
|
5
|
+
}
|
|
6
|
+
u = Number(u);
|
|
3
7
|
if (typeof u === "number" && isFinite(u)) {
|
|
4
8
|
return u;
|
|
5
9
|
}
|
|
6
|
-
|
|
7
|
-
if (typeof n === "number" && isFinite(n)) {
|
|
8
|
-
return n;
|
|
9
|
-
}
|
|
10
|
-
return 0;
|
|
10
|
+
return defaultValue;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// src/sum.ts
|
package/timer.cjs
CHANGED
|
@@ -20,7 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/timer.ts
|
|
21
21
|
var timer_exports = {};
|
|
22
22
|
__export(timer_exports, {
|
|
23
|
-
Timer: () => Timer,
|
|
24
23
|
timer: () => timer
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(timer_exports);
|
|
@@ -158,32 +157,28 @@ function elapsed(ms) {
|
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
// src/timer.ts
|
|
161
|
-
var Timer = class {
|
|
162
|
-
startMs;
|
|
163
|
-
endMs = 0;
|
|
164
|
-
constructor() {
|
|
165
|
-
this.startMs = Date.now();
|
|
166
|
-
}
|
|
167
|
-
stop() {
|
|
168
|
-
this.endMs = Date.now();
|
|
169
|
-
}
|
|
170
|
-
restart() {
|
|
171
|
-
this.endMs = 0;
|
|
172
|
-
this.startMs = Date.now();
|
|
173
|
-
}
|
|
174
|
-
elapsedMs() {
|
|
175
|
-
const stopMs = this.endMs || Date.now();
|
|
176
|
-
return stopMs - this.startMs;
|
|
177
|
-
}
|
|
178
|
-
toString() {
|
|
179
|
-
return elapsed(this.elapsedMs());
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
160
|
function timer() {
|
|
183
|
-
|
|
161
|
+
const obj = {
|
|
162
|
+
startMs: Date.now(),
|
|
163
|
+
endMs: 0,
|
|
164
|
+
stop() {
|
|
165
|
+
obj.endMs = Date.now();
|
|
166
|
+
},
|
|
167
|
+
restart() {
|
|
168
|
+
obj.endMs = 0;
|
|
169
|
+
obj.startMs = Date.now();
|
|
170
|
+
},
|
|
171
|
+
elapsedMs() {
|
|
172
|
+
const stopMs = obj.endMs || Date.now();
|
|
173
|
+
return stopMs - obj.startMs;
|
|
174
|
+
},
|
|
175
|
+
toString() {
|
|
176
|
+
return elapsed(obj.elapsedMs());
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
return obj;
|
|
184
180
|
}
|
|
185
181
|
// Annotate the CommonJS export names for ESM import in node:
|
|
186
182
|
0 && (module.exports = {
|
|
187
|
-
Timer,
|
|
188
183
|
timer
|
|
189
184
|
});
|