@choksheak/ts-utils 0.2.8 → 0.3.0

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 (275) hide show
  1. package/README.md +2 -0
  2. package/{arrayBuffer.js → arrayBuffer.cjs} +0 -1
  3. package/arrayBuffer.d.mts +10 -0
  4. package/arrayBuffer.min.cjs +2 -0
  5. package/arrayBuffer.min.cjs.map +1 -0
  6. package/arrayBuffer.min.mjs +2 -0
  7. package/{arrayBuffer.js.map → arrayBuffer.min.mjs.map} +1 -1
  8. package/arrayBuffer.mjs +14 -0
  9. package/{assert.js → assert.cjs} +3 -2
  10. package/assert.d.mts +7 -0
  11. package/assert.d.ts +1 -1
  12. package/assert.min.cjs +2 -0
  13. package/assert.min.cjs.map +1 -0
  14. package/assert.min.mjs +2 -0
  15. package/assert.min.mjs.map +1 -0
  16. package/assert.mjs +11 -0
  17. package/{average.js → average.cjs} +0 -1
  18. package/average.d.mts +7 -0
  19. package/average.min.cjs +2 -0
  20. package/{average.js.map → average.min.cjs.map} +1 -1
  21. package/average.min.mjs +2 -0
  22. package/average.min.mjs.map +1 -0
  23. package/average.mjs +20 -0
  24. package/base64Url.cjs +40 -0
  25. package/base64Url.d.mts +10 -0
  26. package/base64Url.d.ts +8 -0
  27. package/base64Url.min.cjs +2 -0
  28. package/base64Url.min.cjs.map +1 -0
  29. package/base64Url.min.mjs +2 -0
  30. package/base64Url.min.mjs.map +1 -0
  31. package/base64Url.mjs +14 -0
  32. package/{dateTimeStr.js → dateTimeStr.cjs} +0 -1
  33. package/dateTimeStr.d.mts +85 -0
  34. package/dateTimeStr.min.cjs +2 -0
  35. package/dateTimeStr.min.cjs.map +1 -0
  36. package/dateTimeStr.min.mjs +2 -0
  37. package/{dateTimeStr.js.map → dateTimeStr.min.mjs.map} +1 -1
  38. package/dateTimeStr.mjs +83 -0
  39. package/{duration.js → duration.cjs} +9 -11
  40. package/duration.d.mts +78 -0
  41. package/duration.min.cjs +2 -0
  42. package/duration.min.cjs.map +1 -0
  43. package/duration.min.mjs +2 -0
  44. package/duration.min.mjs.map +1 -0
  45. package/duration.mjs +154 -0
  46. package/{isEmpty.js → isEmpty.cjs} +0 -1
  47. package/isEmpty.d.mts +6 -0
  48. package/isEmpty.min.cjs +2 -0
  49. package/isEmpty.min.cjs.map +1 -0
  50. package/isEmpty.min.mjs +2 -0
  51. package/{isEmpty.js.map → isEmpty.min.mjs.map} +1 -1
  52. package/isEmpty.mjs +22 -0
  53. package/kvStore.cjs +333 -0
  54. package/kvStore.d.mts +97 -0
  55. package/kvStore.min.cjs +2 -0
  56. package/kvStore.min.cjs.map +1 -0
  57. package/kvStore.min.mjs +2 -0
  58. package/kvStore.min.mjs.map +1 -0
  59. package/kvStore.mjs +300 -0
  60. package/{localStorageCache.js → localStorageCache.cjs} +5 -7
  61. package/localStorageCache.d.mts +57 -0
  62. package/localStorageCache.min.cjs +2 -0
  63. package/localStorageCache.min.cjs.map +1 -0
  64. package/localStorageCache.min.mjs +2 -0
  65. package/localStorageCache.min.mjs.map +1 -0
  66. package/localStorageCache.mjs +92 -0
  67. package/{logging.js → logging.cjs} +0 -1
  68. package/logging.d.mts +4 -0
  69. package/logging.min.cjs +2 -0
  70. package/logging.min.cjs.map +1 -0
  71. package/logging.min.mjs +2 -0
  72. package/{logging.js.map → logging.min.mjs.map} +1 -1
  73. package/logging.mjs +21 -0
  74. package/{nonEmpty.js → nonEmpty.cjs} +0 -1
  75. package/nonEmpty.d.mts +10 -0
  76. package/nonEmpty.min.cjs +2 -0
  77. package/{nonEmpty.js.map → nonEmpty.min.cjs.map} +1 -1
  78. package/nonEmpty.min.mjs +2 -0
  79. package/nonEmpty.min.mjs.map +1 -0
  80. package/nonEmpty.mjs +30 -0
  81. package/{nonNil.js → nonNil.cjs} +0 -1
  82. package/{src/nonNil.ts → nonNil.d.mts} +3 -6
  83. package/nonNil.min.cjs +2 -0
  84. package/nonNil.min.cjs.map +1 -0
  85. package/nonNil.min.mjs +2 -0
  86. package/{nonNil.js.map → nonNil.min.mjs.map} +1 -1
  87. package/nonNil.mjs +10 -0
  88. package/package.json +414 -24
  89. package/{round.js → round.cjs} +0 -1
  90. package/{src/round.ts → round.d.mts} +4 -8
  91. package/round.min.cjs +2 -0
  92. package/round.min.cjs.map +1 -0
  93. package/round.min.mjs +2 -0
  94. package/{round.js.map → round.min.mjs.map} +1 -1
  95. package/round.mjs +12 -0
  96. package/{safeBtoa.js → safeBtoa.cjs} +0 -1
  97. package/safeBtoa.d.mts +6 -0
  98. package/safeBtoa.min.cjs +2 -0
  99. package/safeBtoa.min.cjs.map +1 -0
  100. package/safeBtoa.min.mjs +2 -0
  101. package/{safeBtoa.js.map → safeBtoa.min.mjs.map} +1 -1
  102. package/safeBtoa.mjs +9 -0
  103. package/{safeParseFloat.js → safeParseFloat.cjs} +0 -1
  104. package/safeParseFloat.d.mts +6 -0
  105. package/safeParseFloat.min.cjs +2 -0
  106. package/safeParseFloat.min.cjs.map +1 -0
  107. package/safeParseFloat.min.mjs +2 -0
  108. package/{safeParseFloat.js.map → safeParseFloat.min.mjs.map} +1 -1
  109. package/safeParseFloat.mjs +8 -0
  110. package/{safeParseInt.js → safeParseInt.cjs} +0 -1
  111. package/safeParseInt.d.mts +6 -0
  112. package/safeParseInt.min.cjs +2 -0
  113. package/safeParseInt.min.cjs.map +1 -0
  114. package/safeParseInt.min.mjs +2 -0
  115. package/{safeParseInt.js.map → safeParseInt.min.mjs.map} +1 -1
  116. package/safeParseInt.mjs +8 -0
  117. package/sha256.cjs +35 -0
  118. package/sha256.d.mts +6 -0
  119. package/sha256.min.cjs +2 -0
  120. package/sha256.min.cjs.map +1 -0
  121. package/sha256.min.mjs +2 -0
  122. package/{sha256.js.map → sha256.min.mjs.map} +1 -1
  123. package/sha256.mjs +10 -0
  124. package/{sleep.js → sleep.cjs} +0 -1
  125. package/{src/sleep.ts → sleep.d.mts} +3 -3
  126. package/sleep.min.cjs +2 -0
  127. package/sleep.min.cjs.map +1 -0
  128. package/sleep.min.mjs +2 -0
  129. package/{sleep.js.map → sleep.min.mjs.map} +1 -1
  130. package/sleep.mjs +7 -0
  131. package/{sum.js → sum.cjs} +0 -1
  132. package/sum.d.mts +7 -0
  133. package/sum.min.cjs +2 -0
  134. package/sum.min.cjs.map +1 -0
  135. package/sum.min.mjs +2 -0
  136. package/{sum.js.map → sum.min.mjs.map} +1 -1
  137. package/sum.mjs +13 -0
  138. package/{timeConstants.js → timeConstants.cjs} +0 -1
  139. package/timeConstants.d.mts +20 -0
  140. package/timeConstants.min.cjs +2 -0
  141. package/timeConstants.min.cjs.map +1 -0
  142. package/timeConstants.min.mjs +2 -0
  143. package/{timeConstants.js.map → timeConstants.min.mjs.map} +1 -1
  144. package/timeConstants.mjs +31 -0
  145. package/{timer.js → timer.cjs} +6 -6
  146. package/timer.d.mts +13 -0
  147. package/timer.min.cjs +2 -0
  148. package/timer.min.cjs.map +1 -0
  149. package/timer.min.mjs +2 -0
  150. package/timer.min.mjs.map +1 -0
  151. package/timer.mjs +161 -0
  152. package/assert.js.map +0 -1
  153. package/docs/.nojekyll +0 -1
  154. package/docs/assets/hierarchy.js +0 -1
  155. package/docs/assets/highlight.css +0 -22
  156. package/docs/assets/icons.js +0 -18
  157. package/docs/assets/icons.svg +0 -1
  158. package/docs/assets/main.js +0 -60
  159. package/docs/assets/navigation.js +0 -1
  160. package/docs/assets/search.js +0 -1
  161. package/docs/assets/style.css +0 -1640
  162. package/docs/classes/kvStore.KVStore.html +0 -26
  163. package/docs/classes/kvStore.KVStoreField.html +0 -7
  164. package/docs/classes/timer.Timer.html +0 -8
  165. package/docs/functions/arrayBuffer.arrayBufferToBase64.html +0 -2
  166. package/docs/functions/arrayBuffer.arrayBufferToHex.html +0 -2
  167. package/docs/functions/assert.assert.html +0 -3
  168. package/docs/functions/average.average.html +0 -3
  169. package/docs/functions/dateTimeStr.getDisplayDateTime.html +0 -3
  170. package/docs/functions/dateTimeStr.getLongMonthNameOneIndexed.html +0 -4
  171. package/docs/functions/dateTimeStr.getLongMonthNameZeroIndexed.html +0 -4
  172. package/docs/functions/dateTimeStr.getShortMonthNameOneIndexed.html +0 -4
  173. package/docs/functions/dateTimeStr.getShortMonthNameZeroIndexed.html +0 -4
  174. package/docs/functions/dateTimeStr.hhMm.html +0 -4
  175. package/docs/functions/dateTimeStr.hhMmSs.html +0 -4
  176. package/docs/functions/dateTimeStr.hhMmSsMs.html +0 -5
  177. package/docs/functions/dateTimeStr.toDate.html +0 -4
  178. package/docs/functions/dateTimeStr.tzShort.html +0 -4
  179. package/docs/functions/dateTimeStr.yyyyMm.html +0 -4
  180. package/docs/functions/dateTimeStr.yyyyMmDd.html +0 -4
  181. package/docs/functions/duration.durationOrMsToMs.html +0 -2
  182. package/docs/functions/duration.durationToMs.html +0 -2
  183. package/docs/functions/duration.elapsed.html +0 -2
  184. package/docs/functions/duration.formatDuration.html +0 -4
  185. package/docs/functions/duration.msToDuration.html +0 -5
  186. package/docs/functions/duration.readableDuration.html +0 -4
  187. package/docs/functions/isEmpty.isEmpty.html +0 -2
  188. package/docs/functions/kvStore.kvStoreItem.html +0 -2
  189. package/docs/functions/localStorageCache.storeItem.html +0 -15
  190. package/docs/functions/logging.capLength.html +0 -1
  191. package/docs/functions/logging.stringify.html +0 -1
  192. package/docs/functions/nonEmpty.nonEmpty.html +0 -5
  193. package/docs/functions/nonNil.nonNil.html +0 -5
  194. package/docs/functions/round.round.html +0 -5
  195. package/docs/functions/round.roundS.html +0 -3
  196. package/docs/functions/safeBtoa.safeBtoa.html +0 -2
  197. package/docs/functions/safeParseFloat.safeParseFloat.html +0 -2
  198. package/docs/functions/safeParseInt.safeParseInt.html +0 -2
  199. package/docs/functions/sha256.sha256.html +0 -2
  200. package/docs/functions/sleep.sleep.html +0 -3
  201. package/docs/functions/sum.sum.html +0 -3
  202. package/docs/functions/timer.timer.html +0 -2
  203. package/docs/hierarchy.html +0 -1
  204. package/docs/index.html +0 -4
  205. package/docs/modules/arrayBuffer.html +0 -1
  206. package/docs/modules/assert.html +0 -1
  207. package/docs/modules/average.html +0 -1
  208. package/docs/modules/dateTimeStr.html +0 -1
  209. package/docs/modules/duration.html +0 -1
  210. package/docs/modules/isEmpty.html +0 -1
  211. package/docs/modules/kvStore.html +0 -1
  212. package/docs/modules/localStorageCache.html +0 -1
  213. package/docs/modules/logging.html +0 -1
  214. package/docs/modules/nonEmpty.html +0 -1
  215. package/docs/modules/nonNil.html +0 -1
  216. package/docs/modules/round.html +0 -1
  217. package/docs/modules/safeBtoa.html +0 -1
  218. package/docs/modules/safeParseFloat.html +0 -1
  219. package/docs/modules/safeParseInt.html +0 -1
  220. package/docs/modules/sha256.html +0 -1
  221. package/docs/modules/sleep.html +0 -1
  222. package/docs/modules/sum.html +0 -1
  223. package/docs/modules/timeConstants.html +0 -1
  224. package/docs/modules/timer.html +0 -1
  225. package/docs/modules.html +0 -1
  226. package/docs/types/dateTimeStr.AnyDateTime.html +0 -1
  227. package/docs/types/duration.Duration.html +0 -6
  228. package/docs/types/duration.DurationStyle.html +0 -6
  229. package/docs/types/duration.DurationSuffixMap.html +0 -6
  230. package/docs/types/duration.DurationSuffixType.html +0 -1
  231. package/docs/types/duration.DurationType.html +0 -2
  232. package/docs/types/localStorageCache.StoredItem.html +0 -4
  233. package/docs/variables/duration.DURATION_STYLE_SUFFIX_MAP.html +0 -1
  234. package/docs/variables/duration.DURATION_TYPE_SEQUENCE.html +0 -2
  235. package/docs/variables/kvStore.DEFAULT_EXPIRY_DELTA_MS.html +0 -2
  236. package/docs/variables/kvStore.GC_INTERVAL_MS.html +0 -2
  237. package/docs/variables/kvStore.MILLIS_PER_DAY.html +0 -2
  238. package/docs/variables/kvStore.kvStore.html +0 -3
  239. package/docs/variables/timeConstants.HOURS_PER_DAY.html +0 -1
  240. package/docs/variables/timeConstants.HOURS_PER_WEEK.html +0 -1
  241. package/docs/variables/timeConstants.MINUTES_PER_DAY.html +0 -1
  242. package/docs/variables/timeConstants.MINUTES_PER_HOUR.html +0 -1
  243. package/docs/variables/timeConstants.MINUTES_PER_WEEK.html +0 -1
  244. package/docs/variables/timeConstants.MS_PER_DAY.html +0 -1
  245. package/docs/variables/timeConstants.MS_PER_HOUR.html +0 -1
  246. package/docs/variables/timeConstants.MS_PER_MINUTE.html +0 -1
  247. package/docs/variables/timeConstants.MS_PER_SECOND.html +0 -3
  248. package/docs/variables/timeConstants.MS_PER_WEEK.html +0 -1
  249. package/docs/variables/timeConstants.SECONDS_PER_DAY.html +0 -1
  250. package/docs/variables/timeConstants.SECONDS_PER_HOUR.html +0 -1
  251. package/docs/variables/timeConstants.SECONDS_PER_MINUTE.html +0 -1
  252. package/docs/variables/timeConstants.SECONDS_PER_WEEK.html +0 -1
  253. package/duration.js.map +0 -1
  254. package/kvStore.js +0 -383
  255. package/kvStore.js.map +0 -1
  256. package/localStorageCache.js.map +0 -1
  257. package/sha256.js +0 -58
  258. package/src/arrayBuffer.ts +0 -29
  259. package/src/assert.ts +0 -12
  260. package/src/average.ts +0 -13
  261. package/src/dateTimeStr.ts +0 -184
  262. package/src/duration.ts +0 -260
  263. package/src/isEmpty.ts +0 -32
  264. package/src/kvStore.ts +0 -444
  265. package/src/localStorageCache.ts +0 -121
  266. package/src/logging.ts +0 -26
  267. package/src/nonEmpty.ts +0 -18
  268. package/src/safeBtoa.ts +0 -15
  269. package/src/safeParseFloat.ts +0 -10
  270. package/src/safeParseInt.ts +0 -10
  271. package/src/sha256.ts +0 -13
  272. package/src/sum.ts +0 -17
  273. package/src/timeConstants.ts +0 -22
  274. package/src/timer.ts +0 -33
  275. package/timer.js.map +0 -1
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns 0 or the given defaultValue if the string is not a valid number.
3
+ */
4
+ declare function safeParseFloat<T>(s: string, defaultValue?: T | number): T | number;
5
+
6
+ export { safeParseFloat };
@@ -0,0 +1,2 @@
1
+ "use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var b=(e,r)=>{for(var n in r)s(e,n,{get:r[n],enumerable:!0})},m=(e,r,n,u)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of i(r))!o.call(e,t)&&t!==n&&s(e,t,{get:()=>r[t],enumerable:!(u=a(r,t))||u.enumerable});return e};var N=e=>m(s({},"__esModule",{value:!0}),e);var c={};b(c,{safeParseFloat:()=>T});module.exports=N(c);function T(e,r=0){let n=Number(e);return isNaN(n)?r:n}0&&(module.exports={safeParseFloat});
2
+ //# sourceMappingURL=safeParseFloat.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/safeParseFloat.ts"],"sourcesContent":["/**\n * Returns 0 or the given defaultValue if the string is not a valid number.\n */\nexport function safeParseFloat<T>(\n s: string,\n defaultValue: T | number = 0,\n): T | number {\n const i = Number(s);\n return isNaN(i) ? defaultValue : i;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,IAAA,eAAAC,EAAAH,GAGO,SAASE,EACdE,EACAC,EAA2B,EACf,CACZ,IAAMC,EAAI,OAAOF,CAAC,EAClB,OAAO,MAAME,CAAC,EAAID,EAAeC,CACnC","names":["safeParseFloat_exports","__export","safeParseFloat","__toCommonJS","s","defaultValue","i"]}
@@ -0,0 +1,2 @@
1
+ function t(e,n=0){let r=Number(e);return isNaN(r)?n:r}export{t as safeParseFloat};
2
+ //# sourceMappingURL=safeParseFloat.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/safeParseFloat.ts"],"sourcesContent":["/**\n * Returns 0 or the given defaultValue if the string is not a valid number.\n */\nexport function safeParseFloat<T>(\n s: string,\n defaultValue: T | number = 0,\n): T | number {\n const i = Number(s);\n return isNaN(i) ? defaultValue : i;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,eACd,GACA,eAA2B,GACf;AACZ,QAAM,IAAI,OAAO,CAAC;AAClB,SAAO,MAAM,CAAC,IAAI,eAAe;AACnC;","names":[]}
1
+ {"version":3,"sources":["../src/safeParseFloat.ts"],"sourcesContent":["/**\n * Returns 0 or the given defaultValue if the string is not a valid number.\n */\nexport function safeParseFloat<T>(\n s: string,\n defaultValue: T | number = 0,\n): T | number {\n const i = Number(s);\n return isNaN(i) ? defaultValue : i;\n}\n"],"mappings":"AAGO,SAASA,EACdC,EACAC,EAA2B,EACf,CACZ,IAAMC,EAAI,OAAOF,CAAC,EAClB,OAAO,MAAME,CAAC,EAAID,EAAeC,CACnC","names":["safeParseFloat","s","defaultValue","i"]}
@@ -0,0 +1,8 @@
1
+ // src/safeParseFloat.ts
2
+ function safeParseFloat(s, defaultValue = 0) {
3
+ const i = Number(s);
4
+ return isNaN(i) ? defaultValue : i;
5
+ }
6
+ export {
7
+ safeParseFloat
8
+ };
@@ -31,4 +31,3 @@ function safeParseInt(s, defaultValue = 0) {
31
31
  0 && (module.exports = {
32
32
  safeParseInt
33
33
  });
34
- //# sourceMappingURL=safeParseInt.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns 0 or the given defaultValue if the string is not a valid number.
3
+ */
4
+ declare function safeParseInt<T>(s: string, defaultValue?: T | number): T | number;
5
+
6
+ export { safeParseInt };
@@ -0,0 +1,2 @@
1
+ "use strict";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var b=(n,r)=>{for(var e in r)o(n,e,{get:r[e],enumerable:!0})},f=(n,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of a(r))!i.call(n,t)&&t!==e&&o(n,t,{get:()=>r[t],enumerable:!(s=u(r,t))||s.enumerable});return n};var m=n=>f(o({},"__esModule",{value:!0}),n);var T={};b(T,{safeParseInt:()=>N});module.exports=m(T);function N(n,r=0){let e=Number(n);return isNaN(e)?r:Math.floor(e)}0&&(module.exports={safeParseInt});
2
+ //# sourceMappingURL=safeParseInt.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/safeParseInt.ts"],"sourcesContent":["/**\n * Returns 0 or the given defaultValue if the string is not a valid number.\n */\nexport function safeParseInt<T>(\n s: string,\n defaultValue: T | number = 0,\n): T | number {\n const i = Number(s);\n return isNaN(i) ? defaultValue : Math.floor(i);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAGO,SAASE,EACdE,EACAC,EAA2B,EACf,CACZ,IAAMC,EAAI,OAAOF,CAAC,EAClB,OAAO,MAAME,CAAC,EAAID,EAAe,KAAK,MAAMC,CAAC,CAC/C","names":["safeParseInt_exports","__export","safeParseInt","__toCommonJS","s","defaultValue","i"]}
@@ -0,0 +1,2 @@
1
+ function t(n,e=0){let r=Number(n);return isNaN(r)?e:Math.floor(r)}export{t as safeParseInt};
2
+ //# sourceMappingURL=safeParseInt.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/safeParseInt.ts"],"sourcesContent":["/**\n * Returns 0 or the given defaultValue if the string is not a valid number.\n */\nexport function safeParseInt<T>(\n s: string,\n defaultValue: T | number = 0,\n): T | number {\n const i = Number(s);\n return isNaN(i) ? defaultValue : Math.floor(i);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,aACd,GACA,eAA2B,GACf;AACZ,QAAM,IAAI,OAAO,CAAC;AAClB,SAAO,MAAM,CAAC,IAAI,eAAe,KAAK,MAAM,CAAC;AAC/C;","names":[]}
1
+ {"version":3,"sources":["../src/safeParseInt.ts"],"sourcesContent":["/**\n * Returns 0 or the given defaultValue if the string is not a valid number.\n */\nexport function safeParseInt<T>(\n s: string,\n defaultValue: T | number = 0,\n): T | number {\n const i = Number(s);\n return isNaN(i) ? defaultValue : Math.floor(i);\n}\n"],"mappings":"AAGO,SAASA,EACdC,EACAC,EAA2B,EACf,CACZ,IAAMC,EAAI,OAAOF,CAAC,EAClB,OAAO,MAAME,CAAC,EAAID,EAAe,KAAK,MAAMC,CAAC,CAC/C","names":["safeParseInt","s","defaultValue","i"]}
@@ -0,0 +1,8 @@
1
+ // src/safeParseInt.ts
2
+ function safeParseInt(s, defaultValue = 0) {
3
+ const i = Number(s);
4
+ return isNaN(i) ? defaultValue : Math.floor(i);
5
+ }
6
+ export {
7
+ safeParseInt
8
+ };
package/sha256.cjs ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/sha256.ts
21
+ var sha256_exports = {};
22
+ __export(sha256_exports, {
23
+ sha256: () => sha256
24
+ });
25
+ module.exports = __toCommonJS(sha256_exports);
26
+ async function sha256(input) {
27
+ const encoder = new TextEncoder();
28
+ const uint8Array = encoder.encode(input);
29
+ const arrayBuffer = await crypto.subtle.digest("SHA-256", uint8Array);
30
+ return arrayBuffer;
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ sha256
35
+ });
package/sha256.d.mts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * SHA-256 hash an input string into an ArrayBuffer.
3
+ */
4
+ declare function sha256(input: string): Promise<ArrayBuffer>;
5
+
6
+ export { sha256 };
package/sha256.min.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var u=(e,r)=>{for(var n in r)a(e,n,{get:r[n],enumerable:!0})},i=(e,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of s(r))!f.call(e,t)&&t!==n&&a(e,t,{get:()=>r[t],enumerable:!(o=c(r,t))||o.enumerable});return e};var y=e=>i(a({},"__esModule",{value:!0}),e);var A={};u(A,{sha256:()=>d});module.exports=y(A);async function d(e){let n=new TextEncoder().encode(e);return await crypto.subtle.digest("SHA-256",n)}0&&(module.exports={sha256});
2
+ //# sourceMappingURL=sha256.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sha256.ts"],"sourcesContent":["/**\n * SHA-256 hash an input string into an ArrayBuffer.\n */\nexport async function sha256(input: string): Promise<ArrayBuffer> {\n // Encode the input string as a Uint8Array\n const encoder = new TextEncoder();\n const uint8Array = encoder.encode(input);\n\n // Compute the SHA-256 hash using the SubtleCrypto API\n const arrayBuffer = await crypto.subtle.digest(\"SHA-256\", uint8Array);\n\n return arrayBuffer;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAGA,eAAsBE,EAAOE,EAAqC,CAGhE,IAAMC,EADU,IAAI,YAAY,EACL,OAAOD,CAAK,EAKvC,OAFoB,MAAM,OAAO,OAAO,OAAO,UAAWC,CAAU,CAGtE","names":["sha256_exports","__export","sha256","__toCommonJS","input","uint8Array"]}
package/sha256.min.mjs ADDED
@@ -0,0 +1,2 @@
1
+ async function o(r){let e=new TextEncoder().encode(r);return await crypto.subtle.digest("SHA-256",e)}export{o as sha256};
2
+ //# sourceMappingURL=sha256.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sha256.ts"],"sourcesContent":["/**\n * SHA-256 hash an input string into an ArrayBuffer.\n */\nexport async function sha256(input: string): Promise<ArrayBuffer> {\n // Encode the input string as a Uint8Array\n const encoder = new TextEncoder();\n const uint8Array = encoder.encode(input);\n\n // Compute the SHA-256 hash using the SubtleCrypto API\n const arrayBuffer = await crypto.subtle.digest(\"SHA-256\", uint8Array);\n\n return arrayBuffer;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,SAAsB,OAAO,OAAqC;AAAA;AAEhE,UAAM,UAAU,IAAI,YAAY;AAChC,UAAM,aAAa,QAAQ,OAAO,KAAK;AAGvC,UAAM,cAAc,MAAM,OAAO,OAAO,OAAO,WAAW,UAAU;AAEpE,WAAO;AAAA,EACT;AAAA;","names":[]}
1
+ {"version":3,"sources":["../src/sha256.ts"],"sourcesContent":["/**\n * SHA-256 hash an input string into an ArrayBuffer.\n */\nexport async function sha256(input: string): Promise<ArrayBuffer> {\n // Encode the input string as a Uint8Array\n const encoder = new TextEncoder();\n const uint8Array = encoder.encode(input);\n\n // Compute the SHA-256 hash using the SubtleCrypto API\n const arrayBuffer = await crypto.subtle.digest(\"SHA-256\", uint8Array);\n\n return arrayBuffer;\n}\n"],"mappings":"AAGA,eAAsBA,EAAOC,EAAqC,CAGhE,IAAMC,EADU,IAAI,YAAY,EACL,OAAOD,CAAK,EAKvC,OAFoB,MAAM,OAAO,OAAO,OAAO,UAAWC,CAAU,CAGtE","names":["sha256","input","uint8Array"]}
package/sha256.mjs ADDED
@@ -0,0 +1,10 @@
1
+ // src/sha256.ts
2
+ async function sha256(input) {
3
+ const encoder = new TextEncoder();
4
+ const uint8Array = encoder.encode(input);
5
+ const arrayBuffer = await crypto.subtle.digest("SHA-256", uint8Array);
6
+ return arrayBuffer;
7
+ }
8
+ export {
9
+ sha256
10
+ };
@@ -30,4 +30,3 @@ function sleep(ms) {
30
30
  0 && (module.exports = {
31
31
  sleep
32
32
  });
33
- //# sourceMappingURL=sleep.js.map
@@ -2,6 +2,6 @@
2
2
  * Sleep for a given number of milliseconds. Note that this method is async,
3
3
  * so please remember to call it with await, like `await sleep(1000);`.
4
4
  */
5
- export function sleep(ms: number): Promise<void> {
6
- return new Promise((resolve) => setTimeout(resolve, ms));
7
- }
5
+ declare function sleep(ms: number): Promise<void>;
6
+
7
+ export { sleep };
package/sleep.min.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var n=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var p=(o,e)=>{for(var i in e)n(o,i,{get:e[i],enumerable:!0})},P=(o,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of s(e))!u.call(o,r)&&r!==i&&n(o,r,{get:()=>e[r],enumerable:!(t=m(e,r))||t.enumerable});return o};var b=o=>P(n({},"__esModule",{value:!0}),o);var d={};p(d,{sleep:()=>c});module.exports=b(d);function c(o){return new Promise(e=>setTimeout(e,o))}0&&(module.exports={sleep});
2
+ //# sourceMappingURL=sleep.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sleep.ts"],"sourcesContent":["/**\n * Sleep for a given number of milliseconds. Note that this method is async,\n * so please remember to call it with await, like `await sleep(1000);`.\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,IAAA,eAAAC,EAAAH,GAIO,SAASE,EAAME,EAA2B,CAC/C,OAAO,IAAI,QAASC,GAAY,WAAWA,EAASD,CAAE,CAAC,CACzD","names":["sleep_exports","__export","sleep","__toCommonJS","ms","resolve"]}
package/sleep.min.mjs ADDED
@@ -0,0 +1,2 @@
1
+ function r(e){return new Promise(o=>setTimeout(o,e))}export{r as sleep};
2
+ //# sourceMappingURL=sleep.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sleep.ts"],"sourcesContent":["/**\n * Sleep for a given number of milliseconds. Note that this method is async,\n * so please remember to call it with await, like `await sleep(1000);`.\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,MAAM,IAA2B;AAC/C,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AACzD;","names":[]}
1
+ {"version":3,"sources":["../src/sleep.ts"],"sourcesContent":["/**\n * Sleep for a given number of milliseconds. Note that this method is async,\n * so please remember to call it with await, like `await sleep(1000);`.\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":"AAIO,SAASA,EAAMC,EAA2B,CAC/C,OAAO,IAAI,QAASC,GAAY,WAAWA,EAASD,CAAE,CAAC,CACzD","names":["sleep","ms","resolve"]}
package/sleep.mjs ADDED
@@ -0,0 +1,7 @@
1
+ // src/sleep.ts
2
+ function sleep(ms) {
3
+ return new Promise((resolve) => setTimeout(resolve, ms));
4
+ }
5
+ export {
6
+ sleep
7
+ };
@@ -36,4 +36,3 @@ function sum(numbers) {
36
36
  0 && (module.exports = {
37
37
  sum
38
38
  });
39
- //# sourceMappingURL=sum.js.map
package/sum.d.mts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Add all the numbers together in the given array. Treats null, undefined and
3
+ * NaN as zero.
4
+ */
5
+ declare function sum(numbers: (number | null | undefined)[]): number;
6
+
7
+ export { sum };
package/sum.min.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var b=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var r=Object.prototype.hasOwnProperty;var f=(n,e)=>{for(var u in e)b(n,u,{get:e[u],enumerable:!0})},o=(n,e,u,m)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of l(e))!r.call(n,i)&&i!==u&&b(n,i,{get:()=>e[i],enumerable:!(m=d(e,i))||m.enumerable});return n};var s=n=>o(b({},"__esModule",{value:!0}),n);var a={};f(a,{sum:()=>t});module.exports=s(a);function t(n){return n.reduce((e,u)=>{let m=typeof u=="number"&&!isNaN(u)&&isFinite(u)?u:0;return e+m},0)}0&&(module.exports={sum});
2
+ //# sourceMappingURL=sum.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sum.ts"],"sourcesContent":["/**\n * Add all the numbers together in the given array. Treats null, undefined and\n * NaN as zero.\n */\nexport function sum(numbers: (number | null | undefined)[]): number {\n return numbers.reduce(\n (accumulated: number, current: number | null | undefined) => {\n const value =\n typeof current === \"number\" && !isNaN(current) && isFinite(current)\n ? current\n : 0;\n\n return accumulated + value;\n },\n 0,\n );\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,SAAAE,IAAA,eAAAC,EAAAH,GAIO,SAASE,EAAIE,EAAgD,CAClE,OAAOA,EAAQ,OACb,CAACC,EAAqBC,IAAuC,CAC3D,IAAMC,EACJ,OAAOD,GAAY,UAAY,CAAC,MAAMA,CAAO,GAAK,SAASA,CAAO,EAC9DA,EACA,EAEN,OAAOD,EAAcE,CACvB,EACA,CACF,CACF","names":["sum_exports","__export","sum","__toCommonJS","numbers","accumulated","current","value"]}
package/sum.min.mjs ADDED
@@ -0,0 +1,2 @@
1
+ function m(n){return n.reduce((u,e)=>{let i=typeof e=="number"&&!isNaN(e)&&isFinite(e)?e:0;return u+i},0)}export{m as sum};
2
+ //# sourceMappingURL=sum.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sum.ts"],"sourcesContent":["/**\n * Add all the numbers together in the given array. Treats null, undefined and\n * NaN as zero.\n */\nexport function sum(numbers: (number | null | undefined)[]): number {\n return numbers.reduce(\n (accumulated: number, current: number | null | undefined) => {\n const value =\n typeof current === \"number\" && !isNaN(current) && isFinite(current)\n ? current\n : 0;\n\n return accumulated + value;\n },\n 0,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,IAAI,SAAgD;AAClE,SAAO,QAAQ;AAAA,IACb,CAAC,aAAqB,YAAuC;AAC3D,YAAM,QACJ,OAAO,YAAY,YAAY,CAAC,MAAM,OAAO,KAAK,SAAS,OAAO,IAC9D,UACA;AAEN,aAAO,cAAc;AAAA,IACvB;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/sum.ts"],"sourcesContent":["/**\n * Add all the numbers together in the given array. Treats null, undefined and\n * NaN as zero.\n */\nexport function sum(numbers: (number | null | undefined)[]): number {\n return numbers.reduce(\n (accumulated: number, current: number | null | undefined) => {\n const value =\n typeof current === \"number\" && !isNaN(current) && isFinite(current)\n ? current\n : 0;\n\n return accumulated + value;\n },\n 0,\n );\n}\n"],"mappings":"AAIO,SAASA,EAAIC,EAAgD,CAClE,OAAOA,EAAQ,OACb,CAACC,EAAqBC,IAAuC,CAC3D,IAAMC,EACJ,OAAOD,GAAY,UAAY,CAAC,MAAMA,CAAO,GAAK,SAASA,CAAO,EAC9DA,EACA,EAEN,OAAOD,EAAcE,CACvB,EACA,CACF,CACF","names":["sum","numbers","accumulated","current","value"]}
package/sum.mjs ADDED
@@ -0,0 +1,13 @@
1
+ // src/sum.ts
2
+ function sum(numbers) {
3
+ return numbers.reduce(
4
+ (accumulated, current) => {
5
+ const value = typeof current === "number" && !isNaN(current) && isFinite(current) ? current : 0;
6
+ return accumulated + value;
7
+ },
8
+ 0
9
+ );
10
+ }
11
+ export {
12
+ sum
13
+ };
@@ -67,4 +67,3 @@ var HOURS_PER_WEEK = 168;
67
67
  SECONDS_PER_MINUTE,
68
68
  SECONDS_PER_WEEK
69
69
  });
70
- //# sourceMappingURL=timeConstants.js.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Note that month and year do not have fixed durations, and hence are excluded
3
+ * from this file.
4
+ */
5
+ declare const MS_PER_SECOND = 1000;
6
+ declare const MS_PER_MINUTE = 60000;
7
+ declare const MS_PER_HOUR = 3600000;
8
+ declare const MS_PER_DAY = 86400000;
9
+ declare const MS_PER_WEEK = 604800000;
10
+ declare const SECONDS_PER_MINUTE = 60;
11
+ declare const SECONDS_PER_HOUR = 3600;
12
+ declare const SECONDS_PER_DAY = 86400;
13
+ declare const SECONDS_PER_WEEK = 604800;
14
+ declare const MINUTES_PER_HOUR = 60;
15
+ declare const MINUTES_PER_DAY = 1440;
16
+ declare const MINUTES_PER_WEEK = 10080;
17
+ declare const HOURS_PER_DAY = 24;
18
+ declare const HOURS_PER_WEEK = 168;
19
+
20
+ export { HOURS_PER_DAY, HOURS_PER_WEEK, MINUTES_PER_DAY, MINUTES_PER_HOUR, MINUTES_PER_WEEK, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, MS_PER_SECOND, MS_PER_WEEK, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, SECONDS_PER_WEEK };
@@ -0,0 +1,2 @@
1
+ "use strict";var R=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var e=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var p=(E,_)=>{for(var t in _)R(E,t,{get:_[t],enumerable:!0})},r=(E,_,t,S)=>{if(_&&typeof _=="object"||typeof _=="function")for(let o of e(_))!n.call(E,o)&&o!==t&&R(E,o,{get:()=>_[o],enumerable:!(S=c(_,o))||S.enumerable});return E};var s=E=>r(R({},"__esModule",{value:!0}),E);var Y={};p(Y,{HOURS_PER_DAY:()=>K,HOURS_PER_WEEK:()=>W,MINUTES_PER_DAY:()=>T,MINUTES_PER_HOUR:()=>I,MINUTES_PER_WEEK:()=>A,MS_PER_DAY:()=>N,MS_PER_HOUR:()=>M,MS_PER_MINUTE:()=>P,MS_PER_SECOND:()=>x,MS_PER_WEEK:()=>O,SECONDS_PER_DAY:()=>C,SECONDS_PER_HOUR:()=>D,SECONDS_PER_MINUTE:()=>U,SECONDS_PER_WEEK:()=>H});module.exports=s(Y);var x=1e3,P=6e4,M=36e5,N=864e5,O=6048e5,U=60,D=3600,C=86400,H=604800,I=60,T=1440,A=10080,K=24,W=168;0&&(module.exports={HOURS_PER_DAY,HOURS_PER_WEEK,MINUTES_PER_DAY,MINUTES_PER_HOUR,MINUTES_PER_WEEK,MS_PER_DAY,MS_PER_HOUR,MS_PER_MINUTE,MS_PER_SECOND,MS_PER_WEEK,SECONDS_PER_DAY,SECONDS_PER_HOUR,SECONDS_PER_MINUTE,SECONDS_PER_WEEK});
2
+ //# sourceMappingURL=timeConstants.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/timeConstants.ts"],"sourcesContent":["/**\n * Note that month and year do not have fixed durations, and hence are excluded\n * from this file.\n */\n\nexport const MS_PER_SECOND = 1000;\nexport const MS_PER_MINUTE = 60_000;\nexport const MS_PER_HOUR = 3_600_000;\nexport const MS_PER_DAY = 86_400_000;\nexport const MS_PER_WEEK = 604_800_000;\n\nexport const SECONDS_PER_MINUTE = 60;\nexport const SECONDS_PER_HOUR = 3_600;\nexport const SECONDS_PER_DAY = 86_400;\nexport const SECONDS_PER_WEEK = 604_800;\n\nexport const MINUTES_PER_HOUR = 60;\nexport const MINUTES_PER_DAY = 1440;\nexport const MINUTES_PER_WEEK = 10_080;\n\nexport const HOURS_PER_DAY = 24;\nexport const HOURS_PER_WEEK = 168;\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,mBAAAC,EAAA,oBAAAC,EAAA,qBAAAC,EAAA,qBAAAC,EAAA,eAAAC,EAAA,gBAAAC,EAAA,kBAAAC,EAAA,kBAAAC,EAAA,gBAAAC,EAAA,oBAAAC,EAAA,qBAAAC,EAAA,uBAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAhB,GAKO,IAAMU,EAAgB,IAChBD,EAAgB,IAChBD,EAAc,KACdD,EAAa,MACbI,EAAc,OAEdG,EAAqB,GACrBD,EAAmB,KACnBD,EAAkB,MAClBG,EAAmB,OAEnBV,EAAmB,GACnBD,EAAkB,KAClBE,EAAmB,MAEnBJ,EAAgB,GAChBC,EAAiB","names":["timeConstants_exports","__export","HOURS_PER_DAY","HOURS_PER_WEEK","MINUTES_PER_DAY","MINUTES_PER_HOUR","MINUTES_PER_WEEK","MS_PER_DAY","MS_PER_HOUR","MS_PER_MINUTE","MS_PER_SECOND","MS_PER_WEEK","SECONDS_PER_DAY","SECONDS_PER_HOUR","SECONDS_PER_MINUTE","SECONDS_PER_WEEK","__toCommonJS"]}
@@ -0,0 +1,2 @@
1
+ var _=1e3,E=6e4,o=36e5,t=864e5,R=6048e5,S=60,c=3600,e=86400,n=604800,p=60,r=1440,s=10080,x=24,P=168;export{x as HOURS_PER_DAY,P as HOURS_PER_WEEK,r as MINUTES_PER_DAY,p as MINUTES_PER_HOUR,s as MINUTES_PER_WEEK,t as MS_PER_DAY,o as MS_PER_HOUR,E as MS_PER_MINUTE,_ as MS_PER_SECOND,R as MS_PER_WEEK,e as SECONDS_PER_DAY,c as SECONDS_PER_HOUR,S as SECONDS_PER_MINUTE,n as SECONDS_PER_WEEK};
2
+ //# sourceMappingURL=timeConstants.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/timeConstants.ts"],"sourcesContent":["/**\n * Note that month and year do not have fixed durations, and hence are excluded\n * from this file.\n */\n\nexport const MS_PER_SECOND = 1000;\nexport const MS_PER_MINUTE = 60_000;\nexport const MS_PER_HOUR = 3_600_000;\nexport const MS_PER_DAY = 86_400_000;\nexport const MS_PER_WEEK = 604_800_000;\n\nexport const SECONDS_PER_MINUTE = 60;\nexport const SECONDS_PER_HOUR = 3_600;\nexport const SECONDS_PER_DAY = 86_400;\nexport const SECONDS_PER_WEEK = 604_800;\n\nexport const MINUTES_PER_HOUR = 60;\nexport const MINUTES_PER_DAY = 1440;\nexport const MINUTES_PER_WEEK = 10_080;\n\nexport const HOURS_PER_DAY = 24;\nexport const HOURS_PER_WEEK = 168;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,gBAAgB;AACtB,IAAM,gBAAgB;AACtB,IAAM,cAAc;AACpB,IAAM,aAAa;AACnB,IAAM,cAAc;AAEpB,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AAEzB,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AAEzB,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;","names":[]}
1
+ {"version":3,"sources":["../src/timeConstants.ts"],"sourcesContent":["/**\n * Note that month and year do not have fixed durations, and hence are excluded\n * from this file.\n */\n\nexport const MS_PER_SECOND = 1000;\nexport const MS_PER_MINUTE = 60_000;\nexport const MS_PER_HOUR = 3_600_000;\nexport const MS_PER_DAY = 86_400_000;\nexport const MS_PER_WEEK = 604_800_000;\n\nexport const SECONDS_PER_MINUTE = 60;\nexport const SECONDS_PER_HOUR = 3_600;\nexport const SECONDS_PER_DAY = 86_400;\nexport const SECONDS_PER_WEEK = 604_800;\n\nexport const MINUTES_PER_HOUR = 60;\nexport const MINUTES_PER_DAY = 1440;\nexport const MINUTES_PER_WEEK = 10_080;\n\nexport const HOURS_PER_DAY = 24;\nexport const HOURS_PER_WEEK = 168;\n"],"mappings":"AAKO,IAAMA,EAAgB,IAChBC,EAAgB,IAChBC,EAAc,KACdC,EAAa,MACbC,EAAc,OAEdC,EAAqB,GACrBC,EAAmB,KACnBC,EAAkB,MAClBC,EAAmB,OAEnBC,EAAmB,GACnBC,EAAkB,KAClBC,EAAmB,MAEnBC,EAAgB,GAChBC,EAAiB","names":["MS_PER_SECOND","MS_PER_MINUTE","MS_PER_HOUR","MS_PER_DAY","MS_PER_WEEK","SECONDS_PER_MINUTE","SECONDS_PER_HOUR","SECONDS_PER_DAY","SECONDS_PER_WEEK","MINUTES_PER_HOUR","MINUTES_PER_DAY","MINUTES_PER_WEEK","HOURS_PER_DAY","HOURS_PER_WEEK"]}
@@ -0,0 +1,31 @@
1
+ // src/timeConstants.ts
2
+ var MS_PER_SECOND = 1e3;
3
+ var MS_PER_MINUTE = 6e4;
4
+ var MS_PER_HOUR = 36e5;
5
+ var MS_PER_DAY = 864e5;
6
+ var MS_PER_WEEK = 6048e5;
7
+ var SECONDS_PER_MINUTE = 60;
8
+ var SECONDS_PER_HOUR = 3600;
9
+ var SECONDS_PER_DAY = 86400;
10
+ var SECONDS_PER_WEEK = 604800;
11
+ var MINUTES_PER_HOUR = 60;
12
+ var MINUTES_PER_DAY = 1440;
13
+ var MINUTES_PER_WEEK = 10080;
14
+ var HOURS_PER_DAY = 24;
15
+ var HOURS_PER_WEEK = 168;
16
+ export {
17
+ HOURS_PER_DAY,
18
+ HOURS_PER_WEEK,
19
+ MINUTES_PER_DAY,
20
+ MINUTES_PER_HOUR,
21
+ MINUTES_PER_WEEK,
22
+ MS_PER_DAY,
23
+ MS_PER_HOUR,
24
+ MS_PER_MINUTE,
25
+ MS_PER_SECOND,
26
+ MS_PER_WEEK,
27
+ SECONDS_PER_DAY,
28
+ SECONDS_PER_HOUR,
29
+ SECONDS_PER_MINUTE,
30
+ SECONDS_PER_WEEK
31
+ };
@@ -88,7 +88,7 @@ function getDurationTypeSeparator(style) {
88
88
  }
89
89
  function msToDuration(ms, durationTypeForZero) {
90
90
  if (ms === 0) {
91
- durationTypeForZero = durationTypeForZero != null ? durationTypeForZero : "milliseconds";
91
+ durationTypeForZero = durationTypeForZero ?? "milliseconds";
92
92
  return { [durationTypeForZero]: 0 };
93
93
  }
94
94
  const duration = {};
@@ -129,7 +129,7 @@ function msToDuration(ms, durationTypeForZero) {
129
129
  return duration;
130
130
  }
131
131
  function formatDuration(duration, style) {
132
- style = style != null ? style : "short";
132
+ style = style ?? "short";
133
133
  const stylePlural = getDurationStyleForPlural(style);
134
134
  const space = getValueAndUnitSeparator(style);
135
135
  const a = [];
@@ -144,8 +144,8 @@ function formatDuration(duration, style) {
144
144
  return a.join(separator);
145
145
  }
146
146
  function readableDuration(ms, options) {
147
- const duration = msToDuration(ms, options == null ? void 0 : options.durationTypeForZero);
148
- return formatDuration(duration, options == null ? void 0 : options.style);
147
+ const duration = msToDuration(ms, options?.durationTypeForZero);
148
+ return formatDuration(duration, options?.style);
149
149
  }
150
150
  function elapsed(ms) {
151
151
  if (ms > MS_PER_MINUTE) {
@@ -159,8 +159,9 @@ function elapsed(ms) {
159
159
 
160
160
  // src/timer.ts
161
161
  var Timer = class {
162
+ startMs;
163
+ endMs = 0;
162
164
  constructor() {
163
- this.endMs = 0;
164
165
  this.startMs = Date.now();
165
166
  }
166
167
  stop() {
@@ -186,4 +187,3 @@ function timer() {
186
187
  Timer,
187
188
  timer
188
189
  });
189
- //# sourceMappingURL=timer.js.map
package/timer.d.mts ADDED
@@ -0,0 +1,13 @@
1
+ declare class Timer {
2
+ startMs: number;
3
+ endMs: number;
4
+ constructor();
5
+ stop(): void;
6
+ restart(): void;
7
+ elapsedMs(): number;
8
+ toString(): string;
9
+ }
10
+ /** Shorthand for `new Timer()` to make this easier to use. */
11
+ declare function timer(): Timer;
12
+
13
+ export { Timer, timer };
package/timer.min.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var p=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var h=(t,o)=>{for(var r in o)p(t,r,{get:o[r],enumerable:!0})},x=(t,o,r,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of d(o))!m.call(t,n)&&n!==r&&p(t,n,{get:()=>o[n],enumerable:!(i=S(o,n))||i.enumerable});return t};var R=t=>x(p({},"__esModule",{value:!0}),t);var A={};h(A,{Timer:()=>c,timer:()=>I});module.exports=R(A);var y=["days","hours","minutes","seconds","milliseconds"],b={days:{short:"day",shorts:"days",long:"day",longs:"days",narrow:"d"},hours:{short:"hr",shorts:"hrs",long:"hour",longs:"hours",narrow:"h"},minutes:{short:"min",shorts:"mins",long:"minute",longs:"minutes",narrow:"m"},seconds:{short:"sec",shorts:"secs",long:"second",longs:"seconds",narrow:"s"},milliseconds:{short:"ms",shorts:"ms",long:"millisecond",longs:"milliseconds",narrow:"ms"}};function P(t){return t=="short"?"shorts":t==="long"?"longs":t}function T(t){return t==="narrow"?"":" "}function U(t){return t==="narrow"?" ":", "}function N(t,o){if(t===0)return o=o??"milliseconds",{[o]:0};let r={};for(let i=0;i<1;i++){let n=Math.floor(t/1e3),a=t-n*1e3;if(a>0&&(r.milliseconds=a),n===0)break;let e=Math.floor(n/60);if(n-=e*60,n>0&&(r.seconds=n),e===0)break;let s=Math.floor(e/60);if(e-=s*60,e>0&&(r.minutes=e),s===0)break;let u=Math.floor(s/24);s-=u*24,s>0&&(r.hours=s),u>0&&(r.days=u)}return r}function O(t,o){o=o??"short";let r=P(o),i=T(o),n=[];for(let e of y){let s=t[e];if(s===void 0)continue;let u=b[e],M=s===1?u[o]:u[r];n.push(s+i+M)}let a=U(o);return n.join(a)}function w(t,o){let r=N(t,o?.durationTypeForZero);return O(r,o?.style)}function D(t){return t>6e4?w(t):t>100?`${(t/1e3).toFixed(3)}s`:t+"ms"}var c=class{startMs;endMs=0;constructor(){this.startMs=Date.now()}stop(){this.endMs=Date.now()}restart(){this.endMs=0,this.startMs=Date.now()}elapsedMs(){return(this.endMs||Date.now())-this.startMs}toString(){return D(this.elapsedMs())}};function I(){return new c}0&&(module.exports={Timer,timer});
2
+ //# sourceMappingURL=timer.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/timer.ts","../src/duration.ts"],"sourcesContent":["import { elapsed } from \"./duration\";\n\nexport class Timer {\n public startMs: number;\n public endMs = 0;\n\n public constructor() {\n this.startMs = Date.now();\n }\n\n public stop(): void {\n this.endMs = Date.now();\n }\n\n public restart(): void {\n this.endMs = 0;\n this.startMs = Date.now();\n }\n\n public elapsedMs(): number {\n const stopMs = this.endMs || Date.now();\n return stopMs - this.startMs;\n }\n\n public toString(): string {\n return elapsed(this.elapsedMs());\n }\n}\n\n/** Shorthand for `new Timer()` to make this easier to use. */\nexport function timer(): Timer {\n return new Timer();\n}\n","/**\n * Bunch of miscellaneous constants and utility functions related to handling\n * date and time durations.\n *\n * Note that month and year do not have fixed durations, and hence are excluded\n * from this file. Weeks have fixed durations, but are excluded because we\n * use days as the max duration supported.\n */\n\nimport {\n HOURS_PER_DAY,\n MINUTES_PER_HOUR,\n MS_PER_DAY,\n MS_PER_HOUR,\n MS_PER_MINUTE,\n MS_PER_SECOND,\n SECONDS_PER_MINUTE,\n} from \"./timeConstants\";\n\nexport type Duration = {\n days?: number;\n hours?: number;\n minutes?: number;\n seconds?: number;\n milliseconds?: number;\n};\n\n/**\n * One of: days, hours, minutes, seconds, milliseconds\n */\nexport type DurationType = keyof Duration;\n\n/**\n * Order in which the duration type appears in the duration string.\n */\nexport const DURATION_TYPE_SEQUENCE: DurationType[] = [\n \"days\",\n \"hours\",\n \"minutes\",\n \"seconds\",\n \"milliseconds\",\n];\n\n/**\n * Follows the same format as Intl.DurationFormat.prototype.format().\n *\n * Short: 1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns\n * Long: 1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds,\n * 7 milliseconds, 8 microseconds, 9 nanoseconds\n * Narrow: 1y 2mo 3w 3d 4h 5m 6s 7ms 8μs 9ns\n */\nexport type DurationStyle = \"short\" | \"long\" | \"narrow\";\n\nexport type DurationSuffixMap = {\n short: string;\n shorts: string;\n long: string;\n longs: string;\n narrow: string;\n};\n\nexport type DurationSuffixType = keyof DurationSuffixMap;\n\nexport const DURATION_STYLE_SUFFIX_MAP: Record<\n DurationType,\n DurationSuffixMap\n> = {\n days: {\n short: \"day\",\n shorts: \"days\",\n long: \"day\",\n longs: \"days\",\n narrow: \"d\",\n },\n hours: {\n short: \"hr\",\n shorts: \"hrs\",\n long: \"hour\",\n longs: \"hours\",\n narrow: \"h\",\n },\n minutes: {\n short: \"min\",\n shorts: \"mins\",\n long: \"minute\",\n longs: \"minutes\",\n narrow: \"m\",\n },\n seconds: {\n short: \"sec\",\n shorts: \"secs\",\n long: \"second\",\n longs: \"seconds\",\n narrow: \"s\",\n },\n milliseconds: {\n short: \"ms\",\n shorts: \"ms\",\n long: \"millisecond\",\n longs: \"milliseconds\",\n narrow: \"ms\",\n },\n};\n\nfunction getDurationStyleForPlural(style: DurationStyle): DurationSuffixType {\n return style == \"short\" ? \"shorts\" : style === \"long\" ? \"longs\" : style;\n}\n\nfunction getValueAndUnitSeparator(style: DurationStyle): string {\n return style === \"narrow\" ? \"\" : \" \";\n}\n\nfunction getDurationTypeSeparator(style: DurationStyle): string {\n return style === \"narrow\" ? \" \" : \", \";\n}\n\n/**\n * Convert a milliseconds duration into a Duration object. If the given ms is\n * zero, then return an object with a single field of zero with duration type\n * of durationTypeForZero.\n *\n * @param durationTypeForZero Defaults to 'milliseconds'\n */\nexport function msToDuration(\n ms: number,\n durationTypeForZero?: DurationType,\n): Duration {\n if (ms === 0) {\n durationTypeForZero = durationTypeForZero ?? \"milliseconds\";\n return { [durationTypeForZero]: 0 };\n }\n\n const duration: Duration = {};\n\n for (let i = 0; i < 1; i++) {\n let seconds = Math.floor(ms / MS_PER_SECOND);\n const millis = ms - seconds * MS_PER_SECOND;\n\n if (millis > 0) {\n duration[\"milliseconds\"] = millis;\n }\n\n if (seconds === 0) {\n break;\n }\n\n let minutes = Math.floor(seconds / SECONDS_PER_MINUTE);\n seconds -= minutes * SECONDS_PER_MINUTE;\n\n if (seconds > 0) {\n duration[\"seconds\"] = seconds;\n }\n\n if (minutes === 0) {\n break;\n }\n\n let hours = Math.floor(minutes / MINUTES_PER_HOUR);\n minutes -= hours * MINUTES_PER_HOUR;\n\n if (minutes > 0) {\n duration[\"minutes\"] = minutes;\n }\n\n if (hours === 0) {\n break;\n }\n\n const days = Math.floor(hours / HOURS_PER_DAY);\n hours -= days * HOURS_PER_DAY;\n\n if (hours > 0) {\n duration[\"hours\"] = hours;\n }\n\n if (days > 0) {\n duration[\"days\"] = days;\n }\n }\n\n return duration;\n}\n\n/**\n * Returns the number of milliseconds for the given duration.\n */\nexport function durationToMs(duration: Duration): number {\n const daysMs = (duration.days ?? 0) * MS_PER_DAY;\n const hoursMs = (duration.hours ?? 0) * MS_PER_HOUR;\n const minsMs = (duration.minutes ?? 0) * MS_PER_MINUTE;\n const secsMs = (duration.seconds ?? 0) * MS_PER_SECOND;\n const msMs = duration.milliseconds ?? 0;\n\n return daysMs + hoursMs + minsMs + secsMs + msMs;\n}\n\n/**\n * Convenience function to return a duration given an ms or Duration.\n */\nexport function durationOrMsToMs(duration: number | Duration): number {\n return typeof duration === \"number\" ? duration : durationToMs(duration);\n}\n\n/**\n * Format a given Duration object into a string. If the object has no fields,\n * then returns an empty string.\n *\n * @param style Defaults to 'short'\n */\nexport function formatDuration(duration: Duration, style?: DurationStyle) {\n style = style ?? \"short\";\n const stylePlural = getDurationStyleForPlural(style);\n\n const space = getValueAndUnitSeparator(style);\n\n const a: string[] = [];\n\n for (const unit of DURATION_TYPE_SEQUENCE) {\n const value = duration[unit];\n if (value === undefined) continue;\n\n const suffixMap = DURATION_STYLE_SUFFIX_MAP[unit];\n const suffix = value === 1 ? suffixMap[style] : suffixMap[stylePlural];\n a.push(value + space + suffix);\n }\n\n const separator = getDurationTypeSeparator(style);\n return a.join(separator);\n}\n\n/**\n * Convert a millisecond duration into a human-readable duration string.\n *\n * @param options.durationTypeForZero - Defaults to 'milliseconds'\n * @param options.style - Defaults to 'short'\n */\nexport function readableDuration(\n ms: number,\n options?: { durationTypeForZero?: DurationType; style?: DurationStyle },\n): string {\n const duration = msToDuration(ms, options?.durationTypeForZero);\n\n return formatDuration(duration, options?.style);\n}\n\n/** A shortened duration string useful for logging timings. */\nexport function elapsed(ms: number): string {\n // Use long format for 1 minute or over.\n if (ms > MS_PER_MINUTE) {\n return readableDuration(ms);\n }\n\n // Use seconds format for over 100ms.\n if (ms > 100) {\n return `${(ms / 1000).toFixed(3)}s`;\n }\n\n // Use milliseconds format.\n return ms + \"ms\";\n}\n"],"mappings":"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","names":["timer_exports","__export","Timer","timer","__toCommonJS","DURATION_TYPE_SEQUENCE","DURATION_STYLE_SUFFIX_MAP","getDurationStyleForPlural","style","getValueAndUnitSeparator","getDurationTypeSeparator","msToDuration","ms","durationTypeForZero","duration","seconds","millis","minutes","hours","days","formatDuration","duration","style","stylePlural","getDurationStyleForPlural","space","getValueAndUnitSeparator","a","unit","DURATION_TYPE_SEQUENCE","value","suffixMap","DURATION_STYLE_SUFFIX_MAP","suffix","separator","getDurationTypeSeparator","readableDuration","ms","options","msToDuration","elapsed","Timer","elapsed","timer"]}
package/timer.min.mjs ADDED
@@ -0,0 +1,2 @@
1
+ var S=["days","hours","minutes","seconds","milliseconds"],d={days:{short:"day",shorts:"days",long:"day",longs:"days",narrow:"d"},hours:{short:"hr",shorts:"hrs",long:"hour",longs:"hours",narrow:"h"},minutes:{short:"min",shorts:"mins",long:"minute",longs:"minutes",narrow:"m"},seconds:{short:"sec",shorts:"secs",long:"second",longs:"seconds",narrow:"s"},milliseconds:{short:"ms",shorts:"ms",long:"millisecond",longs:"milliseconds",narrow:"ms"}};function m(t){return t=="short"?"shorts":t==="long"?"longs":t}function h(t){return t==="narrow"?"":" "}function x(t){return t==="narrow"?" ":", "}function R(t,o){if(t===0)return o=o??"milliseconds",{[o]:0};let r={};for(let u=0;u<1;u++){let s=Math.floor(t/1e3),a=t-s*1e3;if(a>0&&(r.milliseconds=a),s===0)break;let e=Math.floor(s/60);if(s-=e*60,s>0&&(r.seconds=s),e===0)break;let n=Math.floor(e/60);if(e-=n*60,e>0&&(r.minutes=e),n===0)break;let i=Math.floor(n/24);n-=i*24,n>0&&(r.hours=n),i>0&&(r.days=i)}return r}function g(t,o){o=o??"short";let r=m(o),u=h(o),s=[];for(let e of S){let n=t[e];if(n===void 0)continue;let i=d[e],D=n===1?i[o]:i[r];s.push(n+u+D)}let a=x(o);return s.join(a)}function y(t,o){let r=R(t,o?.durationTypeForZero);return g(r,o?.style)}function E(t){return t>6e4?y(t):t>100?`${(t/1e3).toFixed(3)}s`:t+"ms"}var c=class{startMs;endMs=0;constructor(){this.startMs=Date.now()}stop(){this.endMs=Date.now()}restart(){this.endMs=0,this.startMs=Date.now()}elapsedMs(){return(this.endMs||Date.now())-this.startMs}toString(){return E(this.elapsedMs())}};function w(){return new c}export{c as Timer,w as timer};
2
+ //# sourceMappingURL=timer.min.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/duration.ts","../src/timer.ts"],"sourcesContent":["/**\n * Bunch of miscellaneous constants and utility functions related to handling\n * date and time durations.\n *\n * Note that month and year do not have fixed durations, and hence are excluded\n * from this file. Weeks have fixed durations, but are excluded because we\n * use days as the max duration supported.\n */\n\nimport {\n HOURS_PER_DAY,\n MINUTES_PER_HOUR,\n MS_PER_DAY,\n MS_PER_HOUR,\n MS_PER_MINUTE,\n MS_PER_SECOND,\n SECONDS_PER_MINUTE,\n} from \"./timeConstants\";\n\nexport type Duration = {\n days?: number;\n hours?: number;\n minutes?: number;\n seconds?: number;\n milliseconds?: number;\n};\n\n/**\n * One of: days, hours, minutes, seconds, milliseconds\n */\nexport type DurationType = keyof Duration;\n\n/**\n * Order in which the duration type appears in the duration string.\n */\nexport const DURATION_TYPE_SEQUENCE: DurationType[] = [\n \"days\",\n \"hours\",\n \"minutes\",\n \"seconds\",\n \"milliseconds\",\n];\n\n/**\n * Follows the same format as Intl.DurationFormat.prototype.format().\n *\n * Short: 1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns\n * Long: 1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds,\n * 7 milliseconds, 8 microseconds, 9 nanoseconds\n * Narrow: 1y 2mo 3w 3d 4h 5m 6s 7ms 8μs 9ns\n */\nexport type DurationStyle = \"short\" | \"long\" | \"narrow\";\n\nexport type DurationSuffixMap = {\n short: string;\n shorts: string;\n long: string;\n longs: string;\n narrow: string;\n};\n\nexport type DurationSuffixType = keyof DurationSuffixMap;\n\nexport const DURATION_STYLE_SUFFIX_MAP: Record<\n DurationType,\n DurationSuffixMap\n> = {\n days: {\n short: \"day\",\n shorts: \"days\",\n long: \"day\",\n longs: \"days\",\n narrow: \"d\",\n },\n hours: {\n short: \"hr\",\n shorts: \"hrs\",\n long: \"hour\",\n longs: \"hours\",\n narrow: \"h\",\n },\n minutes: {\n short: \"min\",\n shorts: \"mins\",\n long: \"minute\",\n longs: \"minutes\",\n narrow: \"m\",\n },\n seconds: {\n short: \"sec\",\n shorts: \"secs\",\n long: \"second\",\n longs: \"seconds\",\n narrow: \"s\",\n },\n milliseconds: {\n short: \"ms\",\n shorts: \"ms\",\n long: \"millisecond\",\n longs: \"milliseconds\",\n narrow: \"ms\",\n },\n};\n\nfunction getDurationStyleForPlural(style: DurationStyle): DurationSuffixType {\n return style == \"short\" ? \"shorts\" : style === \"long\" ? \"longs\" : style;\n}\n\nfunction getValueAndUnitSeparator(style: DurationStyle): string {\n return style === \"narrow\" ? \"\" : \" \";\n}\n\nfunction getDurationTypeSeparator(style: DurationStyle): string {\n return style === \"narrow\" ? \" \" : \", \";\n}\n\n/**\n * Convert a milliseconds duration into a Duration object. If the given ms is\n * zero, then return an object with a single field of zero with duration type\n * of durationTypeForZero.\n *\n * @param durationTypeForZero Defaults to 'milliseconds'\n */\nexport function msToDuration(\n ms: number,\n durationTypeForZero?: DurationType,\n): Duration {\n if (ms === 0) {\n durationTypeForZero = durationTypeForZero ?? \"milliseconds\";\n return { [durationTypeForZero]: 0 };\n }\n\n const duration: Duration = {};\n\n for (let i = 0; i < 1; i++) {\n let seconds = Math.floor(ms / MS_PER_SECOND);\n const millis = ms - seconds * MS_PER_SECOND;\n\n if (millis > 0) {\n duration[\"milliseconds\"] = millis;\n }\n\n if (seconds === 0) {\n break;\n }\n\n let minutes = Math.floor(seconds / SECONDS_PER_MINUTE);\n seconds -= minutes * SECONDS_PER_MINUTE;\n\n if (seconds > 0) {\n duration[\"seconds\"] = seconds;\n }\n\n if (minutes === 0) {\n break;\n }\n\n let hours = Math.floor(minutes / MINUTES_PER_HOUR);\n minutes -= hours * MINUTES_PER_HOUR;\n\n if (minutes > 0) {\n duration[\"minutes\"] = minutes;\n }\n\n if (hours === 0) {\n break;\n }\n\n const days = Math.floor(hours / HOURS_PER_DAY);\n hours -= days * HOURS_PER_DAY;\n\n if (hours > 0) {\n duration[\"hours\"] = hours;\n }\n\n if (days > 0) {\n duration[\"days\"] = days;\n }\n }\n\n return duration;\n}\n\n/**\n * Returns the number of milliseconds for the given duration.\n */\nexport function durationToMs(duration: Duration): number {\n const daysMs = (duration.days ?? 0) * MS_PER_DAY;\n const hoursMs = (duration.hours ?? 0) * MS_PER_HOUR;\n const minsMs = (duration.minutes ?? 0) * MS_PER_MINUTE;\n const secsMs = (duration.seconds ?? 0) * MS_PER_SECOND;\n const msMs = duration.milliseconds ?? 0;\n\n return daysMs + hoursMs + minsMs + secsMs + msMs;\n}\n\n/**\n * Convenience function to return a duration given an ms or Duration.\n */\nexport function durationOrMsToMs(duration: number | Duration): number {\n return typeof duration === \"number\" ? duration : durationToMs(duration);\n}\n\n/**\n * Format a given Duration object into a string. If the object has no fields,\n * then returns an empty string.\n *\n * @param style Defaults to 'short'\n */\nexport function formatDuration(duration: Duration, style?: DurationStyle) {\n style = style ?? \"short\";\n const stylePlural = getDurationStyleForPlural(style);\n\n const space = getValueAndUnitSeparator(style);\n\n const a: string[] = [];\n\n for (const unit of DURATION_TYPE_SEQUENCE) {\n const value = duration[unit];\n if (value === undefined) continue;\n\n const suffixMap = DURATION_STYLE_SUFFIX_MAP[unit];\n const suffix = value === 1 ? suffixMap[style] : suffixMap[stylePlural];\n a.push(value + space + suffix);\n }\n\n const separator = getDurationTypeSeparator(style);\n return a.join(separator);\n}\n\n/**\n * Convert a millisecond duration into a human-readable duration string.\n *\n * @param options.durationTypeForZero - Defaults to 'milliseconds'\n * @param options.style - Defaults to 'short'\n */\nexport function readableDuration(\n ms: number,\n options?: { durationTypeForZero?: DurationType; style?: DurationStyle },\n): string {\n const duration = msToDuration(ms, options?.durationTypeForZero);\n\n return formatDuration(duration, options?.style);\n}\n\n/** A shortened duration string useful for logging timings. */\nexport function elapsed(ms: number): string {\n // Use long format for 1 minute or over.\n if (ms > MS_PER_MINUTE) {\n return readableDuration(ms);\n }\n\n // Use seconds format for over 100ms.\n if (ms > 100) {\n return `${(ms / 1000).toFixed(3)}s`;\n }\n\n // Use milliseconds format.\n return ms + \"ms\";\n}\n","import { elapsed } from \"./duration\";\n\nexport class Timer {\n public startMs: number;\n public endMs = 0;\n\n public constructor() {\n this.startMs = Date.now();\n }\n\n public stop(): void {\n this.endMs = Date.now();\n }\n\n public restart(): void {\n this.endMs = 0;\n this.startMs = Date.now();\n }\n\n public elapsedMs(): number {\n const stopMs = this.endMs || Date.now();\n return stopMs - this.startMs;\n }\n\n public toString(): string {\n return elapsed(this.elapsedMs());\n }\n}\n\n/** Shorthand for `new Timer()` to make this easier to use. */\nexport function timer(): Timer {\n return new Timer();\n}\n"],"mappings":"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","names":["DURATION_TYPE_SEQUENCE","DURATION_STYLE_SUFFIX_MAP","getDurationStyleForPlural","style","getValueAndUnitSeparator","getDurationTypeSeparator","msToDuration","ms","durationTypeForZero","duration","i","seconds","millis","minutes","hours","days","formatDuration","duration","style","stylePlural","getDurationStyleForPlural","space","getValueAndUnitSeparator","a","unit","DURATION_TYPE_SEQUENCE","value","suffixMap","DURATION_STYLE_SUFFIX_MAP","suffix","separator","getDurationTypeSeparator","readableDuration","ms","options","msToDuration","elapsed","Timer","elapsed","timer"]}