@choksheak/ts-utils 0.2.9 → 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 (276) 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} +0 -1
  10. package/assert.d.mts +7 -0
  11. package/assert.min.cjs +2 -0
  12. package/assert.min.cjs.map +1 -0
  13. package/assert.min.mjs +2 -0
  14. package/{assert.js.map → assert.min.mjs.map} +1 -1
  15. package/assert.mjs +11 -0
  16. package/{average.js → average.cjs} +0 -1
  17. package/average.d.mts +7 -0
  18. package/average.min.cjs +2 -0
  19. package/{average.js.map → average.min.cjs.map} +1 -1
  20. package/average.min.mjs +2 -0
  21. package/average.min.mjs.map +1 -0
  22. package/average.mjs +20 -0
  23. package/{base64Url.js → base64Url.cjs} +0 -1
  24. package/base64Url.d.mts +10 -0
  25. package/base64Url.min.cjs +2 -0
  26. package/base64Url.min.cjs.map +1 -0
  27. package/base64Url.min.mjs +2 -0
  28. package/{base64Url.js.map → base64Url.min.mjs.map} +1 -1
  29. package/base64Url.mjs +14 -0
  30. package/{dateTimeStr.js → dateTimeStr.cjs} +0 -1
  31. package/dateTimeStr.d.mts +85 -0
  32. package/dateTimeStr.min.cjs +2 -0
  33. package/dateTimeStr.min.cjs.map +1 -0
  34. package/dateTimeStr.min.mjs +2 -0
  35. package/{dateTimeStr.js.map → dateTimeStr.min.mjs.map} +1 -1
  36. package/dateTimeStr.mjs +83 -0
  37. package/{duration.js → duration.cjs} +9 -11
  38. package/duration.d.mts +78 -0
  39. package/duration.min.cjs +2 -0
  40. package/duration.min.cjs.map +1 -0
  41. package/duration.min.mjs +2 -0
  42. package/duration.min.mjs.map +1 -0
  43. package/duration.mjs +154 -0
  44. package/{isEmpty.js → isEmpty.cjs} +0 -1
  45. package/isEmpty.d.mts +6 -0
  46. package/isEmpty.min.cjs +2 -0
  47. package/isEmpty.min.cjs.map +1 -0
  48. package/isEmpty.min.mjs +2 -0
  49. package/{isEmpty.js.map → isEmpty.min.mjs.map} +1 -1
  50. package/isEmpty.mjs +22 -0
  51. package/kvStore.cjs +333 -0
  52. package/kvStore.d.mts +97 -0
  53. package/kvStore.min.cjs +2 -0
  54. package/kvStore.min.cjs.map +1 -0
  55. package/kvStore.min.mjs +2 -0
  56. package/kvStore.min.mjs.map +1 -0
  57. package/kvStore.mjs +300 -0
  58. package/{localStorageCache.js → localStorageCache.cjs} +5 -7
  59. package/localStorageCache.d.mts +57 -0
  60. package/localStorageCache.min.cjs +2 -0
  61. package/localStorageCache.min.cjs.map +1 -0
  62. package/localStorageCache.min.mjs +2 -0
  63. package/localStorageCache.min.mjs.map +1 -0
  64. package/localStorageCache.mjs +92 -0
  65. package/{logging.js → logging.cjs} +0 -1
  66. package/logging.d.mts +4 -0
  67. package/logging.min.cjs +2 -0
  68. package/logging.min.cjs.map +1 -0
  69. package/logging.min.mjs +2 -0
  70. package/{logging.js.map → logging.min.mjs.map} +1 -1
  71. package/logging.mjs +21 -0
  72. package/{nonEmpty.js → nonEmpty.cjs} +0 -1
  73. package/nonEmpty.d.mts +10 -0
  74. package/nonEmpty.min.cjs +2 -0
  75. package/{nonEmpty.js.map → nonEmpty.min.cjs.map} +1 -1
  76. package/nonEmpty.min.mjs +2 -0
  77. package/nonEmpty.min.mjs.map +1 -0
  78. package/nonEmpty.mjs +30 -0
  79. package/{nonNil.js → nonNil.cjs} +0 -1
  80. package/{src/nonNil.ts → nonNil.d.mts} +3 -6
  81. package/nonNil.min.cjs +2 -0
  82. package/nonNil.min.cjs.map +1 -0
  83. package/nonNil.min.mjs +2 -0
  84. package/{nonNil.js.map → nonNil.min.mjs.map} +1 -1
  85. package/nonNil.mjs +10 -0
  86. package/package.json +414 -24
  87. package/{round.js → round.cjs} +0 -1
  88. package/{src/round.ts → round.d.mts} +4 -8
  89. package/round.min.cjs +2 -0
  90. package/round.min.cjs.map +1 -0
  91. package/round.min.mjs +2 -0
  92. package/{round.js.map → round.min.mjs.map} +1 -1
  93. package/round.mjs +12 -0
  94. package/{safeBtoa.js → safeBtoa.cjs} +0 -1
  95. package/safeBtoa.d.mts +6 -0
  96. package/safeBtoa.min.cjs +2 -0
  97. package/safeBtoa.min.cjs.map +1 -0
  98. package/safeBtoa.min.mjs +2 -0
  99. package/{safeBtoa.js.map → safeBtoa.min.mjs.map} +1 -1
  100. package/safeBtoa.mjs +9 -0
  101. package/{safeParseFloat.js → safeParseFloat.cjs} +0 -1
  102. package/safeParseFloat.d.mts +6 -0
  103. package/safeParseFloat.min.cjs +2 -0
  104. package/safeParseFloat.min.cjs.map +1 -0
  105. package/safeParseFloat.min.mjs +2 -0
  106. package/{safeParseFloat.js.map → safeParseFloat.min.mjs.map} +1 -1
  107. package/safeParseFloat.mjs +8 -0
  108. package/{safeParseInt.js → safeParseInt.cjs} +0 -1
  109. package/safeParseInt.d.mts +6 -0
  110. package/safeParseInt.min.cjs +2 -0
  111. package/safeParseInt.min.cjs.map +1 -0
  112. package/safeParseInt.min.mjs +2 -0
  113. package/{safeParseInt.js.map → safeParseInt.min.mjs.map} +1 -1
  114. package/safeParseInt.mjs +8 -0
  115. package/sha256.cjs +35 -0
  116. package/sha256.d.mts +6 -0
  117. package/sha256.min.cjs +2 -0
  118. package/sha256.min.cjs.map +1 -0
  119. package/sha256.min.mjs +2 -0
  120. package/{sha256.js.map → sha256.min.mjs.map} +1 -1
  121. package/sha256.mjs +10 -0
  122. package/{sleep.js → sleep.cjs} +0 -1
  123. package/{src/sleep.ts → sleep.d.mts} +3 -3
  124. package/sleep.min.cjs +2 -0
  125. package/sleep.min.cjs.map +1 -0
  126. package/sleep.min.mjs +2 -0
  127. package/{sleep.js.map → sleep.min.mjs.map} +1 -1
  128. package/sleep.mjs +7 -0
  129. package/{sum.js → sum.cjs} +0 -1
  130. package/sum.d.mts +7 -0
  131. package/sum.min.cjs +2 -0
  132. package/sum.min.cjs.map +1 -0
  133. package/sum.min.mjs +2 -0
  134. package/{sum.js.map → sum.min.mjs.map} +1 -1
  135. package/sum.mjs +13 -0
  136. package/{timeConstants.js → timeConstants.cjs} +0 -1
  137. package/timeConstants.d.mts +20 -0
  138. package/timeConstants.min.cjs +2 -0
  139. package/timeConstants.min.cjs.map +1 -0
  140. package/timeConstants.min.mjs +2 -0
  141. package/{timeConstants.js.map → timeConstants.min.mjs.map} +1 -1
  142. package/timeConstants.mjs +31 -0
  143. package/{timer.js → timer.cjs} +6 -6
  144. package/timer.d.mts +13 -0
  145. package/timer.min.cjs +2 -0
  146. package/timer.min.cjs.map +1 -0
  147. package/timer.min.mjs +2 -0
  148. package/timer.min.mjs.map +1 -0
  149. package/timer.mjs +161 -0
  150. package/docs/.nojekyll +0 -1
  151. package/docs/assets/hierarchy.js +0 -1
  152. package/docs/assets/highlight.css +0 -22
  153. package/docs/assets/icons.js +0 -18
  154. package/docs/assets/icons.svg +0 -1
  155. package/docs/assets/main.js +0 -60
  156. package/docs/assets/navigation.js +0 -1
  157. package/docs/assets/search.js +0 -1
  158. package/docs/assets/style.css +0 -1640
  159. package/docs/classes/kvStore.KVStore.html +0 -26
  160. package/docs/classes/kvStore.KVStoreField.html +0 -7
  161. package/docs/classes/timer.Timer.html +0 -8
  162. package/docs/functions/arrayBuffer.arrayBufferToBase64.html +0 -2
  163. package/docs/functions/arrayBuffer.arrayBufferToHex.html +0 -2
  164. package/docs/functions/assert.assert.html +0 -3
  165. package/docs/functions/average.average.html +0 -3
  166. package/docs/functions/base64Url.base64ToBase64URL.html +0 -2
  167. package/docs/functions/base64Url.base64UrlToBase64.html +0 -2
  168. package/docs/functions/dateTimeStr.getDisplayDateTime.html +0 -3
  169. package/docs/functions/dateTimeStr.getLongMonthNameOneIndexed.html +0 -4
  170. package/docs/functions/dateTimeStr.getLongMonthNameZeroIndexed.html +0 -4
  171. package/docs/functions/dateTimeStr.getShortMonthNameOneIndexed.html +0 -4
  172. package/docs/functions/dateTimeStr.getShortMonthNameZeroIndexed.html +0 -4
  173. package/docs/functions/dateTimeStr.hhMm.html +0 -4
  174. package/docs/functions/dateTimeStr.hhMmSs.html +0 -4
  175. package/docs/functions/dateTimeStr.hhMmSsMs.html +0 -5
  176. package/docs/functions/dateTimeStr.toDate.html +0 -4
  177. package/docs/functions/dateTimeStr.tzShort.html +0 -4
  178. package/docs/functions/dateTimeStr.yyyyMm.html +0 -4
  179. package/docs/functions/dateTimeStr.yyyyMmDd.html +0 -4
  180. package/docs/functions/duration.durationOrMsToMs.html +0 -2
  181. package/docs/functions/duration.durationToMs.html +0 -2
  182. package/docs/functions/duration.elapsed.html +0 -2
  183. package/docs/functions/duration.formatDuration.html +0 -4
  184. package/docs/functions/duration.msToDuration.html +0 -5
  185. package/docs/functions/duration.readableDuration.html +0 -4
  186. package/docs/functions/isEmpty.isEmpty.html +0 -2
  187. package/docs/functions/kvStore.kvStoreItem.html +0 -2
  188. package/docs/functions/localStorageCache.storeItem.html +0 -15
  189. package/docs/functions/logging.capLength.html +0 -1
  190. package/docs/functions/logging.stringify.html +0 -1
  191. package/docs/functions/nonEmpty.nonEmpty.html +0 -5
  192. package/docs/functions/nonNil.nonNil.html +0 -5
  193. package/docs/functions/round.round.html +0 -5
  194. package/docs/functions/round.roundS.html +0 -3
  195. package/docs/functions/safeBtoa.safeBtoa.html +0 -2
  196. package/docs/functions/safeParseFloat.safeParseFloat.html +0 -2
  197. package/docs/functions/safeParseInt.safeParseInt.html +0 -2
  198. package/docs/functions/sha256.sha256.html +0 -2
  199. package/docs/functions/sleep.sleep.html +0 -3
  200. package/docs/functions/sum.sum.html +0 -3
  201. package/docs/functions/timer.timer.html +0 -2
  202. package/docs/hierarchy.html +0 -1
  203. package/docs/index.html +0 -4
  204. package/docs/modules/arrayBuffer.html +0 -1
  205. package/docs/modules/assert.html +0 -1
  206. package/docs/modules/average.html +0 -1
  207. package/docs/modules/base64Url.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 -14
  260. package/src/average.ts +0 -13
  261. package/src/base64Url.ts +0 -20
  262. package/src/dateTimeStr.ts +0 -184
  263. package/src/duration.ts +0 -260
  264. package/src/isEmpty.ts +0 -32
  265. package/src/kvStore.ts +0 -444
  266. package/src/localStorageCache.ts +0 -121
  267. package/src/logging.ts +0 -26
  268. package/src/nonEmpty.ts +0 -18
  269. package/src/safeBtoa.ts +0 -15
  270. package/src/safeParseFloat.ts +0 -10
  271. package/src/safeParseInt.ts +0 -10
  272. package/src/sha256.ts +0 -13
  273. package/src/sum.ts +0 -17
  274. package/src/timeConstants.ts +0 -22
  275. package/src/timer.ts +0 -33
  276. package/timer.js.map +0 -1
package/README.md CHANGED
@@ -4,4 +4,6 @@ This package is a random bunch of Typescript utilities that I have needed in alm
4
4
 
5
5
  The code supports full tree-shaking. Therefore your code will only grow in size by whatever you use. Any code that you are not using will not contribute to your code size.
6
6
 
7
+ Source code: https://github.com/choksheak/ts-utils
8
+
7
9
  Online docs: https://choksheak.github.io/ts-utils/
@@ -38,4 +38,3 @@ function arrayBufferToBase64(buffer) {
38
38
  arrayBufferToBase64,
39
39
  arrayBufferToHex
40
40
  });
41
- //# sourceMappingURL=arrayBuffer.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Encode an input ArrayBuffer into a hex string.
3
+ */
4
+ declare function arrayBufferToHex(buffer: ArrayBuffer): string;
5
+ /**
6
+ * Encode an input ArrayBuffer into a base64 string.
7
+ */
8
+ declare function arrayBufferToBase64(buffer: ArrayBuffer): string;
9
+
10
+ export { arrayBufferToBase64, arrayBufferToHex };
@@ -0,0 +1,2 @@
1
+ "use strict";var e=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var u=(t,r)=>{for(var n in r)e(t,n,{get:r[n],enumerable:!0})},A=(t,r,n,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of i(r))!y.call(t,a)&&a!==n&&e(t,a,{get:()=>r[a],enumerable:!(o=f(r,a))||o.enumerable});return t};var s=t=>A(e({},"__esModule",{value:!0}),t);var m={};u(m,{arrayBufferToBase64:()=>g,arrayBufferToHex:()=>c});module.exports=s(m);function c(t){let r=new Uint8Array(t);return Array.from(r).map(n=>n.toString(16).padStart(2,"0")).join("")}function g(t){let r=new Uint8Array(t),n=Array.from(r).map(o=>String.fromCodePoint(o)).join("");return btoa(n)}0&&(module.exports={arrayBufferToBase64,arrayBufferToHex});
2
+ //# sourceMappingURL=arrayBuffer.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/arrayBuffer.ts"],"sourcesContent":["/**\n * Encode an input ArrayBuffer into a hex string.\n */\nexport function arrayBufferToHex(buffer: ArrayBuffer): string {\n // Create a Uint8Array view of the ArrayBuffer\n const byteArray = new Uint8Array(buffer);\n\n // Convert each byte to a two-character hexadecimal string\n return Array.from(byteArray)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Encode an input ArrayBuffer into a base64 string.\n */\nexport function arrayBufferToBase64(buffer: ArrayBuffer): string {\n // Convert the ArrayBuffer to a Uint8Array\n const byteArray = new Uint8Array(buffer);\n\n // Create a binary string from the byte array\n const binaryString = Array.from(byteArray)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Encode the binary string to base64. No need to use safeBtoa because we\n // already simplified the binary input above.\n return btoa(binaryString);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,EAAA,qBAAAC,IAAA,eAAAC,EAAAJ,GAGO,SAASG,EAAiBE,EAA6B,CAE5D,IAAMC,EAAY,IAAI,WAAWD,CAAM,EAGvC,OAAO,MAAM,KAAKC,CAAS,EACxB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAKO,SAASL,EAAoBG,EAA6B,CAE/D,IAAMC,EAAY,IAAI,WAAWD,CAAM,EAGjCG,EAAe,MAAM,KAAKF,CAAS,EACtC,IAAKC,GAAS,OAAO,cAAcA,CAAI,CAAC,EACxC,KAAK,EAAE,EAIV,OAAO,KAAKC,CAAY,CAC1B","names":["arrayBuffer_exports","__export","arrayBufferToBase64","arrayBufferToHex","__toCommonJS","buffer","byteArray","byte","binaryString"]}
@@ -0,0 +1,2 @@
1
+ function o(r){let t=new Uint8Array(r);return Array.from(t).map(n=>n.toString(16).padStart(2,"0")).join("")}function e(r){let t=new Uint8Array(r),n=Array.from(t).map(a=>String.fromCodePoint(a)).join("");return btoa(n)}export{e as arrayBufferToBase64,o as arrayBufferToHex};
2
+ //# sourceMappingURL=arrayBuffer.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/arrayBuffer.ts"],"sourcesContent":["/**\n * Encode an input ArrayBuffer into a hex string.\n */\nexport function arrayBufferToHex(buffer: ArrayBuffer): string {\n // Create a Uint8Array view of the ArrayBuffer\n const byteArray = new Uint8Array(buffer);\n\n // Convert each byte to a two-character hexadecimal string\n return Array.from(byteArray)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Encode an input ArrayBuffer into a base64 string.\n */\nexport function arrayBufferToBase64(buffer: ArrayBuffer): string {\n // Convert the ArrayBuffer to a Uint8Array\n const byteArray = new Uint8Array(buffer);\n\n // Create a binary string from the byte array\n const binaryString = Array.from(byteArray)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Encode the binary string to base64. No need to use safeBtoa because we\n // already simplified the binary input above.\n return btoa(binaryString);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,iBAAiB,QAA6B;AAE5D,QAAM,YAAY,IAAI,WAAW,MAAM;AAGvC,SAAO,MAAM,KAAK,SAAS,EACxB,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAChD,KAAK,EAAE;AACZ;AAKO,SAAS,oBAAoB,QAA6B;AAE/D,QAAM,YAAY,IAAI,WAAW,MAAM;AAGvC,QAAM,eAAe,MAAM,KAAK,SAAS,EACtC,IAAI,CAAC,SAAS,OAAO,cAAc,IAAI,CAAC,EACxC,KAAK,EAAE;AAIV,SAAO,KAAK,YAAY;AAC1B;","names":[]}
1
+ {"version":3,"sources":["../src/arrayBuffer.ts"],"sourcesContent":["/**\n * Encode an input ArrayBuffer into a hex string.\n */\nexport function arrayBufferToHex(buffer: ArrayBuffer): string {\n // Create a Uint8Array view of the ArrayBuffer\n const byteArray = new Uint8Array(buffer);\n\n // Convert each byte to a two-character hexadecimal string\n return Array.from(byteArray)\n .map((byte) => byte.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Encode an input ArrayBuffer into a base64 string.\n */\nexport function arrayBufferToBase64(buffer: ArrayBuffer): string {\n // Convert the ArrayBuffer to a Uint8Array\n const byteArray = new Uint8Array(buffer);\n\n // Create a binary string from the byte array\n const binaryString = Array.from(byteArray)\n .map((byte) => String.fromCodePoint(byte))\n .join(\"\");\n\n // Encode the binary string to base64. No need to use safeBtoa because we\n // already simplified the binary input above.\n return btoa(binaryString);\n}\n"],"mappings":"AAGO,SAASA,EAAiBC,EAA6B,CAE5D,IAAMC,EAAY,IAAI,WAAWD,CAAM,EAGvC,OAAO,MAAM,KAAKC,CAAS,EACxB,IAAKC,GAASA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,EAChD,KAAK,EAAE,CACZ,CAKO,SAASC,EAAoBH,EAA6B,CAE/D,IAAMC,EAAY,IAAI,WAAWD,CAAM,EAGjCI,EAAe,MAAM,KAAKH,CAAS,EACtC,IAAKC,GAAS,OAAO,cAAcA,CAAI,CAAC,EACxC,KAAK,EAAE,EAIV,OAAO,KAAKE,CAAY,CAC1B","names":["arrayBufferToHex","buffer","byteArray","byte","arrayBufferToBase64","binaryString"]}
@@ -0,0 +1,14 @@
1
+ // src/arrayBuffer.ts
2
+ function arrayBufferToHex(buffer) {
3
+ const byteArray = new Uint8Array(buffer);
4
+ return Array.from(byteArray).map((byte) => byte.toString(16).padStart(2, "0")).join("");
5
+ }
6
+ function arrayBufferToBase64(buffer) {
7
+ const byteArray = new Uint8Array(buffer);
8
+ const binaryString = Array.from(byteArray).map((byte) => String.fromCodePoint(byte)).join("");
9
+ return btoa(binaryString);
10
+ }
11
+ export {
12
+ arrayBufferToBase64,
13
+ arrayBufferToHex
14
+ };
@@ -34,4 +34,3 @@ function assert(t, errorMessage) {
34
34
  0 && (module.exports = {
35
35
  assert
36
36
  });
37
- //# sourceMappingURL=assert.js.map
package/assert.d.mts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Type asserts that `t` is truthy. Throws an error with `errorMessage` if
3
+ * `t` is falsy.
4
+ */
5
+ declare function assert<T>(t: T | null | undefined | "" | 0 | -0 | 0n | false | typeof NaN, errorMessage?: string): asserts t is T;
6
+
7
+ export { assert };
package/assert.min.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var r=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var l=(e,s)=>{for(var n in s)r(e,n,{get:s[n],enumerable:!0})},d=(e,s,n,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of a(s))!o.call(e,i)&&i!==n&&r(e,i,{get:()=>s[i],enumerable:!(t=f(s,i))||t.enumerable});return e};var u=e=>d(r({},"__esModule",{value:!0}),e);var N={};l(N,{assert:()=>y});module.exports=u(N);function y(e,s){if(!e)throw new Error(s||`Assertion failed: ${JSON.stringify(e)} is falsy`)}0&&(module.exports={assert});
2
+ //# sourceMappingURL=assert.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Type asserts that `t` is truthy. Throws an error with `errorMessage` if\n * `t` is falsy.\n */\nexport function assert<T>(\n t: T | null | undefined | \"\" | 0 | -0 | 0n | false | typeof NaN,\n errorMessage?: string,\n): asserts t is T {\n if (!t) {\n throw new Error(\n errorMessage || `Assertion failed: ${JSON.stringify(t)} is falsy`,\n );\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,YAAAE,IAAA,eAAAC,EAAAH,GAIO,SAASE,EACdE,EACAC,EACgB,CAChB,GAAI,CAACD,EACH,MAAM,IAAI,MACRC,GAAgB,qBAAqB,KAAK,UAAUD,CAAC,CAAC,WACxD,CAEJ","names":["assert_exports","__export","assert","__toCommonJS","t","errorMessage"]}
package/assert.min.mjs ADDED
@@ -0,0 +1,2 @@
1
+ function i(s,e){if(!s)throw new Error(e||`Assertion failed: ${JSON.stringify(s)} is falsy`)}export{i as assert};
2
+ //# sourceMappingURL=assert.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Type asserts that `t` is truthy. Throws an error with `errorMessage` if\n * `t` is falsy.\n */\nexport function assert<T>(\n t: T | null | undefined | \"\" | 0 | -0 | 0n | false | typeof NaN,\n errorMessage?: string,\n): asserts t is T {\n if (!t) {\n throw new Error(\n errorMessage || `Assertion failed: ${JSON.stringify(t)} is falsy`,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,OACd,GACA,cACgB;AAChB,MAAI,CAAC,GAAG;AACN,UAAM,IAAI;AAAA,MACR,gBAAgB,qBAAqB,KAAK,UAAU,CAAC,CAAC;AAAA,IACxD;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/assert.ts"],"sourcesContent":["/**\n * Type asserts that `t` is truthy. Throws an error with `errorMessage` if\n * `t` is falsy.\n */\nexport function assert<T>(\n t: T | null | undefined | \"\" | 0 | -0 | 0n | false | typeof NaN,\n errorMessage?: string,\n): asserts t is T {\n if (!t) {\n throw new Error(\n errorMessage || `Assertion failed: ${JSON.stringify(t)} is falsy`,\n );\n }\n}\n"],"mappings":"AAIO,SAASA,EACdC,EACAC,EACgB,CAChB,GAAI,CAACD,EACH,MAAM,IAAI,MACRC,GAAgB,qBAAqB,KAAK,UAAUD,CAAC,CAAC,WACxD,CAEJ","names":["assert","t","errorMessage"]}
package/assert.mjs ADDED
@@ -0,0 +1,11 @@
1
+ // src/assert.ts
2
+ function assert(t, errorMessage) {
3
+ if (!t) {
4
+ throw new Error(
5
+ errorMessage || `Assertion failed: ${JSON.stringify(t)} is falsy`
6
+ );
7
+ }
8
+ }
9
+ export {
10
+ assert
11
+ };
@@ -45,4 +45,3 @@ function average(numbers) {
45
45
  0 && (module.exports = {
46
46
  average
47
47
  });
48
- //# sourceMappingURL=average.js.map
package/average.d.mts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Average all the numbers together in the given array. Treats null, undefined
3
+ * and NaN as zero.
4
+ */
5
+ declare function average(numbers: (number | null | undefined)[]): number;
6
+
7
+ export { average };
@@ -0,0 +1,2 @@
1
+ "use strict";var i=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var d=(n,e)=>{for(var u in e)i(n,u,{get:e[u],enumerable:!0})},a=(n,e,u,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of m(e))!f.call(n,t)&&t!==u&&i(n,t,{get:()=>e[t],enumerable:!(r=o(e,t))||r.enumerable});return n};var b=n=>a(i({},"__esModule",{value:!0}),n);var s={};d(s,{average:()=>p});module.exports=b(s);function l(n){return n.reduce((e,u)=>{let r=typeof u=="number"&&!isNaN(u)&&isFinite(u)?u:0;return e+r},0)}function p(n){return n.length===0?0:l(n)/n.length}0&&(module.exports={average});
2
+ //# sourceMappingURL=average.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/average.ts","../src/sum.ts"],"sourcesContent":["import { sum } from \"./sum\";\n\n/**\n * Average all the numbers together in the given array. Treats null, undefined\n * and NaN as zero.\n */\nexport function average(numbers: (number | null | undefined)[]): number {\n if (numbers.length === 0) return 0;\n\n const total = sum(numbers);\n\n return total / numbers.length;\n}\n","/**\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;;;ACIO,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;;;ADVO,SAAS,QAAQ,SAAgD;AACtE,MAAI,QAAQ,WAAW,EAAG,QAAO;AAEjC,QAAM,QAAQ,IAAI,OAAO;AAEzB,SAAO,QAAQ,QAAQ;AACzB;","names":[]}
1
+ {"version":3,"sources":["../src/average.ts","../src/sum.ts"],"sourcesContent":["import { sum } from \"./sum\";\n\n/**\n * Average all the numbers together in the given array. Treats null, undefined\n * and NaN as zero.\n */\nexport function average(numbers: (number | null | undefined)[]): number {\n if (numbers.length === 0) return 0;\n\n const total = sum(numbers);\n\n return total / numbers.length;\n}\n","/**\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,aAAAE,IAAA,eAAAC,EAAAH,GCIO,SAASI,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,CDVO,SAASC,EAAQC,EAAgD,CACtE,OAAIA,EAAQ,SAAW,EAAU,EAEnBC,EAAID,CAAO,EAEVA,EAAQ,MACzB","names":["average_exports","__export","average","__toCommonJS","sum","numbers","accumulated","current","value","average","numbers","sum"]}
@@ -0,0 +1,2 @@
1
+ function t(n){return n.reduce((u,e)=>{let r=typeof e=="number"&&!isNaN(e)&&isFinite(e)?e:0;return u+r},0)}function o(n){return n.length===0?0:t(n)/n.length}export{o as average};
2
+ //# sourceMappingURL=average.min.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sum.ts","../src/average.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","import { sum } from \"./sum\";\n\n/**\n * Average all the numbers together in the given array. Treats null, undefined\n * and NaN as zero.\n */\nexport function average(numbers: (number | null | undefined)[]): number {\n if (numbers.length === 0) return 0;\n\n const total = sum(numbers);\n\n return total / numbers.length;\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,CCVO,SAASC,EAAQC,EAAgD,CACtE,OAAIA,EAAQ,SAAW,EAAU,EAEnBC,EAAID,CAAO,EAEVA,EAAQ,MACzB","names":["sum","numbers","accumulated","current","value","average","numbers","sum"]}
package/average.mjs ADDED
@@ -0,0 +1,20 @@
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
+
12
+ // src/average.ts
13
+ function average(numbers) {
14
+ if (numbers.length === 0) return 0;
15
+ const total = sum(numbers);
16
+ return total / numbers.length;
17
+ }
18
+ export {
19
+ average
20
+ };
@@ -38,4 +38,3 @@ function base64UrlToBase64(base64Url) {
38
38
  base64ToBase64URL,
39
39
  base64UrlToBase64
40
40
  });
41
- //# sourceMappingURL=base64Url.js.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Convert a base64 string to a base64url string.
3
+ */
4
+ declare function base64ToBase64URL(base64: string): string;
5
+ /**
6
+ * Convert a base64url string to a base64 string.
7
+ */
8
+ declare function base64UrlToBase64(base64Url: string): string;
9
+
10
+ export { base64ToBase64URL, base64UrlToBase64 };
@@ -0,0 +1,2 @@
1
+ "use strict";var a=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var o=(e,r)=>{for(var t in r)a(e,t,{get:r[t],enumerable:!0})},i=(e,r,t,g)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of c(r))!p.call(e,n)&&n!==t&&a(e,n,{get:()=>r[n],enumerable:!(g=s(r,n))||g.enumerable});return e};var l=e=>i(a({},"__esModule",{value:!0}),e);var b={};o(b,{base64ToBase64URL:()=>u,base64UrlToBase64:()=>f});module.exports=l(b);function u(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function f(e){if(!e)return"";let r=e.replace(/-/g,"+").replace(/_/g,"/"),t=(4-r.length%4)%4;return r+"=".repeat(t)}0&&(module.exports={base64ToBase64URL,base64UrlToBase64});
2
+ //# sourceMappingURL=base64Url.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/base64Url.ts"],"sourcesContent":["/**\n * Convert a base64 string to a base64url string.\n */\nexport function base64ToBase64URL(base64: string): string {\n return base64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\"); // Remove padding\n}\n\n/**\n * Convert a base64url string to a base64 string.\n */\nexport function base64UrlToBase64(base64Url: string): string {\n if (!base64Url) return \"\";\n\n // Replace URL-safe characters\n const base64 = base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n\n // Calculate and add padding\n const padLength = (4 - (base64.length % 4)) % 4;\n return base64 + \"=\".repeat(padLength);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,sBAAAC,IAAA,eAAAC,EAAAJ,GAGO,SAASE,EAAkBG,EAAwB,CACxD,OAAOA,EAAO,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,EAAE,CACzE,CAKO,SAASF,EAAkBG,EAA2B,CAC3D,GAAI,CAACA,EAAW,MAAO,GAGvB,IAAMD,EAASC,EAAU,QAAQ,KAAM,GAAG,EAAE,QAAQ,KAAM,GAAG,EAGvDC,GAAa,EAAKF,EAAO,OAAS,GAAM,EAC9C,OAAOA,EAAS,IAAI,OAAOE,CAAS,CACtC","names":["base64Url_exports","__export","base64ToBase64URL","base64UrlToBase64","__toCommonJS","base64","base64Url","padLength"]}
@@ -0,0 +1,2 @@
1
+ function n(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function a(e){if(!e)return"";let r=e.replace(/-/g,"+").replace(/_/g,"/"),t=(4-r.length%4)%4;return r+"=".repeat(t)}export{n as base64ToBase64URL,a as base64UrlToBase64};
2
+ //# sourceMappingURL=base64Url.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/base64Url.ts"],"sourcesContent":["/**\n * Convert a base64 string to a base64url string.\n */\nexport function base64ToBase64URL(base64: string): string {\n return base64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\"); // Remove padding\n}\n\n/**\n * Convert a base64url string to a base64 string.\n */\nexport function base64UrlToBase64(base64Url: string): string {\n if (!base64Url) return \"\";\n\n // Replace URL-safe characters\n const base64 = base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n\n // Calculate and add padding\n const padLength = (4 - (base64.length % 4)) % 4;\n return base64 + \"=\".repeat(padLength);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,kBAAkB,QAAwB;AACxD,SAAO,OAAO,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE;AACzE;AAKO,SAAS,kBAAkB,WAA2B;AAC3D,MAAI,CAAC,UAAW,QAAO;AAGvB,QAAM,SAAS,UAAU,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG;AAG7D,QAAM,aAAa,IAAK,OAAO,SAAS,KAAM;AAC9C,SAAO,SAAS,IAAI,OAAO,SAAS;AACtC;","names":[]}
1
+ {"version":3,"sources":["../src/base64Url.ts"],"sourcesContent":["/**\n * Convert a base64 string to a base64url string.\n */\nexport function base64ToBase64URL(base64: string): string {\n return base64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\"); // Remove padding\n}\n\n/**\n * Convert a base64url string to a base64 string.\n */\nexport function base64UrlToBase64(base64Url: string): string {\n if (!base64Url) return \"\";\n\n // Replace URL-safe characters\n const base64 = base64Url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n\n // Calculate and add padding\n const padLength = (4 - (base64.length % 4)) % 4;\n return base64 + \"=\".repeat(padLength);\n}\n"],"mappings":"AAGO,SAASA,EAAkBC,EAAwB,CACxD,OAAOA,EAAO,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,GAAG,EAAE,QAAQ,MAAO,EAAE,CACzE,CAKO,SAASC,EAAkBC,EAA2B,CAC3D,GAAI,CAACA,EAAW,MAAO,GAGvB,IAAMF,EAASE,EAAU,QAAQ,KAAM,GAAG,EAAE,QAAQ,KAAM,GAAG,EAGvDC,GAAa,EAAKH,EAAO,OAAS,GAAM,EAC9C,OAAOA,EAAS,IAAI,OAAOG,CAAS,CACtC","names":["base64ToBase64URL","base64","base64UrlToBase64","base64Url","padLength"]}
package/base64Url.mjs ADDED
@@ -0,0 +1,14 @@
1
+ // src/base64Url.ts
2
+ function base64ToBase64URL(base64) {
3
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
4
+ }
5
+ function base64UrlToBase64(base64Url) {
6
+ if (!base64Url) return "";
7
+ const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
8
+ const padLength = (4 - base64.length % 4) % 4;
9
+ return base64 + "=".repeat(padLength);
10
+ }
11
+ export {
12
+ base64ToBase64URL,
13
+ base64UrlToBase64
14
+ };
@@ -117,4 +117,3 @@ function getDisplayDateTime(ts) {
117
117
  yyyyMm,
118
118
  yyyyMmDd
119
119
  });
120
- //# sourceMappingURL=dateTimeStr.js.map
@@ -0,0 +1,85 @@
1
+ type AnyDateTime = number | Date | string;
2
+ /**
3
+ * Convert a number (epoch seconds or milliseconds), string (parseable
4
+ * date/time or epoch seconds or milliseconds), or Date object (no conversion)
5
+ * into a Date object.
6
+ */
7
+ declare function toDate(ts: AnyDateTime): Date;
8
+ /**
9
+ * Returns a date in yyyy-MM format. E.g. '2000-01'.
10
+ *
11
+ * @param dt Specify a date object or default to the current date.
12
+ * @param separator Defaults to '-'.
13
+ */
14
+ declare function yyyyMm(dt?: Date, separator?: string): string;
15
+ /**
16
+ * Returns a date in yyyy-MM-dd format. E.g. '2000-01-02'.
17
+ *
18
+ * @param dt Specify a date object or default to the current date.
19
+ * @param separator Defaults to '-'.
20
+ */
21
+ declare function yyyyMmDd(dt?: Date, separator?: string): string;
22
+ /**
23
+ * Returns a date in hh:mm format. E.g. '01:02'.
24
+ *
25
+ * @param dt Specify a date object or default to the current date/time.
26
+ * @param separator Defaults to ':'.
27
+ */
28
+ declare function hhMm(dt?: Date, separator?: string): string;
29
+ /**
30
+ * Returns a date in hh:mm:ss format. E.g. '01:02:03'.
31
+ *
32
+ * @param dt Specify a date object or default to the current date/time.
33
+ * @param separator Defaults to ':'.
34
+ */
35
+ declare function hhMmSs(dt?: Date, separator?: string): string;
36
+ /**
37
+ * Returns a date in hh:mm:ss.SSS format. E.g. '01:02:03.004'.
38
+ *
39
+ * @param dt Specify a date object or default to the current date/time.
40
+ * @param timeSeparator Separator for hh/mm/ss. Defaults to ':'.
41
+ * @param msSeparator Separator before SSS. Defaults to '.'.
42
+ */
43
+ declare function hhMmSsMs(dt?: Date, timeSeparator?: string, msSeparator?: string): string;
44
+ /**
45
+ * Returns the timezone string for the given date. E.g. '+8', '-3.5'.
46
+ * Returns 'Z' for UTC.
47
+ *
48
+ * @param dt Specify a date object or default to the current date/time.
49
+ */
50
+ declare function tzShort(dt?: Date): string;
51
+ /**
52
+ * Returns the long month name, zero-indexed. E.g. 0 for 'January'.
53
+ *
54
+ * @param month Zero-indexed month.
55
+ * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
56
+ */
57
+ declare function getLongMonthNameZeroIndexed(month: number, locales?: Intl.LocalesArgument): string;
58
+ /**
59
+ * Returns the long month name, one-indexed. E.g. 1 for 'January'.
60
+ *
61
+ * @param month One-indexed month.
62
+ * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
63
+ */
64
+ declare function getLongMonthNameOneIndexed(month: number, locales?: Intl.LocalesArgument): string;
65
+ /**
66
+ * Returns the short month name, zero-indexed. E.g. 0 for 'Jan'.
67
+ *
68
+ * @param month Zero-indexed month.
69
+ * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
70
+ */
71
+ declare function getShortMonthNameZeroIndexed(month: number, locales?: Intl.LocalesArgument): string;
72
+ /**
73
+ * Returns the short month name, one-indexed. E.g. 1 for 'Jan'.
74
+ *
75
+ * @param month One-indexed month.
76
+ * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
77
+ */
78
+ declare function getShortMonthNameOneIndexed(month: number, locales?: Intl.LocalesArgument): string;
79
+ /**
80
+ * Returns a human-readable string date/time like '2025-01-01 22:31:16Z'.
81
+ * Excludes the milliseconds assuming it is not necessary for display.
82
+ */
83
+ declare function getDisplayDateTime(ts: AnyDateTime): string;
84
+
85
+ export { type AnyDateTime, getDisplayDateTime, getLongMonthNameOneIndexed, getLongMonthNameZeroIndexed, getShortMonthNameOneIndexed, getShortMonthNameZeroIndexed, hhMm, hhMmSs, hhMmSsMs, toDate, tzShort, yyyyMm, yyyyMmDd };
@@ -0,0 +1,2 @@
1
+ "use strict";var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var h=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},x=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of l(t))!D.call(e,o)&&o!==n&&i(e,o,{get:()=>t[o],enumerable:!(r=f(t,o))||r.enumerable});return e};var y=e=>x(i({},"__esModule",{value:!0}),e);var A={};h(A,{getDisplayDateTime:()=>b,getLongMonthNameOneIndexed:()=>S,getLongMonthNameZeroIndexed:()=>c,getShortMonthNameOneIndexed:()=>I,getShortMonthNameZeroIndexed:()=>m,hhMm:()=>g,hhMmSs:()=>a,hhMmSsMs:()=>d,toDate:()=>u,tzShort:()=>w,yyyyMm:()=>s,yyyyMmDd:()=>M});module.exports=y(A);function p(e){return/^\d+$/.test(e)}function u(e){return typeof e=="number"?e<1e11?new Date(e*1e3):new Date(e):typeof e=="string"?p(e)?u(Number(e)):new Date(e):e}function s(e=new Date,t="-"){let n=e.getFullYear(),r=e.getMonth()+1;return n+t+(r<10?"0"+r:r)}function M(e=new Date,t="-"){let n=e.getDate();return s(e,t)+t+(n<10?"0"+n:n)}function g(e=new Date,t=":"){let n=e.getHours(),r=e.getMinutes();return(n<10?"0"+n:n)+t+(r<10?"0"+r:r)}function a(e=new Date,t=":"){let n=e.getSeconds();return g(e,t)+t+(n<10?"0"+n:n)}function d(e=new Date,t=":",n="."){let r=e.getMilliseconds();return a(e,t)+n+(r<10?"00"+r:r<100?"0"+r:r)}function w(e=new Date){if(e.getTimezoneOffset()===0)return"Z";let t=e.getTimezoneOffset()/60;return t>=0?"+"+t:String(t)}function c(e,t="default"){return new Date(2024,e,15).toLocaleString(t,{month:"long"})}function S(e,t="default"){return c(e-1,t)}function m(e,t="default"){return new Date(2e3,e,15).toLocaleString(t,{month:"short"})}function I(e,t="default"){return m(e-1,t)}function b(e){return(u(e).toISOString().slice(0,19)+"Z").replace("T"," ")}0&&(module.exports={getDisplayDateTime,getLongMonthNameOneIndexed,getLongMonthNameZeroIndexed,getShortMonthNameOneIndexed,getShortMonthNameZeroIndexed,hhMm,hhMmSs,hhMmSsMs,toDate,tzShort,yyyyMm,yyyyMmDd});
2
+ //# sourceMappingURL=dateTimeStr.min.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/dateTimeStr.ts"],"sourcesContent":["export type AnyDateTime = number | Date | string;\n\nfunction isAllDigits(str: string): boolean {\n return /^\\d+$/.test(str);\n}\n\n/**\n * Convert a number (epoch seconds or milliseconds), string (parseable\n * date/time or epoch seconds or milliseconds), or Date object (no conversion)\n * into a Date object.\n */\nexport function toDate(ts: AnyDateTime): Date {\n if (typeof ts === \"number\") {\n // Handle timestamp in seconds (less than 12 digits long).\n if (ts < 1_000_000_000_00) {\n return new Date(ts * 1000);\n }\n\n // Handle timestamp in milliseconds.\n return new Date(ts);\n }\n\n if (typeof ts === \"string\") {\n if (isAllDigits(ts)) {\n return toDate(Number(ts));\n }\n\n return new Date(ts);\n }\n\n return ts;\n}\n\n/**\n * Returns a date in yyyy-MM format. E.g. '2000-01'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMm(dt = new Date(), separator = \"-\"): string {\n const yr = dt.getFullYear();\n const mth = dt.getMonth() + 1;\n\n return yr + separator + (mth < 10 ? \"0\" + mth : mth);\n}\n\n/**\n * Returns a date in yyyy-MM-dd format. E.g. '2000-01-02'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMmDd(dt = new Date(), separator = \"-\"): string {\n const day = dt.getDate();\n\n return yyyyMm(dt, separator) + separator + (day < 10 ? \"0\" + day : day);\n}\n\n/**\n * Returns a date in hh:mm format. E.g. '01:02'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMm(dt = new Date(), separator = \":\"): string {\n const hr = dt.getHours();\n const min = dt.getMinutes();\n\n return (hr < 10 ? \"0\" + hr : hr) + separator + (min < 10 ? \"0\" + min : min);\n}\n\n/**\n * Returns a date in hh:mm:ss format. E.g. '01:02:03'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMmSs(dt = new Date(), separator = \":\"): string {\n const sec = dt.getSeconds();\n\n return hhMm(dt, separator) + separator + (sec < 10 ? \"0\" + sec : sec);\n}\n\n/**\n * Returns a date in hh:mm:ss.SSS format. E.g. '01:02:03.004'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param timeSeparator Separator for hh/mm/ss. Defaults to ':'.\n * @param msSeparator Separator before SSS. Defaults to '.'.\n */\nexport function hhMmSsMs(\n dt = new Date(),\n timeSeparator = \":\",\n msSeparator = \".\",\n): string {\n const ms = dt.getMilliseconds();\n\n return (\n hhMmSs(dt, timeSeparator) +\n msSeparator +\n (ms < 10 ? \"00\" + ms : ms < 100 ? \"0\" + ms : ms)\n );\n}\n\n/**\n * Returns the timezone string for the given date. E.g. '+8', '-3.5'.\n * Returns 'Z' for UTC.\n *\n * @param dt Specify a date object or default to the current date/time.\n */\nexport function tzShort(dt = new Date()): string {\n if (dt.getTimezoneOffset() === 0) {\n return \"Z\";\n }\n\n const tzHours = dt.getTimezoneOffset() / 60;\n return tzHours >= 0 ? \"+\" + tzHours : String(tzHours);\n}\n\n/**\n * Returns the long month name, zero-indexed. E.g. 0 for 'January'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2024, month, 15).toLocaleString(locales, {\n month: \"long\",\n });\n}\n\n/**\n * Returns the long month name, one-indexed. E.g. 1 for 'January'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getLongMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns the short month name, zero-indexed. E.g. 0 for 'Jan'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2000, month, 15).toLocaleString(locales, {\n month: \"short\",\n });\n}\n\n/**\n * Returns the short month name, one-indexed. E.g. 1 for 'Jan'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getShortMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns a human-readable string date/time like '2025-01-01 22:31:16Z'.\n * Excludes the milliseconds assuming it is not necessary for display.\n */\nexport function getDisplayDateTime(ts: AnyDateTime) {\n const iso = toDate(ts).toISOString();\n const noMs = iso.slice(0, 19) + \"Z\";\n return noMs.replace(\"T\", \" \");\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,+BAAAC,EAAA,gCAAAC,EAAA,gCAAAC,EAAA,iCAAAC,EAAA,SAAAC,EAAA,WAAAC,EAAA,aAAAC,EAAA,WAAAC,EAAA,YAAAC,EAAA,WAAAC,EAAA,aAAAC,IAAA,eAAAC,EAAAd,GAEA,SAASe,EAAYC,EAAsB,CACzC,MAAO,QAAQ,KAAKA,CAAG,CACzB,CAOO,SAASN,EAAOO,EAAuB,CAC5C,OAAI,OAAOA,GAAO,SAEZA,EAAK,KACA,IAAI,KAAKA,EAAK,GAAI,EAIpB,IAAI,KAAKA,CAAE,EAGhB,OAAOA,GAAO,SACZF,EAAYE,CAAE,EACTP,EAAO,OAAOO,CAAE,CAAC,EAGnB,IAAI,KAAKA,CAAE,EAGbA,CACT,CAQO,SAASL,EAAOM,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC/D,IAAMC,EAAKF,EAAG,YAAY,EACpBG,EAAMH,EAAG,SAAS,EAAI,EAE5B,OAAOE,EAAKD,GAAaE,EAAM,GAAK,IAAMA,EAAMA,EAClD,CAQO,SAASR,EAASK,EAAK,IAAI,KAAQC,EAAY,IAAa,CACjE,IAAMG,EAAMJ,EAAG,QAAQ,EAEvB,OAAON,EAAOM,EAAIC,CAAS,EAAIA,GAAaG,EAAM,GAAK,IAAMA,EAAMA,EACrE,CAQO,SAASf,EAAKW,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC7D,IAAMI,EAAKL,EAAG,SAAS,EACjBM,EAAMN,EAAG,WAAW,EAE1B,OAAQK,EAAK,GAAK,IAAMA,EAAKA,GAAMJ,GAAaK,EAAM,GAAK,IAAMA,EAAMA,EACzE,CAQO,SAAShB,EAAOU,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC/D,IAAMM,EAAMP,EAAG,WAAW,EAE1B,OAAOX,EAAKW,EAAIC,CAAS,EAAIA,GAAaM,EAAM,GAAK,IAAMA,EAAMA,EACnE,CASO,SAAShB,EACdS,EAAK,IAAI,KACTQ,EAAgB,IAChBC,EAAc,IACN,CACR,IAAMC,EAAKV,EAAG,gBAAgB,EAE9B,OACEV,EAAOU,EAAIQ,CAAa,EACxBC,GACCC,EAAK,GAAK,KAAOA,EAAKA,EAAK,IAAM,IAAMA,EAAKA,EAEjD,CAQO,SAASjB,EAAQO,EAAK,IAAI,KAAgB,CAC/C,GAAIA,EAAG,kBAAkB,IAAM,EAC7B,MAAO,IAGT,IAAMW,EAAUX,EAAG,kBAAkB,EAAI,GACzC,OAAOW,GAAW,EAAI,IAAMA,EAAU,OAAOA,CAAO,CACtD,CAQO,SAASzB,EACd0B,EACAC,EAAgC,UACxB,CACR,OAAO,IAAI,KAAK,KAAMD,EAAO,EAAE,EAAE,eAAeC,EAAS,CACvD,MAAO,MACT,CAAC,CACH,CAQO,SAAS5B,EACd2B,EACAC,EAAgC,UACxB,CACR,OAAO3B,EAA4B0B,EAAQ,EAAGC,CAAO,CACvD,CAQO,SAASzB,EACdwB,EACAC,EAAgC,UACxB,CACR,OAAO,IAAI,KAAK,IAAMD,EAAO,EAAE,EAAE,eAAeC,EAAS,CACvD,MAAO,OACT,CAAC,CACH,CAQO,SAAS1B,EACdyB,EACAC,EAAgC,UACxB,CACR,OAAOzB,EAA6BwB,EAAQ,EAAGC,CAAO,CACxD,CAMO,SAAS7B,EAAmBe,EAAiB,CAGlD,OAFYP,EAAOO,CAAE,EAAE,YAAY,EAClB,MAAM,EAAG,EAAE,EAAI,KACpB,QAAQ,IAAK,GAAG,CAC9B","names":["dateTimeStr_exports","__export","getDisplayDateTime","getLongMonthNameOneIndexed","getLongMonthNameZeroIndexed","getShortMonthNameOneIndexed","getShortMonthNameZeroIndexed","hhMm","hhMmSs","hhMmSsMs","toDate","tzShort","yyyyMm","yyyyMmDd","__toCommonJS","isAllDigits","str","ts","dt","separator","yr","mth","day","hr","min","sec","timeSeparator","msSeparator","ms","tzHours","month","locales"]}
@@ -0,0 +1,2 @@
1
+ function i(e){return/^\d+$/.test(e)}function o(e){return typeof e=="number"?e<1e11?new Date(e*1e3):new Date(e):typeof e=="string"?i(e)?o(Number(e)):new Date(e):e}function u(e=new Date,t="-"){let n=e.getFullYear(),r=e.getMonth()+1;return n+t+(r<10?"0"+r:r)}function m(e=new Date,t="-"){let n=e.getDate();return u(e,t)+t+(n<10?"0"+n:n)}function s(e=new Date,t=":"){let n=e.getHours(),r=e.getMinutes();return(n<10?"0"+n:n)+t+(r<10?"0"+r:r)}function g(e=new Date,t=":"){let n=e.getSeconds();return s(e,t)+t+(n<10?"0"+n:n)}function f(e=new Date,t=":",n="."){let r=e.getMilliseconds();return g(e,t)+n+(r<10?"00"+r:r<100?"0"+r:r)}function l(e=new Date){if(e.getTimezoneOffset()===0)return"Z";let t=e.getTimezoneOffset()/60;return t>=0?"+"+t:String(t)}function a(e,t="default"){return new Date(2024,e,15).toLocaleString(t,{month:"long"})}function D(e,t="default"){return a(e-1,t)}function c(e,t="default"){return new Date(2e3,e,15).toLocaleString(t,{month:"short"})}function h(e,t="default"){return c(e-1,t)}function x(e){return(o(e).toISOString().slice(0,19)+"Z").replace("T"," ")}export{x as getDisplayDateTime,D as getLongMonthNameOneIndexed,a as getLongMonthNameZeroIndexed,h as getShortMonthNameOneIndexed,c as getShortMonthNameZeroIndexed,s as hhMm,g as hhMmSs,f as hhMmSsMs,o as toDate,l as tzShort,u as yyyyMm,m as yyyyMmDd};
2
+ //# sourceMappingURL=dateTimeStr.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dateTimeStr.ts"],"sourcesContent":["export type AnyDateTime = number | Date | string;\n\nfunction isAllDigits(str: string): boolean {\n return /^\\d+$/.test(str);\n}\n\n/**\n * Convert a number (epoch seconds or milliseconds), string (parseable\n * date/time or epoch seconds or milliseconds), or Date object (no conversion)\n * into a Date object.\n */\nexport function toDate(ts: AnyDateTime): Date {\n if (typeof ts === \"number\") {\n // Handle timestamp in seconds (less than 12 digits long).\n if (ts < 1_000_000_000_00) {\n return new Date(ts * 1000);\n }\n\n // Handle timestamp in milliseconds.\n return new Date(ts);\n }\n\n if (typeof ts === \"string\") {\n if (isAllDigits(ts)) {\n return toDate(Number(ts));\n }\n\n return new Date(ts);\n }\n\n return ts;\n}\n\n/**\n * Returns a date in yyyy-MM format. E.g. '2000-01'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMm(dt = new Date(), separator = \"-\"): string {\n const yr = dt.getFullYear();\n const mth = dt.getMonth() + 1;\n\n return yr + separator + (mth < 10 ? \"0\" + mth : mth);\n}\n\n/**\n * Returns a date in yyyy-MM-dd format. E.g. '2000-01-02'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMmDd(dt = new Date(), separator = \"-\"): string {\n const day = dt.getDate();\n\n return yyyyMm(dt, separator) + separator + (day < 10 ? \"0\" + day : day);\n}\n\n/**\n * Returns a date in hh:mm format. E.g. '01:02'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMm(dt = new Date(), separator = \":\"): string {\n const hr = dt.getHours();\n const min = dt.getMinutes();\n\n return (hr < 10 ? \"0\" + hr : hr) + separator + (min < 10 ? \"0\" + min : min);\n}\n\n/**\n * Returns a date in hh:mm:ss format. E.g. '01:02:03'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMmSs(dt = new Date(), separator = \":\"): string {\n const sec = dt.getSeconds();\n\n return hhMm(dt, separator) + separator + (sec < 10 ? \"0\" + sec : sec);\n}\n\n/**\n * Returns a date in hh:mm:ss.SSS format. E.g. '01:02:03.004'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param timeSeparator Separator for hh/mm/ss. Defaults to ':'.\n * @param msSeparator Separator before SSS. Defaults to '.'.\n */\nexport function hhMmSsMs(\n dt = new Date(),\n timeSeparator = \":\",\n msSeparator = \".\",\n): string {\n const ms = dt.getMilliseconds();\n\n return (\n hhMmSs(dt, timeSeparator) +\n msSeparator +\n (ms < 10 ? \"00\" + ms : ms < 100 ? \"0\" + ms : ms)\n );\n}\n\n/**\n * Returns the timezone string for the given date. E.g. '+8', '-3.5'.\n * Returns 'Z' for UTC.\n *\n * @param dt Specify a date object or default to the current date/time.\n */\nexport function tzShort(dt = new Date()): string {\n if (dt.getTimezoneOffset() === 0) {\n return \"Z\";\n }\n\n const tzHours = dt.getTimezoneOffset() / 60;\n return tzHours >= 0 ? \"+\" + tzHours : String(tzHours);\n}\n\n/**\n * Returns the long month name, zero-indexed. E.g. 0 for 'January'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2024, month, 15).toLocaleString(locales, {\n month: \"long\",\n });\n}\n\n/**\n * Returns the long month name, one-indexed. E.g. 1 for 'January'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getLongMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns the short month name, zero-indexed. E.g. 0 for 'Jan'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2000, month, 15).toLocaleString(locales, {\n month: \"short\",\n });\n}\n\n/**\n * Returns the short month name, one-indexed. E.g. 1 for 'Jan'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getShortMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns a human-readable string date/time like '2025-01-01 22:31:16Z'.\n * Excludes the milliseconds assuming it is not necessary for display.\n */\nexport function getDisplayDateTime(ts: AnyDateTime) {\n const iso = toDate(ts).toISOString();\n const noMs = iso.slice(0, 19) + \"Z\";\n return noMs.replace(\"T\", \" \");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,SAAS,YAAY,KAAsB;AACzC,SAAO,QAAQ,KAAK,GAAG;AACzB;AAOO,SAAS,OAAO,IAAuB;AAC5C,MAAI,OAAO,OAAO,UAAU;AAE1B,QAAI,KAAK,MAAkB;AACzB,aAAO,IAAI,KAAK,KAAK,GAAI;AAAA,IAC3B;AAGA,WAAO,IAAI,KAAK,EAAE;AAAA,EACpB;AAEA,MAAI,OAAO,OAAO,UAAU;AAC1B,QAAI,YAAY,EAAE,GAAG;AACnB,aAAO,OAAO,OAAO,EAAE,CAAC;AAAA,IAC1B;AAEA,WAAO,IAAI,KAAK,EAAE;AAAA,EACpB;AAEA,SAAO;AACT;AAQO,SAAS,OAAO,KAAK,oBAAI,KAAK,GAAG,YAAY,KAAa;AAC/D,QAAM,KAAK,GAAG,YAAY;AAC1B,QAAM,MAAM,GAAG,SAAS,IAAI;AAE5B,SAAO,KAAK,aAAa,MAAM,KAAK,MAAM,MAAM;AAClD;AAQO,SAAS,SAAS,KAAK,oBAAI,KAAK,GAAG,YAAY,KAAa;AACjE,QAAM,MAAM,GAAG,QAAQ;AAEvB,SAAO,OAAO,IAAI,SAAS,IAAI,aAAa,MAAM,KAAK,MAAM,MAAM;AACrE;AAQO,SAAS,KAAK,KAAK,oBAAI,KAAK,GAAG,YAAY,KAAa;AAC7D,QAAM,KAAK,GAAG,SAAS;AACvB,QAAM,MAAM,GAAG,WAAW;AAE1B,UAAQ,KAAK,KAAK,MAAM,KAAK,MAAM,aAAa,MAAM,KAAK,MAAM,MAAM;AACzE;AAQO,SAAS,OAAO,KAAK,oBAAI,KAAK,GAAG,YAAY,KAAa;AAC/D,QAAM,MAAM,GAAG,WAAW;AAE1B,SAAO,KAAK,IAAI,SAAS,IAAI,aAAa,MAAM,KAAK,MAAM,MAAM;AACnE;AASO,SAAS,SACd,KAAK,oBAAI,KAAK,GACd,gBAAgB,KAChB,cAAc,KACN;AACR,QAAM,KAAK,GAAG,gBAAgB;AAE9B,SACE,OAAO,IAAI,aAAa,IACxB,eACC,KAAK,KAAK,OAAO,KAAK,KAAK,MAAM,MAAM,KAAK;AAEjD;AAQO,SAAS,QAAQ,KAAK,oBAAI,KAAK,GAAW;AAC/C,MAAI,GAAG,kBAAkB,MAAM,GAAG;AAChC,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,GAAG,kBAAkB,IAAI;AACzC,SAAO,WAAW,IAAI,MAAM,UAAU,OAAO,OAAO;AACtD;AAQO,SAAS,4BACd,OACA,UAAgC,WACxB;AACR,SAAO,IAAI,KAAK,MAAM,OAAO,EAAE,EAAE,eAAe,SAAS;AAAA,IACvD,OAAO;AAAA,EACT,CAAC;AACH;AAQO,SAAS,2BACd,OACA,UAAgC,WACxB;AACR,SAAO,4BAA4B,QAAQ,GAAG,OAAO;AACvD;AAQO,SAAS,6BACd,OACA,UAAgC,WACxB;AACR,SAAO,IAAI,KAAK,KAAM,OAAO,EAAE,EAAE,eAAe,SAAS;AAAA,IACvD,OAAO;AAAA,EACT,CAAC;AACH;AAQO,SAAS,4BACd,OACA,UAAgC,WACxB;AACR,SAAO,6BAA6B,QAAQ,GAAG,OAAO;AACxD;AAMO,SAAS,mBAAmB,IAAiB;AAClD,QAAM,MAAM,OAAO,EAAE,EAAE,YAAY;AACnC,QAAM,OAAO,IAAI,MAAM,GAAG,EAAE,IAAI;AAChC,SAAO,KAAK,QAAQ,KAAK,GAAG;AAC9B;","names":[]}
1
+ {"version":3,"sources":["../src/dateTimeStr.ts"],"sourcesContent":["export type AnyDateTime = number | Date | string;\n\nfunction isAllDigits(str: string): boolean {\n return /^\\d+$/.test(str);\n}\n\n/**\n * Convert a number (epoch seconds or milliseconds), string (parseable\n * date/time or epoch seconds or milliseconds), or Date object (no conversion)\n * into a Date object.\n */\nexport function toDate(ts: AnyDateTime): Date {\n if (typeof ts === \"number\") {\n // Handle timestamp in seconds (less than 12 digits long).\n if (ts < 1_000_000_000_00) {\n return new Date(ts * 1000);\n }\n\n // Handle timestamp in milliseconds.\n return new Date(ts);\n }\n\n if (typeof ts === \"string\") {\n if (isAllDigits(ts)) {\n return toDate(Number(ts));\n }\n\n return new Date(ts);\n }\n\n return ts;\n}\n\n/**\n * Returns a date in yyyy-MM format. E.g. '2000-01'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMm(dt = new Date(), separator = \"-\"): string {\n const yr = dt.getFullYear();\n const mth = dt.getMonth() + 1;\n\n return yr + separator + (mth < 10 ? \"0\" + mth : mth);\n}\n\n/**\n * Returns a date in yyyy-MM-dd format. E.g. '2000-01-02'.\n *\n * @param dt Specify a date object or default to the current date.\n * @param separator Defaults to '-'.\n */\nexport function yyyyMmDd(dt = new Date(), separator = \"-\"): string {\n const day = dt.getDate();\n\n return yyyyMm(dt, separator) + separator + (day < 10 ? \"0\" + day : day);\n}\n\n/**\n * Returns a date in hh:mm format. E.g. '01:02'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMm(dt = new Date(), separator = \":\"): string {\n const hr = dt.getHours();\n const min = dt.getMinutes();\n\n return (hr < 10 ? \"0\" + hr : hr) + separator + (min < 10 ? \"0\" + min : min);\n}\n\n/**\n * Returns a date in hh:mm:ss format. E.g. '01:02:03'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param separator Defaults to ':'.\n */\nexport function hhMmSs(dt = new Date(), separator = \":\"): string {\n const sec = dt.getSeconds();\n\n return hhMm(dt, separator) + separator + (sec < 10 ? \"0\" + sec : sec);\n}\n\n/**\n * Returns a date in hh:mm:ss.SSS format. E.g. '01:02:03.004'.\n *\n * @param dt Specify a date object or default to the current date/time.\n * @param timeSeparator Separator for hh/mm/ss. Defaults to ':'.\n * @param msSeparator Separator before SSS. Defaults to '.'.\n */\nexport function hhMmSsMs(\n dt = new Date(),\n timeSeparator = \":\",\n msSeparator = \".\",\n): string {\n const ms = dt.getMilliseconds();\n\n return (\n hhMmSs(dt, timeSeparator) +\n msSeparator +\n (ms < 10 ? \"00\" + ms : ms < 100 ? \"0\" + ms : ms)\n );\n}\n\n/**\n * Returns the timezone string for the given date. E.g. '+8', '-3.5'.\n * Returns 'Z' for UTC.\n *\n * @param dt Specify a date object or default to the current date/time.\n */\nexport function tzShort(dt = new Date()): string {\n if (dt.getTimezoneOffset() === 0) {\n return \"Z\";\n }\n\n const tzHours = dt.getTimezoneOffset() / 60;\n return tzHours >= 0 ? \"+\" + tzHours : String(tzHours);\n}\n\n/**\n * Returns the long month name, zero-indexed. E.g. 0 for 'January'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2024, month, 15).toLocaleString(locales, {\n month: \"long\",\n });\n}\n\n/**\n * Returns the long month name, one-indexed. E.g. 1 for 'January'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getLongMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getLongMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns the short month name, zero-indexed. E.g. 0 for 'Jan'.\n *\n * @param month Zero-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameZeroIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return new Date(2000, month, 15).toLocaleString(locales, {\n month: \"short\",\n });\n}\n\n/**\n * Returns the short month name, one-indexed. E.g. 1 for 'Jan'.\n *\n * @param month One-indexed month.\n * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale(\"en-US\").\n */\nexport function getShortMonthNameOneIndexed(\n month: number,\n locales: Intl.LocalesArgument = \"default\",\n): string {\n return getShortMonthNameZeroIndexed(month - 1, locales);\n}\n\n/**\n * Returns a human-readable string date/time like '2025-01-01 22:31:16Z'.\n * Excludes the milliseconds assuming it is not necessary for display.\n */\nexport function getDisplayDateTime(ts: AnyDateTime) {\n const iso = toDate(ts).toISOString();\n const noMs = iso.slice(0, 19) + \"Z\";\n return noMs.replace(\"T\", \" \");\n}\n"],"mappings":"AAEA,SAASA,EAAYC,EAAsB,CACzC,MAAO,QAAQ,KAAKA,CAAG,CACzB,CAOO,SAASC,EAAOC,EAAuB,CAC5C,OAAI,OAAOA,GAAO,SAEZA,EAAK,KACA,IAAI,KAAKA,EAAK,GAAI,EAIpB,IAAI,KAAKA,CAAE,EAGhB,OAAOA,GAAO,SACZH,EAAYG,CAAE,EACTD,EAAO,OAAOC,CAAE,CAAC,EAGnB,IAAI,KAAKA,CAAE,EAGbA,CACT,CAQO,SAASC,EAAOC,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC/D,IAAMC,EAAKF,EAAG,YAAY,EACpBG,EAAMH,EAAG,SAAS,EAAI,EAE5B,OAAOE,EAAKD,GAAaE,EAAM,GAAK,IAAMA,EAAMA,EAClD,CAQO,SAASC,EAASJ,EAAK,IAAI,KAAQC,EAAY,IAAa,CACjE,IAAMI,EAAML,EAAG,QAAQ,EAEvB,OAAOD,EAAOC,EAAIC,CAAS,EAAIA,GAAaI,EAAM,GAAK,IAAMA,EAAMA,EACrE,CAQO,SAASC,EAAKN,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC7D,IAAMM,EAAKP,EAAG,SAAS,EACjBQ,EAAMR,EAAG,WAAW,EAE1B,OAAQO,EAAK,GAAK,IAAMA,EAAKA,GAAMN,GAAaO,EAAM,GAAK,IAAMA,EAAMA,EACzE,CAQO,SAASC,EAAOT,EAAK,IAAI,KAAQC,EAAY,IAAa,CAC/D,IAAMS,EAAMV,EAAG,WAAW,EAE1B,OAAOM,EAAKN,EAAIC,CAAS,EAAIA,GAAaS,EAAM,GAAK,IAAMA,EAAMA,EACnE,CASO,SAASC,EACdX,EAAK,IAAI,KACTY,EAAgB,IAChBC,EAAc,IACN,CACR,IAAMC,EAAKd,EAAG,gBAAgB,EAE9B,OACES,EAAOT,EAAIY,CAAa,EACxBC,GACCC,EAAK,GAAK,KAAOA,EAAKA,EAAK,IAAM,IAAMA,EAAKA,EAEjD,CAQO,SAASC,EAAQf,EAAK,IAAI,KAAgB,CAC/C,GAAIA,EAAG,kBAAkB,IAAM,EAC7B,MAAO,IAGT,IAAMgB,EAAUhB,EAAG,kBAAkB,EAAI,GACzC,OAAOgB,GAAW,EAAI,IAAMA,EAAU,OAAOA,CAAO,CACtD,CAQO,SAASC,EACdC,EACAC,EAAgC,UACxB,CACR,OAAO,IAAI,KAAK,KAAMD,EAAO,EAAE,EAAE,eAAeC,EAAS,CACvD,MAAO,MACT,CAAC,CACH,CAQO,SAASC,EACdF,EACAC,EAAgC,UACxB,CACR,OAAOF,EAA4BC,EAAQ,EAAGC,CAAO,CACvD,CAQO,SAASE,EACdH,EACAC,EAAgC,UACxB,CACR,OAAO,IAAI,KAAK,IAAMD,EAAO,EAAE,EAAE,eAAeC,EAAS,CACvD,MAAO,OACT,CAAC,CACH,CAQO,SAASG,EACdJ,EACAC,EAAgC,UACxB,CACR,OAAOE,EAA6BH,EAAQ,EAAGC,CAAO,CACxD,CAMO,SAASI,EAAmBzB,EAAiB,CAGlD,OAFYD,EAAOC,CAAE,EAAE,YAAY,EAClB,MAAM,EAAG,EAAE,EAAI,KACpB,QAAQ,IAAK,GAAG,CAC9B","names":["isAllDigits","str","toDate","ts","yyyyMm","dt","separator","yr","mth","yyyyMmDd","day","hhMm","hr","min","hhMmSs","sec","hhMmSsMs","timeSeparator","msSeparator","ms","tzShort","tzHours","getLongMonthNameZeroIndexed","month","locales","getLongMonthNameOneIndexed","getShortMonthNameZeroIndexed","getShortMonthNameOneIndexed","getDisplayDateTime"]}
@@ -0,0 +1,83 @@
1
+ // src/dateTimeStr.ts
2
+ function isAllDigits(str) {
3
+ return /^\d+$/.test(str);
4
+ }
5
+ function toDate(ts) {
6
+ if (typeof ts === "number") {
7
+ if (ts < 1e11) {
8
+ return new Date(ts * 1e3);
9
+ }
10
+ return new Date(ts);
11
+ }
12
+ if (typeof ts === "string") {
13
+ if (isAllDigits(ts)) {
14
+ return toDate(Number(ts));
15
+ }
16
+ return new Date(ts);
17
+ }
18
+ return ts;
19
+ }
20
+ function yyyyMm(dt = /* @__PURE__ */ new Date(), separator = "-") {
21
+ const yr = dt.getFullYear();
22
+ const mth = dt.getMonth() + 1;
23
+ return yr + separator + (mth < 10 ? "0" + mth : mth);
24
+ }
25
+ function yyyyMmDd(dt = /* @__PURE__ */ new Date(), separator = "-") {
26
+ const day = dt.getDate();
27
+ return yyyyMm(dt, separator) + separator + (day < 10 ? "0" + day : day);
28
+ }
29
+ function hhMm(dt = /* @__PURE__ */ new Date(), separator = ":") {
30
+ const hr = dt.getHours();
31
+ const min = dt.getMinutes();
32
+ return (hr < 10 ? "0" + hr : hr) + separator + (min < 10 ? "0" + min : min);
33
+ }
34
+ function hhMmSs(dt = /* @__PURE__ */ new Date(), separator = ":") {
35
+ const sec = dt.getSeconds();
36
+ return hhMm(dt, separator) + separator + (sec < 10 ? "0" + sec : sec);
37
+ }
38
+ function hhMmSsMs(dt = /* @__PURE__ */ new Date(), timeSeparator = ":", msSeparator = ".") {
39
+ const ms = dt.getMilliseconds();
40
+ return hhMmSs(dt, timeSeparator) + msSeparator + (ms < 10 ? "00" + ms : ms < 100 ? "0" + ms : ms);
41
+ }
42
+ function tzShort(dt = /* @__PURE__ */ new Date()) {
43
+ if (dt.getTimezoneOffset() === 0) {
44
+ return "Z";
45
+ }
46
+ const tzHours = dt.getTimezoneOffset() / 60;
47
+ return tzHours >= 0 ? "+" + tzHours : String(tzHours);
48
+ }
49
+ function getLongMonthNameZeroIndexed(month, locales = "default") {
50
+ return new Date(2024, month, 15).toLocaleString(locales, {
51
+ month: "long"
52
+ });
53
+ }
54
+ function getLongMonthNameOneIndexed(month, locales = "default") {
55
+ return getLongMonthNameZeroIndexed(month - 1, locales);
56
+ }
57
+ function getShortMonthNameZeroIndexed(month, locales = "default") {
58
+ return new Date(2e3, month, 15).toLocaleString(locales, {
59
+ month: "short"
60
+ });
61
+ }
62
+ function getShortMonthNameOneIndexed(month, locales = "default") {
63
+ return getShortMonthNameZeroIndexed(month - 1, locales);
64
+ }
65
+ function getDisplayDateTime(ts) {
66
+ const iso = toDate(ts).toISOString();
67
+ const noMs = iso.slice(0, 19) + "Z";
68
+ return noMs.replace("T", " ");
69
+ }
70
+ export {
71
+ getDisplayDateTime,
72
+ getLongMonthNameOneIndexed,
73
+ getLongMonthNameZeroIndexed,
74
+ getShortMonthNameOneIndexed,
75
+ getShortMonthNameZeroIndexed,
76
+ hhMm,
77
+ hhMmSs,
78
+ hhMmSsMs,
79
+ toDate,
80
+ tzShort,
81
+ yyyyMm,
82
+ yyyyMmDd
83
+ };
@@ -96,7 +96,7 @@ function getDurationTypeSeparator(style) {
96
96
  }
97
97
  function msToDuration(ms, durationTypeForZero) {
98
98
  if (ms === 0) {
99
- durationTypeForZero = durationTypeForZero != null ? durationTypeForZero : "milliseconds";
99
+ durationTypeForZero = durationTypeForZero ?? "milliseconds";
100
100
  return { [durationTypeForZero]: 0 };
101
101
  }
102
102
  const duration = {};
@@ -137,19 +137,18 @@ function msToDuration(ms, durationTypeForZero) {
137
137
  return duration;
138
138
  }
139
139
  function durationToMs(duration) {
140
- var _a, _b, _c, _d, _e;
141
- const daysMs = ((_a = duration.days) != null ? _a : 0) * MS_PER_DAY;
142
- const hoursMs = ((_b = duration.hours) != null ? _b : 0) * MS_PER_HOUR;
143
- const minsMs = ((_c = duration.minutes) != null ? _c : 0) * MS_PER_MINUTE;
144
- const secsMs = ((_d = duration.seconds) != null ? _d : 0) * MS_PER_SECOND;
145
- const msMs = (_e = duration.milliseconds) != null ? _e : 0;
140
+ const daysMs = (duration.days ?? 0) * MS_PER_DAY;
141
+ const hoursMs = (duration.hours ?? 0) * MS_PER_HOUR;
142
+ const minsMs = (duration.minutes ?? 0) * MS_PER_MINUTE;
143
+ const secsMs = (duration.seconds ?? 0) * MS_PER_SECOND;
144
+ const msMs = duration.milliseconds ?? 0;
146
145
  return daysMs + hoursMs + minsMs + secsMs + msMs;
147
146
  }
148
147
  function durationOrMsToMs(duration) {
149
148
  return typeof duration === "number" ? duration : durationToMs(duration);
150
149
  }
151
150
  function formatDuration(duration, style) {
152
- style = style != null ? style : "short";
151
+ style = style ?? "short";
153
152
  const stylePlural = getDurationStyleForPlural(style);
154
153
  const space = getValueAndUnitSeparator(style);
155
154
  const a = [];
@@ -164,8 +163,8 @@ function formatDuration(duration, style) {
164
163
  return a.join(separator);
165
164
  }
166
165
  function readableDuration(ms, options) {
167
- const duration = msToDuration(ms, options == null ? void 0 : options.durationTypeForZero);
168
- return formatDuration(duration, options == null ? void 0 : options.style);
166
+ const duration = msToDuration(ms, options?.durationTypeForZero);
167
+ return formatDuration(duration, options?.style);
169
168
  }
170
169
  function elapsed(ms) {
171
170
  if (ms > MS_PER_MINUTE) {
@@ -187,4 +186,3 @@ function elapsed(ms) {
187
186
  msToDuration,
188
187
  readableDuration
189
188
  });
190
- //# sourceMappingURL=duration.js.map