@choksheak/ts-utils 0.2.9 → 0.3.1

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 (315) 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.d.ts +4 -2
  5. package/arrayBuffer.min.cjs +2 -0
  6. package/arrayBuffer.min.cjs.map +1 -0
  7. package/arrayBuffer.min.mjs +2 -0
  8. package/{arrayBuffer.js.map → arrayBuffer.min.mjs.map} +1 -1
  9. package/arrayBuffer.mjs +14 -0
  10. package/{assert.js → assert.cjs} +0 -1
  11. package/assert.d.mts +7 -0
  12. package/assert.d.ts +3 -1
  13. package/assert.min.cjs +2 -0
  14. package/assert.min.cjs.map +1 -0
  15. package/assert.min.mjs +2 -0
  16. package/{assert.js.map → assert.min.mjs.map} +1 -1
  17. package/assert.mjs +11 -0
  18. package/{average.js → average.cjs} +0 -1
  19. package/average.d.mts +7 -0
  20. package/average.d.ts +3 -1
  21. package/average.min.cjs +2 -0
  22. package/{average.js.map → average.min.cjs.map} +1 -1
  23. package/average.min.mjs +2 -0
  24. package/average.min.mjs.map +1 -0
  25. package/average.mjs +20 -0
  26. package/{base64Url.js → base64Url.cjs} +0 -1
  27. package/base64Url.d.mts +10 -0
  28. package/base64Url.d.ts +4 -2
  29. package/base64Url.min.cjs +2 -0
  30. package/base64Url.min.cjs.map +1 -0
  31. package/base64Url.min.mjs +2 -0
  32. package/{base64Url.js.map → base64Url.min.mjs.map} +1 -1
  33. package/base64Url.mjs +14 -0
  34. package/{dateTimeStr.js → dateTimeStr.cjs} +0 -1
  35. package/dateTimeStr.d.mts +85 -0
  36. package/dateTimeStr.d.ts +15 -13
  37. package/dateTimeStr.min.cjs +2 -0
  38. package/dateTimeStr.min.cjs.map +1 -0
  39. package/dateTimeStr.min.mjs +2 -0
  40. package/{dateTimeStr.js.map → dateTimeStr.min.mjs.map} +1 -1
  41. package/dateTimeStr.mjs +83 -0
  42. package/{duration.js → duration.cjs} +9 -11
  43. package/duration.d.mts +78 -0
  44. package/duration.d.ts +15 -13
  45. package/duration.min.cjs +2 -0
  46. package/duration.min.cjs.map +1 -0
  47. package/duration.min.mjs +2 -0
  48. package/duration.min.mjs.map +1 -0
  49. package/duration.mjs +154 -0
  50. package/{isEmpty.js → isEmpty.cjs} +0 -1
  51. package/isEmpty.d.mts +6 -0
  52. package/isEmpty.d.ts +3 -1
  53. package/isEmpty.min.cjs +2 -0
  54. package/isEmpty.min.cjs.map +1 -0
  55. package/isEmpty.min.mjs +2 -0
  56. package/{isEmpty.js.map → isEmpty.min.mjs.map} +1 -1
  57. package/isEmpty.mjs +22 -0
  58. package/iterators.cjs +34 -0
  59. package/iterators.d.mts +4 -0
  60. package/iterators.d.ts +4 -0
  61. package/iterators.min.cjs +2 -0
  62. package/iterators.min.cjs.map +1 -0
  63. package/iterators.min.mjs +2 -0
  64. package/iterators.min.mjs.map +1 -0
  65. package/iterators.mjs +9 -0
  66. package/kvStore.cjs +365 -0
  67. package/kvStore.d.mts +139 -0
  68. package/kvStore.d.ts +95 -50
  69. package/kvStore.min.cjs +2 -0
  70. package/kvStore.min.cjs.map +1 -0
  71. package/kvStore.min.mjs +2 -0
  72. package/kvStore.min.mjs.map +1 -0
  73. package/kvStore.mjs +333 -0
  74. package/localStore.cjs +267 -0
  75. package/localStore.d.mts +119 -0
  76. package/localStore.d.ts +119 -0
  77. package/localStore.min.cjs +2 -0
  78. package/localStore.min.cjs.map +1 -0
  79. package/localStore.min.mjs +2 -0
  80. package/localStore.min.mjs.map +1 -0
  81. package/localStore.mjs +235 -0
  82. package/{logging.js → logging.cjs} +0 -1
  83. package/logging.d.mts +4 -0
  84. package/logging.d.ts +4 -2
  85. package/logging.min.cjs +2 -0
  86. package/logging.min.cjs.map +1 -0
  87. package/logging.min.mjs +2 -0
  88. package/{logging.js.map → logging.min.mjs.map} +1 -1
  89. package/logging.mjs +21 -0
  90. package/{nonEmpty.js → nonEmpty.cjs} +0 -1
  91. package/nonEmpty.d.mts +10 -0
  92. package/nonEmpty.d.ts +3 -1
  93. package/nonEmpty.min.cjs +2 -0
  94. package/{nonEmpty.js.map → nonEmpty.min.cjs.map} +1 -1
  95. package/nonEmpty.min.mjs +2 -0
  96. package/nonEmpty.min.mjs.map +1 -0
  97. package/nonEmpty.mjs +30 -0
  98. package/{nonNil.js → nonNil.cjs} +0 -1
  99. package/{src/nonNil.ts → nonNil.d.mts} +3 -6
  100. package/nonNil.d.ts +3 -1
  101. package/nonNil.min.cjs +2 -0
  102. package/nonNil.min.cjs.map +1 -0
  103. package/nonNil.min.mjs +2 -0
  104. package/{nonNil.js.map → nonNil.min.mjs.map} +1 -1
  105. package/nonNil.mjs +10 -0
  106. package/package.json +447 -24
  107. package/{round.js → round.cjs} +0 -1
  108. package/{src/round.ts → round.d.mts} +4 -8
  109. package/round.d.ts +4 -2
  110. package/round.min.cjs +2 -0
  111. package/round.min.cjs.map +1 -0
  112. package/round.min.mjs +2 -0
  113. package/{round.js.map → round.min.mjs.map} +1 -1
  114. package/round.mjs +12 -0
  115. package/{safeBtoa.js → safeBtoa.cjs} +0 -1
  116. package/safeBtoa.d.mts +6 -0
  117. package/safeBtoa.d.ts +3 -1
  118. package/safeBtoa.min.cjs +2 -0
  119. package/safeBtoa.min.cjs.map +1 -0
  120. package/safeBtoa.min.mjs +2 -0
  121. package/{safeBtoa.js.map → safeBtoa.min.mjs.map} +1 -1
  122. package/safeBtoa.mjs +9 -0
  123. package/{safeParseFloat.js → safeParseFloat.cjs} +0 -1
  124. package/safeParseFloat.d.mts +6 -0
  125. package/safeParseFloat.d.ts +3 -1
  126. package/safeParseFloat.min.cjs +2 -0
  127. package/safeParseFloat.min.cjs.map +1 -0
  128. package/safeParseFloat.min.mjs +2 -0
  129. package/{safeParseFloat.js.map → safeParseFloat.min.mjs.map} +1 -1
  130. package/safeParseFloat.mjs +8 -0
  131. package/{safeParseInt.js → safeParseInt.cjs} +0 -1
  132. package/safeParseInt.d.mts +6 -0
  133. package/safeParseInt.d.ts +3 -1
  134. package/safeParseInt.min.cjs +2 -0
  135. package/safeParseInt.min.cjs.map +1 -0
  136. package/safeParseInt.min.mjs +2 -0
  137. package/{safeParseInt.js.map → safeParseInt.min.mjs.map} +1 -1
  138. package/safeParseInt.mjs +8 -0
  139. package/sha256.cjs +35 -0
  140. package/sha256.d.mts +6 -0
  141. package/sha256.d.ts +3 -1
  142. package/sha256.min.cjs +2 -0
  143. package/sha256.min.cjs.map +1 -0
  144. package/sha256.min.mjs +2 -0
  145. package/{sha256.js.map → sha256.min.mjs.map} +1 -1
  146. package/sha256.mjs +10 -0
  147. package/{sleep.js → sleep.cjs} +0 -1
  148. package/{src/sleep.ts → sleep.d.mts} +3 -3
  149. package/sleep.d.ts +3 -1
  150. package/sleep.min.cjs +2 -0
  151. package/sleep.min.cjs.map +1 -0
  152. package/sleep.min.mjs +2 -0
  153. package/{sleep.js.map → sleep.min.mjs.map} +1 -1
  154. package/sleep.mjs +7 -0
  155. package/storageAdapter.cjs +18 -0
  156. package/storageAdapter.d.mts +33 -0
  157. package/storageAdapter.d.ts +33 -0
  158. package/storageAdapter.min.cjs +2 -0
  159. package/storageAdapter.min.cjs.map +1 -0
  160. package/storageAdapter.min.mjs +1 -0
  161. package/storageAdapter.min.mjs.map +1 -0
  162. package/storageAdapter.mjs +0 -0
  163. package/{sum.js → sum.cjs} +0 -1
  164. package/sum.d.mts +7 -0
  165. package/sum.d.ts +3 -1
  166. package/sum.min.cjs +2 -0
  167. package/sum.min.cjs.map +1 -0
  168. package/sum.min.mjs +2 -0
  169. package/{sum.js.map → sum.min.mjs.map} +1 -1
  170. package/sum.mjs +13 -0
  171. package/{timeConstants.js → timeConstants.cjs} +0 -1
  172. package/timeConstants.d.mts +20 -0
  173. package/timeConstants.d.ts +16 -14
  174. package/timeConstants.min.cjs +2 -0
  175. package/timeConstants.min.cjs.map +1 -0
  176. package/timeConstants.min.mjs +2 -0
  177. package/{timeConstants.js.map → timeConstants.min.mjs.map} +1 -1
  178. package/timeConstants.mjs +31 -0
  179. package/{timer.js → timer.cjs} +6 -6
  180. package/timer.d.mts +13 -0
  181. package/timer.d.ts +4 -2
  182. package/timer.min.cjs +2 -0
  183. package/timer.min.cjs.map +1 -0
  184. package/timer.min.mjs +2 -0
  185. package/timer.min.mjs.map +1 -0
  186. package/timer.mjs +161 -0
  187. package/docs/.nojekyll +0 -1
  188. package/docs/assets/hierarchy.js +0 -1
  189. package/docs/assets/highlight.css +0 -22
  190. package/docs/assets/icons.js +0 -18
  191. package/docs/assets/icons.svg +0 -1
  192. package/docs/assets/main.js +0 -60
  193. package/docs/assets/navigation.js +0 -1
  194. package/docs/assets/search.js +0 -1
  195. package/docs/assets/style.css +0 -1640
  196. package/docs/classes/kvStore.KVStore.html +0 -26
  197. package/docs/classes/kvStore.KVStoreField.html +0 -7
  198. package/docs/classes/timer.Timer.html +0 -8
  199. package/docs/functions/arrayBuffer.arrayBufferToBase64.html +0 -2
  200. package/docs/functions/arrayBuffer.arrayBufferToHex.html +0 -2
  201. package/docs/functions/assert.assert.html +0 -3
  202. package/docs/functions/average.average.html +0 -3
  203. package/docs/functions/base64Url.base64ToBase64URL.html +0 -2
  204. package/docs/functions/base64Url.base64UrlToBase64.html +0 -2
  205. package/docs/functions/dateTimeStr.getDisplayDateTime.html +0 -3
  206. package/docs/functions/dateTimeStr.getLongMonthNameOneIndexed.html +0 -4
  207. package/docs/functions/dateTimeStr.getLongMonthNameZeroIndexed.html +0 -4
  208. package/docs/functions/dateTimeStr.getShortMonthNameOneIndexed.html +0 -4
  209. package/docs/functions/dateTimeStr.getShortMonthNameZeroIndexed.html +0 -4
  210. package/docs/functions/dateTimeStr.hhMm.html +0 -4
  211. package/docs/functions/dateTimeStr.hhMmSs.html +0 -4
  212. package/docs/functions/dateTimeStr.hhMmSsMs.html +0 -5
  213. package/docs/functions/dateTimeStr.toDate.html +0 -4
  214. package/docs/functions/dateTimeStr.tzShort.html +0 -4
  215. package/docs/functions/dateTimeStr.yyyyMm.html +0 -4
  216. package/docs/functions/dateTimeStr.yyyyMmDd.html +0 -4
  217. package/docs/functions/duration.durationOrMsToMs.html +0 -2
  218. package/docs/functions/duration.durationToMs.html +0 -2
  219. package/docs/functions/duration.elapsed.html +0 -2
  220. package/docs/functions/duration.formatDuration.html +0 -4
  221. package/docs/functions/duration.msToDuration.html +0 -5
  222. package/docs/functions/duration.readableDuration.html +0 -4
  223. package/docs/functions/isEmpty.isEmpty.html +0 -2
  224. package/docs/functions/kvStore.kvStoreItem.html +0 -2
  225. package/docs/functions/localStorageCache.storeItem.html +0 -15
  226. package/docs/functions/logging.capLength.html +0 -1
  227. package/docs/functions/logging.stringify.html +0 -1
  228. package/docs/functions/nonEmpty.nonEmpty.html +0 -5
  229. package/docs/functions/nonNil.nonNil.html +0 -5
  230. package/docs/functions/round.round.html +0 -5
  231. package/docs/functions/round.roundS.html +0 -3
  232. package/docs/functions/safeBtoa.safeBtoa.html +0 -2
  233. package/docs/functions/safeParseFloat.safeParseFloat.html +0 -2
  234. package/docs/functions/safeParseInt.safeParseInt.html +0 -2
  235. package/docs/functions/sha256.sha256.html +0 -2
  236. package/docs/functions/sleep.sleep.html +0 -3
  237. package/docs/functions/sum.sum.html +0 -3
  238. package/docs/functions/timer.timer.html +0 -2
  239. package/docs/hierarchy.html +0 -1
  240. package/docs/index.html +0 -4
  241. package/docs/modules/arrayBuffer.html +0 -1
  242. package/docs/modules/assert.html +0 -1
  243. package/docs/modules/average.html +0 -1
  244. package/docs/modules/base64Url.html +0 -1
  245. package/docs/modules/dateTimeStr.html +0 -1
  246. package/docs/modules/duration.html +0 -1
  247. package/docs/modules/isEmpty.html +0 -1
  248. package/docs/modules/kvStore.html +0 -1
  249. package/docs/modules/localStorageCache.html +0 -1
  250. package/docs/modules/logging.html +0 -1
  251. package/docs/modules/nonEmpty.html +0 -1
  252. package/docs/modules/nonNil.html +0 -1
  253. package/docs/modules/round.html +0 -1
  254. package/docs/modules/safeBtoa.html +0 -1
  255. package/docs/modules/safeParseFloat.html +0 -1
  256. package/docs/modules/safeParseInt.html +0 -1
  257. package/docs/modules/sha256.html +0 -1
  258. package/docs/modules/sleep.html +0 -1
  259. package/docs/modules/sum.html +0 -1
  260. package/docs/modules/timeConstants.html +0 -1
  261. package/docs/modules/timer.html +0 -1
  262. package/docs/modules.html +0 -1
  263. package/docs/types/dateTimeStr.AnyDateTime.html +0 -1
  264. package/docs/types/duration.Duration.html +0 -6
  265. package/docs/types/duration.DurationStyle.html +0 -6
  266. package/docs/types/duration.DurationSuffixMap.html +0 -6
  267. package/docs/types/duration.DurationSuffixType.html +0 -1
  268. package/docs/types/duration.DurationType.html +0 -2
  269. package/docs/types/localStorageCache.StoredItem.html +0 -4
  270. package/docs/variables/duration.DURATION_STYLE_SUFFIX_MAP.html +0 -1
  271. package/docs/variables/duration.DURATION_TYPE_SEQUENCE.html +0 -2
  272. package/docs/variables/kvStore.DEFAULT_EXPIRY_DELTA_MS.html +0 -2
  273. package/docs/variables/kvStore.GC_INTERVAL_MS.html +0 -2
  274. package/docs/variables/kvStore.MILLIS_PER_DAY.html +0 -2
  275. package/docs/variables/kvStore.kvStore.html +0 -3
  276. package/docs/variables/timeConstants.HOURS_PER_DAY.html +0 -1
  277. package/docs/variables/timeConstants.HOURS_PER_WEEK.html +0 -1
  278. package/docs/variables/timeConstants.MINUTES_PER_DAY.html +0 -1
  279. package/docs/variables/timeConstants.MINUTES_PER_HOUR.html +0 -1
  280. package/docs/variables/timeConstants.MINUTES_PER_WEEK.html +0 -1
  281. package/docs/variables/timeConstants.MS_PER_DAY.html +0 -1
  282. package/docs/variables/timeConstants.MS_PER_HOUR.html +0 -1
  283. package/docs/variables/timeConstants.MS_PER_MINUTE.html +0 -1
  284. package/docs/variables/timeConstants.MS_PER_SECOND.html +0 -3
  285. package/docs/variables/timeConstants.MS_PER_WEEK.html +0 -1
  286. package/docs/variables/timeConstants.SECONDS_PER_DAY.html +0 -1
  287. package/docs/variables/timeConstants.SECONDS_PER_HOUR.html +0 -1
  288. package/docs/variables/timeConstants.SECONDS_PER_MINUTE.html +0 -1
  289. package/docs/variables/timeConstants.SECONDS_PER_WEEK.html +0 -1
  290. package/duration.js.map +0 -1
  291. package/kvStore.js +0 -383
  292. package/kvStore.js.map +0 -1
  293. package/localStorageCache.d.ts +0 -55
  294. package/localStorageCache.js +0 -121
  295. package/localStorageCache.js.map +0 -1
  296. package/sha256.js +0 -58
  297. package/src/arrayBuffer.ts +0 -29
  298. package/src/assert.ts +0 -14
  299. package/src/average.ts +0 -13
  300. package/src/base64Url.ts +0 -20
  301. package/src/dateTimeStr.ts +0 -184
  302. package/src/duration.ts +0 -260
  303. package/src/isEmpty.ts +0 -32
  304. package/src/kvStore.ts +0 -444
  305. package/src/localStorageCache.ts +0 -121
  306. package/src/logging.ts +0 -26
  307. package/src/nonEmpty.ts +0 -18
  308. package/src/safeBtoa.ts +0 -15
  309. package/src/safeParseFloat.ts +0 -10
  310. package/src/safeParseInt.ts +0 -10
  311. package/src/sha256.ts +0 -13
  312. package/src/sum.ts +0 -17
  313. package/src/timeConstants.ts +0 -22
  314. package/src/timer.ts +0 -33
  315. 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 };
package/arrayBuffer.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * Encode an input ArrayBuffer into a hex string.
3
3
  */
4
- export declare function arrayBufferToHex(buffer: ArrayBuffer): string;
4
+ declare function arrayBufferToHex(buffer: ArrayBuffer): string;
5
5
  /**
6
6
  * Encode an input ArrayBuffer into a base64 string.
7
7
  */
8
- export declare function arrayBufferToBase64(buffer: ArrayBuffer): string;
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.d.ts CHANGED
@@ -2,4 +2,6 @@
2
2
  * Type asserts that `t` is truthy. Throws an error with `errorMessage` if
3
3
  * `t` is falsy.
4
4
  */
5
- export declare function assert<T>(t: T | null | undefined | "" | 0 | -0 | 0n | false | typeof NaN, errorMessage?: string): asserts t is T;
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 };
package/average.d.ts CHANGED
@@ -2,4 +2,6 @@
2
2
  * Average all the numbers together in the given array. Treats null, undefined
3
3
  * and NaN as zero.
4
4
  */
5
- export declare function average(numbers: (number | null | undefined)[]): number;
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 };
package/base64Url.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * Convert a base64 string to a base64url string.
3
3
  */
4
- export declare function base64ToBase64URL(base64: string): string;
4
+ declare function base64ToBase64URL(base64: string): string;
5
5
  /**
6
6
  * Convert a base64url string to a base64 string.
7
7
  */
8
- export declare function base64UrlToBase64(base64Url: string): string;
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 };
package/dateTimeStr.d.ts CHANGED
@@ -1,38 +1,38 @@
1
- export type AnyDateTime = number | Date | string;
1
+ type AnyDateTime = number | Date | string;
2
2
  /**
3
3
  * Convert a number (epoch seconds or milliseconds), string (parseable
4
4
  * date/time or epoch seconds or milliseconds), or Date object (no conversion)
5
5
  * into a Date object.
6
6
  */
7
- export declare function toDate(ts: AnyDateTime): Date;
7
+ declare function toDate(ts: AnyDateTime): Date;
8
8
  /**
9
9
  * Returns a date in yyyy-MM format. E.g. '2000-01'.
10
10
  *
11
11
  * @param dt Specify a date object or default to the current date.
12
12
  * @param separator Defaults to '-'.
13
13
  */
14
- export declare function yyyyMm(dt?: Date, separator?: string): string;
14
+ declare function yyyyMm(dt?: Date, separator?: string): string;
15
15
  /**
16
16
  * Returns a date in yyyy-MM-dd format. E.g. '2000-01-02'.
17
17
  *
18
18
  * @param dt Specify a date object or default to the current date.
19
19
  * @param separator Defaults to '-'.
20
20
  */
21
- export declare function yyyyMmDd(dt?: Date, separator?: string): string;
21
+ declare function yyyyMmDd(dt?: Date, separator?: string): string;
22
22
  /**
23
23
  * Returns a date in hh:mm format. E.g. '01:02'.
24
24
  *
25
25
  * @param dt Specify a date object or default to the current date/time.
26
26
  * @param separator Defaults to ':'.
27
27
  */
28
- export declare function hhMm(dt?: Date, separator?: string): string;
28
+ declare function hhMm(dt?: Date, separator?: string): string;
29
29
  /**
30
30
  * Returns a date in hh:mm:ss format. E.g. '01:02:03'.
31
31
  *
32
32
  * @param dt Specify a date object or default to the current date/time.
33
33
  * @param separator Defaults to ':'.
34
34
  */
35
- export declare function hhMmSs(dt?: Date, separator?: string): string;
35
+ declare function hhMmSs(dt?: Date, separator?: string): string;
36
36
  /**
37
37
  * Returns a date in hh:mm:ss.SSS format. E.g. '01:02:03.004'.
38
38
  *
@@ -40,44 +40,46 @@ export declare function hhMmSs(dt?: Date, separator?: string): string;
40
40
  * @param timeSeparator Separator for hh/mm/ss. Defaults to ':'.
41
41
  * @param msSeparator Separator before SSS. Defaults to '.'.
42
42
  */
43
- export declare function hhMmSsMs(dt?: Date, timeSeparator?: string, msSeparator?: string): string;
43
+ declare function hhMmSsMs(dt?: Date, timeSeparator?: string, msSeparator?: string): string;
44
44
  /**
45
45
  * Returns the timezone string for the given date. E.g. '+8', '-3.5'.
46
46
  * Returns 'Z' for UTC.
47
47
  *
48
48
  * @param dt Specify a date object or default to the current date/time.
49
49
  */
50
- export declare function tzShort(dt?: Date): string;
50
+ declare function tzShort(dt?: Date): string;
51
51
  /**
52
52
  * Returns the long month name, zero-indexed. E.g. 0 for 'January'.
53
53
  *
54
54
  * @param month Zero-indexed month.
55
55
  * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
56
56
  */
57
- export declare function getLongMonthNameZeroIndexed(month: number, locales?: Intl.LocalesArgument): string;
57
+ declare function getLongMonthNameZeroIndexed(month: number, locales?: Intl.LocalesArgument): string;
58
58
  /**
59
59
  * Returns the long month name, one-indexed. E.g. 1 for 'January'.
60
60
  *
61
61
  * @param month One-indexed month.
62
62
  * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
63
63
  */
64
- export declare function getLongMonthNameOneIndexed(month: number, locales?: Intl.LocalesArgument): string;
64
+ declare function getLongMonthNameOneIndexed(month: number, locales?: Intl.LocalesArgument): string;
65
65
  /**
66
66
  * Returns the short month name, zero-indexed. E.g. 0 for 'Jan'.
67
67
  *
68
68
  * @param month Zero-indexed month.
69
69
  * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
70
70
  */
71
- export declare function getShortMonthNameZeroIndexed(month: number, locales?: Intl.LocalesArgument): string;
71
+ declare function getShortMonthNameZeroIndexed(month: number, locales?: Intl.LocalesArgument): string;
72
72
  /**
73
73
  * Returns the short month name, one-indexed. E.g. 1 for 'Jan'.
74
74
  *
75
75
  * @param month One-indexed month.
76
76
  * @param locales Specify the locale, e.g. 'en-US', new Intl.Locale("en-US").
77
77
  */
78
- export declare function getShortMonthNameOneIndexed(month: number, locales?: Intl.LocalesArgument): string;
78
+ declare function getShortMonthNameOneIndexed(month: number, locales?: Intl.LocalesArgument): string;
79
79
  /**
80
80
  * Returns a human-readable string date/time like '2025-01-01 22:31:16Z'.
81
81
  * Excludes the milliseconds assuming it is not necessary for display.
82
82
  */
83
- export declare function getDisplayDateTime(ts: AnyDateTime): string;
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"]}