@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.
Files changed (131) hide show
  1. package/README.md +9 -3
  2. package/asNumber.cjs +6 -6
  3. package/asNumber.d.mts +1 -1
  4. package/asNumber.d.ts +1 -1
  5. package/asNumber.min.cjs +1 -1
  6. package/asNumber.min.cjs.map +1 -1
  7. package/asNumber.min.mjs +1 -1
  8. package/asNumber.min.mjs.map +1 -1
  9. package/asNumber.mjs +6 -6
  10. package/capLength.cjs +80 -0
  11. package/capLength.d.mts +3 -0
  12. package/capLength.d.ts +3 -0
  13. package/capLength.min.cjs +6 -0
  14. package/capLength.min.cjs.map +1 -0
  15. package/capLength.min.mjs +6 -0
  16. package/capLength.min.mjs.map +1 -0
  17. package/capLength.mjs +53 -0
  18. package/{iterators.cjs → concatIterators.cjs} +4 -4
  19. package/{iterators.min.cjs → concatIterators.min.cjs} +1 -1
  20. package/concatIterators.min.cjs.map +1 -0
  21. package/{iterators.min.mjs → concatIterators.min.mjs} +1 -1
  22. package/concatIterators.min.mjs.map +1 -0
  23. package/{iterators.mjs → concatIterators.mjs} +1 -1
  24. package/duration.min.cjs +1 -1
  25. package/duration.min.mjs +1 -1
  26. package/kvStore.cjs +230 -239
  27. package/kvStore.d.mts +142 -44
  28. package/kvStore.d.ts +142 -44
  29. package/kvStore.min.cjs +1 -1
  30. package/kvStore.min.cjs.map +1 -1
  31. package/kvStore.min.mjs +1 -1
  32. package/kvStore.min.mjs.map +1 -1
  33. package/kvStore.mjs +229 -237
  34. package/localStore.cjs +187 -186
  35. package/localStore.d.mts +135 -34
  36. package/localStore.d.ts +135 -34
  37. package/localStore.min.cjs +1 -1
  38. package/localStore.min.cjs.map +1 -1
  39. package/localStore.min.mjs +1 -1
  40. package/localStore.min.mjs.map +1 -1
  41. package/localStore.mjs +186 -184
  42. package/mean.cjs +6 -6
  43. package/mean.min.cjs +1 -1
  44. package/mean.min.cjs.map +1 -1
  45. package/mean.min.mjs +1 -1
  46. package/mean.min.mjs.map +1 -1
  47. package/mean.mjs +6 -6
  48. package/median.cjs +7 -7
  49. package/median.min.cjs +1 -1
  50. package/median.min.cjs.map +1 -1
  51. package/median.min.mjs +1 -1
  52. package/median.min.mjs.map +1 -1
  53. package/median.mjs +7 -7
  54. package/package.json +67 -82
  55. package/round.cjs +2 -10
  56. package/round.d.mts +2 -8
  57. package/round.d.ts +2 -8
  58. package/round.min.cjs +1 -1
  59. package/round.min.cjs.map +1 -1
  60. package/round.min.mjs +1 -1
  61. package/round.min.mjs.map +1 -1
  62. package/round.mjs +1 -8
  63. package/{safeParseInt.cjs → roundToString.cjs} +19 -9
  64. package/roundToString.d.mts +8 -0
  65. package/roundToString.d.ts +8 -0
  66. package/roundToString.min.cjs +2 -0
  67. package/roundToString.min.cjs.map +1 -0
  68. package/roundToString.min.mjs +2 -0
  69. package/roundToString.min.mjs.map +1 -0
  70. package/roundToString.mjs +16 -0
  71. package/safeBtoa.d.mts +7 -0
  72. package/safeBtoa.d.ts +7 -0
  73. package/safeBtoa.min.cjs.map +1 -1
  74. package/safeBtoa.min.mjs.map +1 -1
  75. package/sum.cjs +6 -6
  76. package/sum.min.cjs +1 -1
  77. package/sum.min.cjs.map +1 -1
  78. package/sum.min.mjs +1 -1
  79. package/sum.min.mjs.map +1 -1
  80. package/sum.mjs +6 -6
  81. package/timer.cjs +19 -24
  82. package/timer.d.mts +9 -6
  83. package/timer.d.ts +9 -6
  84. package/timer.min.cjs +1 -1
  85. package/timer.min.cjs.map +1 -1
  86. package/timer.min.mjs +1 -1
  87. package/timer.min.mjs.map +1 -1
  88. package/timer.mjs +19 -23
  89. package/toReadableString.cjs +69 -0
  90. package/toReadableString.d.mts +10 -0
  91. package/toReadableString.d.ts +10 -0
  92. package/toReadableString.min.cjs +6 -0
  93. package/toReadableString.min.cjs.map +1 -0
  94. package/toReadableString.min.mjs +6 -0
  95. package/toReadableString.min.mjs.map +1 -0
  96. package/toReadableString.mjs +44 -0
  97. package/average.cjs +0 -55
  98. package/average.d.mts +0 -7
  99. package/average.d.ts +0 -7
  100. package/average.min.cjs +0 -2
  101. package/average.min.cjs.map +0 -1
  102. package/average.min.mjs +0 -2
  103. package/average.min.mjs.map +0 -1
  104. package/average.mjs +0 -28
  105. package/iterators.min.cjs.map +0 -1
  106. package/iterators.min.mjs.map +0 -1
  107. package/logging.cjs +0 -47
  108. package/logging.d.mts +0 -4
  109. package/logging.d.ts +0 -4
  110. package/logging.min.cjs +0 -2
  111. package/logging.min.cjs.map +0 -1
  112. package/logging.min.mjs +0 -2
  113. package/logging.min.mjs.map +0 -1
  114. package/logging.mjs +0 -21
  115. package/safeParseFloat.cjs +0 -33
  116. package/safeParseFloat.d.mts +0 -6
  117. package/safeParseFloat.d.ts +0 -6
  118. package/safeParseFloat.min.cjs +0 -2
  119. package/safeParseFloat.min.cjs.map +0 -1
  120. package/safeParseFloat.min.mjs +0 -2
  121. package/safeParseFloat.min.mjs.map +0 -1
  122. package/safeParseFloat.mjs +0 -8
  123. package/safeParseInt.d.mts +0 -6
  124. package/safeParseInt.d.ts +0 -6
  125. package/safeParseInt.min.cjs +0 -2
  126. package/safeParseInt.min.cjs.map +0 -1
  127. package/safeParseInt.min.mjs +0 -2
  128. package/safeParseInt.min.mjs.map +0 -1
  129. package/safeParseInt.mjs +0 -8
  130. /package/{iterators.d.mts → concatIterators.d.mts} +0 -0
  131. /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.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": "rm -rf docs && typedoc `find src -name '*.ts' ! -name '*.test.ts'` --out docs --name 'Chok’s Typescript Utilities'",
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, roundS };
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, roundS };
9
+ export { round };
package/round.min.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var i=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var b=(r,n)=>{for(var t in n)i(r,t,{get:n[t],enumerable:!0})},d=(r,n,t,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of g(n))!p.call(r,o)&&o!==t&&i(r,o,{get:()=>n[o],enumerable:!(u=m(n,o))||u.enumerable});return r};var x=r=>d(i({},"__esModule",{value:!0}),r);var a={};b(a,{round:()=>e,roundS:()=>S});module.exports=x(a);function e(r,n=0){let t=Math.pow(10,n);return Math.round(r*t)/t}function S(r,n=0){return e(r,n).toLocaleString("en-US",{minimumFractionDigits:n,maximumFractionDigits:n})}0&&(module.exports={round,roundS});
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\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 roundS(n: number, numDecimalPlaces = 0): string {\n return round(n, numDecimalPlaces).toLocaleString(\"en-US\", {\n minimumFractionDigits: numDecimalPlaces,\n maximumFractionDigits: numDecimalPlaces,\n });\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,EAAA,WAAAC,IAAA,eAAAC,EAAAJ,GAMO,SAASE,EAAMG,EAAWC,EAAmB,EAAW,CAC7D,IAAMC,EAAY,KAAK,IAAI,GAAID,CAAgB,EAC/C,OAAO,KAAK,MAAMD,EAAIE,CAAS,EAAIA,CACrC,CAOO,SAASJ,EAAOE,EAAWC,EAAmB,EAAW,CAC9D,OAAOJ,EAAMG,EAAGC,CAAgB,EAAE,eAAe,QAAS,CACxD,sBAAuBA,EACvB,sBAAuBA,CACzB,CAAC,CACH","names":["round_exports","__export","round","roundS","__toCommonJS","n","numDecimalPlaces","multipler"]}
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 o(r,n=0){let t=Math.pow(10,n);return Math.round(r*t)/t}function i(r,n=0){return o(r,n).toLocaleString("en-US",{minimumFractionDigits:n,maximumFractionDigits:n})}export{o as round,i as roundS};
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\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 roundS(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,EAAMC,EAAWC,EAAmB,EAAW,CAC7D,IAAMC,EAAY,KAAK,IAAI,GAAID,CAAgB,EAC/C,OAAO,KAAK,MAAMD,EAAIE,CAAS,EAAIA,CACrC,CAOO,SAASC,EAAOH,EAAWC,EAAmB,EAAW,CAC9D,OAAOF,EAAMC,EAAGC,CAAgB,EAAE,eAAe,QAAS,CACxD,sBAAuBA,EACvB,sBAAuBA,CACzB,CAAC,CACH","names":["round","n","numDecimalPlaces","multipler","roundS"]}
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/safeParseInt.ts
21
- var safeParseInt_exports = {};
22
- __export(safeParseInt_exports, {
23
- safeParseInt: () => safeParseInt
20
+ // src/roundToString.ts
21
+ var roundToString_exports = {};
22
+ __export(roundToString_exports, {
23
+ roundToString: () => roundToString
24
24
  });
25
- module.exports = __toCommonJS(safeParseInt_exports);
26
- function safeParseInt(s, defaultValue = 0) {
27
- const i = Number(s);
28
- return isNaN(i) ? defaultValue : Math.floor(i);
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
- safeParseInt
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,2 @@
1
+ function o(n,r=0){let t=Math.pow(10,r);return Math.round(n*t)/t}function m(n,r=0){return o(n,r).toLocaleString("en-US",{minimumFractionDigits:r,maximumFractionDigits:r})}export{m as roundToString};
2
+ //# sourceMappingURL=roundToString.min.mjs.map
@@ -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
 
@@ -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,GAGO,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"]}
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"]}
@@ -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":"AAGO,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"]}
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
- const n = Number(u);
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 t=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var s=(r,n)=>{for(var e in n)t(r,e,{get:n[e],enumerable:!0})},p=(r,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let u of b(n))!f.call(r,u)&&u!==e&&t(r,u,{get:()=>n[u],enumerable:!(o=m(n,u))||o.enumerable});return r};var c=r=>p(t({},"__esModule",{value:!0}),r);var w={};s(w,{sum:()=>k});module.exports=c(w);function i(r){if(typeof r=="number"&&isFinite(r))return r;let n=Number(r);return typeof n=="number"&&isFinite(n)?n:0}function k(r){return r.reduce((n,e)=>n+i(e),0)}0&&(module.exports={sum});
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 // No transformation needed if u is already a number.\n if (typeof u === \"number\" && isFinite(u)) {\n return u;\n }\n\n // Try to make into a number if possible.\n const n = Number(u);\n if (typeof n === \"number\" && isFinite(n)) {\n return n;\n }\n\n // Return 0 for everything else. This is usually ok if want to just ignore\n // all other noise.\n return 0;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,IAAA,eAAAC,EAAAH,GCGO,SAASI,EAASC,EAAoB,CAE3C,GAAI,OAAOA,GAAM,UAAY,SAASA,CAAC,EACrC,OAAOA,EAIT,IAAM,EAAI,OAAOA,CAAC,EAClB,OAAI,OAAO,GAAM,UAAY,SAAS,CAAC,EAC9B,EAKF,CACT,CDZO,SAASC,EAAIC,EAA4B,CAC9C,OAAOA,EAAQ,OAAO,CAACC,EAAqBC,IACnCD,EAAcE,EAASD,CAAO,EACpC,CAAC,CACN","names":["sum_exports","__export","sum","__toCommonJS","asNumber","u","sum","numbers","accumulated","current","asNumber"]}
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){if(typeof n=="number"&&isFinite(n))return n;let r=Number(n);return typeof r=="number"&&isFinite(r)?r:0}function i(n){return n.reduce((r,u)=>r+e(u),0)}export{i as sum};
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 // No transformation needed if u is already a number.\n if (typeof u === \"number\" && isFinite(u)) {\n return u;\n }\n\n // Try to make into a number if possible.\n const n = Number(u);\n if (typeof n === \"number\" && isFinite(n)) {\n return n;\n }\n\n // Return 0 for everything else. This is usually ok if want to just ignore\n // all other noise.\n return 0;\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,EAAoB,CAE3C,GAAI,OAAOA,GAAM,UAAY,SAASA,CAAC,EACrC,OAAOA,EAIT,IAAMC,EAAI,OAAOD,CAAC,EAClB,OAAI,OAAOC,GAAM,UAAY,SAASA,CAAC,EAC9BA,EAKF,CACT,CCZO,SAASC,EAAIC,EAA4B,CAC9C,OAAOA,EAAQ,OAAO,CAACC,EAAqBC,IACnCD,EAAcE,EAASD,CAAO,EACpC,CAAC,CACN","names":["asNumber","u","n","sum","numbers","accumulated","current","asNumber"]}
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
- const n = Number(u);
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
- return new Timer();
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
  });