@choksheak/ts-utils 0.3.4 → 0.3.6

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 (285) hide show
  1. package/README.md +9 -3
  2. package/arrayBuffer.cjs +10 -39
  3. package/arrayBuffer.min.cjs +1 -1
  4. package/arrayBuffer.min.cjs.map +1 -1
  5. package/arrayBuffer.min.mjs +1 -1
  6. package/arrayBuffer.min.mjs.map +1 -1
  7. package/arrayBuffer.mjs +7 -10
  8. package/asNumber.cjs +6 -38
  9. package/asNumber.d.mts +1 -1
  10. package/asNumber.d.ts +1 -1
  11. package/asNumber.min.cjs +1 -1
  12. package/asNumber.min.cjs.map +1 -1
  13. package/asNumber.min.mjs +1 -1
  14. package/asNumber.min.mjs.map +1 -1
  15. package/asNumber.mjs +4 -11
  16. package/assert.cjs +4 -27
  17. package/assert.min.cjs +1 -1
  18. package/assert.min.cjs.map +1 -1
  19. package/assert.min.mjs +1 -1
  20. package/assert.min.mjs.map +1 -1
  21. package/assert.mjs +2 -0
  22. package/base64Url.cjs +5 -29
  23. package/base64Url.min.cjs +1 -1
  24. package/base64Url.min.cjs.map +1 -1
  25. package/base64Url.min.mjs +1 -1
  26. package/base64Url.min.mjs.map +1 -1
  27. package/base64Url.mjs +2 -0
  28. package/capLength.cjs +7 -71
  29. package/capLength.min.cjs +1 -5
  30. package/capLength.min.cjs.map +1 -1
  31. package/capLength.min.mjs +1 -5
  32. package/capLength.min.mjs.map +1 -1
  33. package/capLength.mjs +4 -41
  34. package/chunk-22JDWCOS.min.cjs +2 -0
  35. package/chunk-22JDWCOS.min.cjs.map +1 -0
  36. package/chunk-244NBT4Q.min.mjs +2 -0
  37. package/chunk-244NBT4Q.min.mjs.map +1 -0
  38. package/chunk-27MBP3ES.min.cjs +2 -0
  39. package/chunk-27MBP3ES.min.cjs.map +1 -0
  40. package/chunk-34ENP2B3.min.mjs +438 -0
  41. package/chunk-34ENP2B3.min.mjs.map +1 -0
  42. package/chunk-3EBQ2GO2.min.cjs +2 -0
  43. package/chunk-3EBQ2GO2.min.cjs.map +1 -0
  44. package/chunk-4GLOLTJ5.cjs +167 -0
  45. package/chunk-6TQBMXTL.min.cjs +2 -0
  46. package/chunk-6TQBMXTL.min.cjs.map +1 -0
  47. package/chunk-AWZBCFMG.min.cjs +2 -0
  48. package/chunk-AWZBCFMG.min.cjs.map +1 -0
  49. package/chunk-AXNETZET.cjs +20 -0
  50. package/chunk-BKZM6NWX.min.cjs +2 -0
  51. package/chunk-BKZM6NWX.min.cjs.map +1 -0
  52. package/chunk-BZKQXX3A.cjs +40 -0
  53. package/chunk-CERFUU5I.cjs +93 -0
  54. package/chunk-CSTKFJ6G.mjs +239 -0
  55. package/chunk-DUN4UY2Q.cjs +239 -0
  56. package/chunk-EDJJUP4K.min.cjs +6 -0
  57. package/chunk-EDJJUP4K.min.cjs.map +1 -0
  58. package/chunk-FFNQBZH5.cjs +14 -0
  59. package/chunk-FZZRSHSH.min.mjs +6 -0
  60. package/chunk-FZZRSHSH.min.mjs.map +1 -0
  61. package/chunk-GAP2HS5M.min.cjs +2 -0
  62. package/chunk-GAP2HS5M.min.cjs.map +1 -0
  63. package/chunk-GLYMAPS4.min.mjs +2 -0
  64. package/chunk-GLYMAPS4.min.mjs.map +1 -0
  65. package/chunk-I65KPVMO.min.cjs +438 -0
  66. package/chunk-I65KPVMO.min.cjs.map +1 -0
  67. package/chunk-ILGTU46T.cjs +39 -0
  68. package/chunk-IOKRXHKE.min.mjs +2 -0
  69. package/chunk-IOKRXHKE.min.mjs.map +1 -0
  70. package/chunk-ISP4SMRC.min.cjs +2 -0
  71. package/chunk-ISP4SMRC.min.cjs.map +1 -0
  72. package/chunk-KETP5HBF.cjs +24 -0
  73. package/chunk-KLHNGJ4Y.min.mjs +2 -0
  74. package/chunk-KLHNGJ4Y.min.mjs.map +1 -0
  75. package/chunk-KMNTU3DJ.mjs +45 -0
  76. package/chunk-LDVEXETI.cjs +45 -0
  77. package/chunk-LZENHV35.min.cjs +2 -0
  78. package/chunk-LZENHV35.min.cjs.map +1 -0
  79. package/chunk-M5PIM2HB.mjs +42 -0
  80. package/chunk-M6PYQYOX.mjs +39 -0
  81. package/chunk-MN5EYNZN.min.mjs +2 -0
  82. package/chunk-MN5EYNZN.min.mjs.map +1 -0
  83. package/chunk-NRIBJ2OJ.mjs +16031 -0
  84. package/chunk-NVLYXWLX.cjs +32 -0
  85. package/chunk-O352F2MT.mjs +24 -0
  86. package/chunk-O6B2TKFK.min.mjs +2 -0
  87. package/chunk-O6B2TKFK.min.mjs.map +1 -0
  88. package/chunk-OGF34H4T.min.cjs +2 -0
  89. package/chunk-OGF34H4T.min.cjs.map +1 -0
  90. package/chunk-OXSWWWOM.min.mjs +2 -0
  91. package/chunk-OXSWWWOM.min.mjs.map +1 -0
  92. package/chunk-PRUGHVRT.mjs +14 -0
  93. package/chunk-Q4WCMSOW.min.mjs +2 -0
  94. package/chunk-Q4WCMSOW.min.mjs.map +1 -0
  95. package/chunk-QH74JZCK.mjs +9 -0
  96. package/chunk-QNNJNLGK.min.cjs +2 -0
  97. package/chunk-QNNJNLGK.min.cjs.map +1 -0
  98. package/chunk-QWCFN7ZM.mjs +15 -0
  99. package/chunk-SDM2OPT6.mjs +32 -0
  100. package/chunk-SHKRZCF2.cjs +16031 -0
  101. package/chunk-SJDJDNDN.min.cjs +2 -0
  102. package/chunk-SJDJDNDN.min.cjs.map +1 -0
  103. package/chunk-SULNMALN.cjs +328 -0
  104. package/chunk-SV35RBZ7.min.mjs +2 -0
  105. package/chunk-SV35RBZ7.min.mjs.map +1 -0
  106. package/chunk-TJFYGFOW.mjs +328 -0
  107. package/chunk-UHRYBUUX.min.mjs +2 -0
  108. package/chunk-UHRYBUUX.min.mjs.map +1 -0
  109. package/chunk-UOU6IP3S.min.mjs +2 -0
  110. package/chunk-UOU6IP3S.min.mjs.map +1 -0
  111. package/chunk-V76XVNZ5.mjs +20 -0
  112. package/chunk-VFYQ7I5V.min.mjs +2 -0
  113. package/chunk-VFYQ7I5V.min.mjs.map +1 -0
  114. package/chunk-VG7VV7J2.mjs +167 -0
  115. package/chunk-VJCV56DO.cjs +15 -0
  116. package/chunk-VREA6AKG.cjs +9 -0
  117. package/chunk-W5I6Y5FK.min.mjs +2 -0
  118. package/chunk-W5I6Y5FK.min.mjs.map +1 -0
  119. package/chunk-Y7MC73BZ.cjs +42 -0
  120. package/chunk-YVWROQKU.mjs +40 -0
  121. package/chunk-ZKIZ5SWK.min.cjs +2 -0
  122. package/chunk-ZKIZ5SWK.min.cjs.map +1 -0
  123. package/chunk-ZZZB7NJX.mjs +93 -0
  124. package/concatIterators.cjs +4 -27
  125. package/concatIterators.min.cjs +1 -1
  126. package/concatIterators.min.cjs.map +1 -1
  127. package/concatIterators.min.mjs +1 -1
  128. package/concatIterators.min.mjs.map +1 -1
  129. package/concatIterators.mjs +2 -0
  130. package/dateTimeStr.cjs +31 -119
  131. package/dateTimeStr.min.cjs +1 -1
  132. package/dateTimeStr.min.cjs.map +1 -1
  133. package/dateTimeStr.min.mjs +1 -1
  134. package/dateTimeStr.min.mjs.map +1 -1
  135. package/dateTimeStr.mjs +17 -69
  136. package/duration.cjs +24 -188
  137. package/duration.min.cjs +1 -1
  138. package/duration.min.cjs.map +1 -1
  139. package/duration.min.mjs +1 -1
  140. package/duration.min.mjs.map +1 -1
  141. package/duration.mjs +14 -144
  142. package/getEnv.cjs +20 -0
  143. package/getEnv.d.mts +11 -0
  144. package/getEnv.d.ts +11 -0
  145. package/getEnv.min.cjs +2 -0
  146. package/getEnv.min.cjs.map +1 -0
  147. package/getEnv.min.mjs +2 -0
  148. package/getEnv.min.mjs.map +1 -0
  149. package/getEnv.mjs +20 -0
  150. package/isEmpty.cjs +8 -46
  151. package/isEmpty.min.cjs +1 -1
  152. package/isEmpty.min.cjs.map +1 -1
  153. package/isEmpty.min.mjs +1 -1
  154. package/isEmpty.min.mjs.map +1 -1
  155. package/isEmpty.mjs +6 -19
  156. package/isPromise.cjs +5 -29
  157. package/isPromise.min.cjs +1 -1
  158. package/isPromise.min.cjs.map +1 -1
  159. package/isPromise.min.mjs +1 -1
  160. package/isPromise.min.mjs.map +1 -1
  161. package/isPromise.mjs +2 -0
  162. package/kvStore.cjs +15 -362
  163. package/kvStore.d.mts +142 -44
  164. package/kvStore.d.ts +142 -44
  165. package/kvStore.min.cjs +1 -1
  166. package/kvStore.min.cjs.map +1 -1
  167. package/kvStore.min.mjs +1 -1
  168. package/kvStore.min.mjs.map +1 -1
  169. package/kvStore.mjs +13 -328
  170. package/localStore.cjs +15 -263
  171. package/localStore.d.mts +135 -34
  172. package/localStore.d.ts +135 -34
  173. package/localStore.min.cjs +1 -1
  174. package/localStore.min.cjs.map +1 -1
  175. package/localStore.min.mjs +1 -1
  176. package/localStore.min.mjs.map +1 -1
  177. package/localStore.mjs +13 -229
  178. package/magic-string.es-4UY437WL.min.mjs +14 -0
  179. package/magic-string.es-4UY437WL.min.mjs.map +1 -0
  180. package/magic-string.es-OAQWZQTY.mjs +1323 -0
  181. package/magic-string.es-UE2UVQEL.cjs +1323 -0
  182. package/magic-string.es-X6DNUB6Y.min.cjs +14 -0
  183. package/magic-string.es-X6DNUB6Y.min.cjs.map +1 -0
  184. package/mean.cjs +8 -48
  185. package/mean.min.cjs +1 -1
  186. package/mean.min.cjs.map +1 -1
  187. package/mean.min.mjs +1 -1
  188. package/mean.min.mjs.map +1 -1
  189. package/mean.mjs +5 -18
  190. package/median.cjs +7 -41
  191. package/median.min.cjs +1 -1
  192. package/median.min.cjs.map +1 -1
  193. package/median.min.mjs +1 -1
  194. package/median.min.mjs.map +1 -1
  195. package/median.mjs +5 -12
  196. package/nonEmpty.cjs +8 -48
  197. package/nonEmpty.min.cjs +1 -1
  198. package/nonEmpty.min.cjs.map +1 -1
  199. package/nonEmpty.min.mjs +1 -1
  200. package/nonEmpty.min.mjs.map +1 -1
  201. package/nonEmpty.mjs +6 -19
  202. package/nonNil.cjs +4 -27
  203. package/nonNil.min.cjs +1 -1
  204. package/nonNil.min.cjs.map +1 -1
  205. package/nonNil.min.mjs +1 -1
  206. package/nonNil.min.mjs.map +1 -1
  207. package/nonNil.mjs +2 -0
  208. package/package.json +274 -34
  209. package/round.cjs +6 -32
  210. package/round.min.cjs +1 -1
  211. package/round.min.cjs.map +1 -1
  212. package/round.min.mjs +1 -1
  213. package/round.min.mjs.map +1 -1
  214. package/round.mjs +4 -5
  215. package/roundToString.cjs +7 -35
  216. package/roundToString.min.cjs +1 -1
  217. package/roundToString.min.cjs.map +1 -1
  218. package/roundToString.min.mjs +1 -1
  219. package/roundToString.min.mjs.map +1 -1
  220. package/roundToString.mjs +4 -5
  221. package/safeBtoa.cjs +4 -27
  222. package/safeBtoa.d.mts +7 -0
  223. package/safeBtoa.d.ts +7 -0
  224. package/safeBtoa.min.cjs +1 -1
  225. package/safeBtoa.min.cjs.map +1 -1
  226. package/safeBtoa.min.mjs +1 -1
  227. package/safeBtoa.min.mjs.map +1 -1
  228. package/safeBtoa.mjs +2 -0
  229. package/sha256.cjs +8 -34
  230. package/sha256.min.cjs +1 -1
  231. package/sha256.min.cjs.map +1 -1
  232. package/sha256.min.mjs +1 -1
  233. package/sha256.min.mjs.map +1 -1
  234. package/sha256.mjs +6 -7
  235. package/sleep.cjs +4 -27
  236. package/sleep.min.cjs +1 -1
  237. package/sleep.min.cjs.map +1 -1
  238. package/sleep.min.mjs +1 -1
  239. package/sleep.min.mjs.map +1 -1
  240. package/sleep.mjs +2 -0
  241. package/storageAdapter.cjs +1 -18
  242. package/storageAdapter.min.cjs +1 -2
  243. package/storageAdapter.min.cjs.map +1 -1
  244. package/sum.cjs +5 -45
  245. package/sum.min.cjs +1 -1
  246. package/sum.min.cjs.map +1 -1
  247. package/sum.min.mjs +1 -1
  248. package/sum.min.mjs.map +1 -1
  249. package/sum.mjs +5 -18
  250. package/timeConstants.cjs +35 -69
  251. package/timeConstants.min.cjs +1 -1
  252. package/timeConstants.min.cjs.map +1 -1
  253. package/timeConstants.min.mjs +1 -1
  254. package/timeConstants.min.mjs.map +1 -1
  255. package/timeConstants.mjs +19 -15
  256. package/timer.cjs +7 -185
  257. package/timer.d.mts +9 -6
  258. package/timer.d.ts +9 -6
  259. package/timer.min.cjs +1 -1
  260. package/timer.min.cjs.map +1 -1
  261. package/timer.min.mjs +1 -1
  262. package/timer.min.mjs.map +1 -1
  263. package/timer.mjs +8 -158
  264. package/toReadableString.cjs +6 -68
  265. package/toReadableString.min.cjs +1 -5
  266. package/toReadableString.min.cjs.map +1 -1
  267. package/toReadableString.min.mjs +1 -5
  268. package/toReadableString.min.mjs.map +1 -1
  269. package/toReadableString.mjs +4 -41
  270. package/safeParseFloat.cjs +0 -33
  271. package/safeParseFloat.d.mts +0 -6
  272. package/safeParseFloat.d.ts +0 -6
  273. package/safeParseFloat.min.cjs +0 -2
  274. package/safeParseFloat.min.cjs.map +0 -1
  275. package/safeParseFloat.min.mjs +0 -2
  276. package/safeParseFloat.min.mjs.map +0 -1
  277. package/safeParseFloat.mjs +0 -8
  278. package/safeParseInt.cjs +0 -33
  279. package/safeParseInt.d.mts +0 -6
  280. package/safeParseInt.d.ts +0 -6
  281. package/safeParseInt.min.cjs +0 -2
  282. package/safeParseInt.min.cjs.map +0 -1
  283. package/safeParseInt.min.mjs +0 -2
  284. package/safeParseInt.min.mjs.map +0 -1
  285. package/safeParseInt.mjs +0 -8
package/isPromise.cjs CHANGED
@@ -1,29 +1,6 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-ILGTU46T.cjs');
19
2
 
20
3
  // src/isPromise.ts
21
- var isPromise_exports = {};
22
- __export(isPromise_exports, {
23
- isNativePromise: () => isNativePromise,
24
- isPromise: () => isPromise
25
- });
26
- module.exports = __toCommonJS(isPromise_exports);
27
4
  function isPromise(obj) {
28
5
  if (!obj || typeof obj !== "object" && typeof obj !== "function") {
29
6
  return false;
@@ -33,8 +10,7 @@ function isPromise(obj) {
33
10
  function isNativePromise(obj) {
34
11
  return obj instanceof Promise;
35
12
  }
36
- // Annotate the CommonJS export names for ESM import in node:
37
- 0 && (module.exports = {
38
- isNativePromise,
39
- isPromise
40
- });
13
+
14
+
15
+
16
+ exports.isNativePromise = isNativePromise; exports.isPromise = isPromise;
package/isPromise.min.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var t=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var c=(n,e)=>{for(var i in e)t(n,i,{get:e[i],enumerable:!0})},m=(n,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of u(e))!f.call(n,o)&&o!==i&&t(n,o,{get:()=>e[o],enumerable:!(r=s(e,o))||r.enumerable});return n};var p=n=>m(t({},"__esModule",{value:!0}),n);var w={};c(w,{isNativePromise:()=>k,isPromise:()=>P});module.exports=p(w);function P(n){return!n||typeof n!="object"&&typeof n!="function"?!1:"then"in n&&typeof n.then=="function"}function k(n){return n instanceof Promise}0&&(module.exports={isNativePromise,isPromise});
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-QNNJNLGK.min.cjs');function e(n){return!n||typeof n!="object"&&typeof n!="function"?!1:"then"in n&&typeof n.then=="function"}function o(n){return n instanceof Promise}exports.isNativePromise = o; exports.isPromise = e;
2
2
  //# sourceMappingURL=isPromise.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/isPromise.ts"],"sourcesContent":["/**\n * A type guard to check if an object is a Promise (or a \"thenable\"). It checks\n * if the object is not null, is an object, and has a callable .then method.\n *\n * Note that if the Promise expects a certain type like `Promise<T>`, there is\n * no way to validate the type of T unless we resolve the promise. This function\n * does not attempt to typecheck for T in any way.\n */\nexport function isPromise(obj: unknown): obj is Promise<unknown> {\n // Check if the object is defined and not null.\n if (!obj || (typeof obj !== \"object\" && typeof obj !== \"function\")) {\n return false;\n }\n\n // Check if the .then property is a function (callable).\n return \"then\" in obj && typeof obj.then === \"function\";\n}\n\n/**\n * A type guard to check if an object is a native Promise.\n *\n * Note that if the Promise expects a certain type like `Promise<T>`, there is\n * no way to validate the type of T unless we resolve the promise. This function\n * does not attempt to typecheck for T in any way.\n */\nexport function isNativePromise(obj: unknown): obj is Promise<unknown> {\n return obj instanceof Promise;\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,cAAAC,IAAA,eAAAC,EAAAJ,GAQO,SAASG,EAAUE,EAAuC,CAE/D,MAAI,CAACA,GAAQ,OAAOA,GAAQ,UAAY,OAAOA,GAAQ,WAC9C,GAIF,SAAUA,GAAO,OAAOA,EAAI,MAAS,UAC9C,CASO,SAASH,EAAgBG,EAAuC,CACrE,OAAOA,aAAe,OACxB","names":["isPromise_exports","__export","isNativePromise","isPromise","__toCommonJS","obj"]}
1
+ {"version":3,"sources":["/Users/choksheaklau/src/ts-utils/dist/isPromise.min.cjs","../src/isPromise.ts"],"names":["isPromise","obj","isNativePromise"],"mappings":"AAAA,6GAAgC,SCQhBA,CAAAA,CAAUC,CAAAA,CAAuC,CAE/D,MAAI,CAACA,CAAAA,EAAQ,OAAOA,CAAAA,EAAQ,QAAA,EAAY,OAAOA,CAAAA,EAAQ,UAAA,CAC9C,CAAA,CAAA,CAIF,MAAA,GAAUA,CAAAA,EAAO,OAAOA,CAAAA,CAAI,IAAA,EAAS,UAC9C,CASO,SAASC,CAAAA,CAAgBD,CAAAA,CAAuC,CACrE,OAAOA,EAAAA,WAAe,OACxB,CAAA,mDAAA","file":"/Users/choksheaklau/src/ts-utils/dist/isPromise.min.cjs","sourcesContent":[null,"/**\n * A type guard to check if an object is a Promise (or a \"thenable\"). It checks\n * if the object is not null, is an object, and has a callable .then method.\n *\n * Note that if the Promise expects a certain type like `Promise<T>`, there is\n * no way to validate the type of T unless we resolve the promise. This function\n * does not attempt to typecheck for T in any way.\n */\nexport function isPromise(obj: unknown): obj is Promise<unknown> {\n // Check if the object is defined and not null.\n if (!obj || (typeof obj !== \"object\" && typeof obj !== \"function\")) {\n return false;\n }\n\n // Check if the .then property is a function (callable).\n return \"then\" in obj && typeof obj.then === \"function\";\n}\n\n/**\n * A type guard to check if an object is a native Promise.\n *\n * Note that if the Promise expects a certain type like `Promise<T>`, there is\n * no way to validate the type of T unless we resolve the promise. This function\n * does not attempt to typecheck for T in any way.\n */\nexport function isNativePromise(obj: unknown): obj is Promise<unknown> {\n return obj instanceof Promise;\n}\n"]}
package/isPromise.min.mjs CHANGED
@@ -1,2 +1,2 @@
1
- function e(n){return!n||typeof n!="object"&&typeof n!="function"?!1:"then"in n&&typeof n.then=="function"}function o(n){return n instanceof Promise}export{o as isNativePromise,e as isPromise};
1
+ import"./chunk-UOU6IP3S.min.mjs";function e(n){return!n||typeof n!="object"&&typeof n!="function"?!1:"then"in n&&typeof n.then=="function"}function o(n){return n instanceof Promise}export{o as isNativePromise,e as isPromise};
2
2
  //# sourceMappingURL=isPromise.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/isPromise.ts"],"sourcesContent":["/**\n * A type guard to check if an object is a Promise (or a \"thenable\"). It checks\n * if the object is not null, is an object, and has a callable .then method.\n *\n * Note that if the Promise expects a certain type like `Promise<T>`, there is\n * no way to validate the type of T unless we resolve the promise. This function\n * does not attempt to typecheck for T in any way.\n */\nexport function isPromise(obj: unknown): obj is Promise<unknown> {\n // Check if the object is defined and not null.\n if (!obj || (typeof obj !== \"object\" && typeof obj !== \"function\")) {\n return false;\n }\n\n // Check if the .then property is a function (callable).\n return \"then\" in obj && typeof obj.then === \"function\";\n}\n\n/**\n * A type guard to check if an object is a native Promise.\n *\n * Note that if the Promise expects a certain type like `Promise<T>`, there is\n * no way to validate the type of T unless we resolve the promise. This function\n * does not attempt to typecheck for T in any way.\n */\nexport function isNativePromise(obj: unknown): obj is Promise<unknown> {\n return obj instanceof Promise;\n}\n"],"mappings":"AAQO,SAASA,EAAUC,EAAuC,CAE/D,MAAI,CAACA,GAAQ,OAAOA,GAAQ,UAAY,OAAOA,GAAQ,WAC9C,GAIF,SAAUA,GAAO,OAAOA,EAAI,MAAS,UAC9C,CASO,SAASC,EAAgBD,EAAuC,CACrE,OAAOA,aAAe,OACxB","names":["isPromise","obj","isNativePromise"]}
1
+ {"version":3,"sources":["../src/isPromise.ts"],"sourcesContent":["/**\n * A type guard to check if an object is a Promise (or a \"thenable\"). It checks\n * if the object is not null, is an object, and has a callable .then method.\n *\n * Note that if the Promise expects a certain type like `Promise<T>`, there is\n * no way to validate the type of T unless we resolve the promise. This function\n * does not attempt to typecheck for T in any way.\n */\nexport function isPromise(obj: unknown): obj is Promise<unknown> {\n // Check if the object is defined and not null.\n if (!obj || (typeof obj !== \"object\" && typeof obj !== \"function\")) {\n return false;\n }\n\n // Check if the .then property is a function (callable).\n return \"then\" in obj && typeof obj.then === \"function\";\n}\n\n/**\n * A type guard to check if an object is a native Promise.\n *\n * Note that if the Promise expects a certain type like `Promise<T>`, there is\n * no way to validate the type of T unless we resolve the promise. This function\n * does not attempt to typecheck for T in any way.\n */\nexport function isNativePromise(obj: unknown): obj is Promise<unknown> {\n return obj instanceof Promise;\n}\n"],"mappings":"iCAQO,SAASA,EAAUC,EAAuC,CAE/D,MAAI,CAACA,GAAQ,OAAOA,GAAQ,UAAY,OAAOA,GAAQ,WAC9C,GAIF,SAAUA,GAAO,OAAOA,EAAI,MAAS,UAC9C,CASO,SAASC,EAAgBD,EAAuC,CACrE,OAAOA,aAAe,OACxB","names":["isPromise","obj","isNativePromise"]}
package/isPromise.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import "./chunk-M6PYQYOX.mjs";
2
+
1
3
  // src/isPromise.ts
2
4
  function isPromise(obj) {
3
5
  if (!obj || typeof obj !== "object" && typeof obj !== "function") {
package/kvStore.cjs CHANGED
@@ -1,366 +1,19 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
19
2
 
20
- // src/kvStore.ts
21
- var kvStore_exports = {};
22
- __export(kvStore_exports, {
23
- KvStore: () => KvStore,
24
- KvStoreConfig: () => KvStoreConfig,
25
- KvStoreItem: () => KvStoreItem,
26
- configureKvStore: () => configureKvStore,
27
- kvStore: () => kvStore,
28
- kvStoreItem: () => kvStoreItem
29
- });
30
- module.exports = __toCommonJS(kvStore_exports);
31
3
 
32
- // src/timeConstants.ts
33
- var MS_PER_SECOND = 1e3;
34
- var MS_PER_MINUTE = 6e4;
35
- var MS_PER_HOUR = 36e5;
36
- var MS_PER_DAY = 864e5;
37
4
 
38
- // src/duration.ts
39
- function durationToMs(duration) {
40
- const daysMs = (duration.days ?? 0) * MS_PER_DAY;
41
- const hoursMs = (duration.hours ?? 0) * MS_PER_HOUR;
42
- const minsMs = (duration.minutes ?? 0) * MS_PER_MINUTE;
43
- const secsMs = (duration.seconds ?? 0) * MS_PER_SECOND;
44
- const msMs = duration.milliseconds ?? 0;
45
- return daysMs + hoursMs + minsMs + secsMs + msMs;
46
- }
47
- function durationOrMsToMs(duration) {
48
- return typeof duration === "number" ? duration : durationToMs(duration);
49
- }
50
5
 
51
- // src/kvStore.ts
52
- var KvStoreConfig = {
53
- /**
54
- * Name of the DB in the indexed DB.
55
- * Updating the DB name will cause all old entries to be gone.
56
- */
57
- dbName: "KVStore",
58
- /**
59
- * Version of the DB schema. Most likely you will never want to change this.
60
- * Updating the version will cause all old entries to be gone.
61
- */
62
- dbVersion: 1,
63
- /**
64
- * Name of the store within the indexed DB. Each DB can have multiple stores.
65
- * In practice, it doesn't matter what you name this to be.
66
- */
67
- storeName: "kvStore",
68
- /** 30 days in ms. */
69
- expiryMs: MS_PER_DAY * 30,
70
- /** Do GC once per day. */
71
- gcIntervalMs: MS_PER_DAY
72
- };
73
- function configureKvStore(config) {
74
- Object.assign(KvStoreConfig, config);
75
- }
76
- function validateStoredObject(obj) {
77
- if (!obj || typeof obj !== "object" || typeof obj.key !== "string" || obj.value === void 0 || typeof obj.storedMs !== "number" || typeof obj.expiryMs !== "number" || Date.now() >= obj.expiryMs) {
78
- return void 0;
79
- }
80
- return obj;
81
- }
82
- function withOnError(request, reject) {
83
- request.onerror = (event) => {
84
- reject(event);
85
- };
86
- return request;
87
- }
88
- var KvStore = class {
89
- constructor(dbName, options) {
90
- this.dbName = dbName;
91
- this.dbVersion = options?.dbVersion ?? KvStoreConfig.dbVersion;
92
- this.storeName = options?.storeName ?? KvStoreConfig.storeName;
93
- this.defaultExpiryMs = options?.defaultExpiryMs ? durationOrMsToMs(options.defaultExpiryMs) : KvStoreConfig.expiryMs;
94
- this.gcIntervalMs = options?.gcIntervalMs ? durationOrMsToMs(options.gcIntervalMs) : KvStoreConfig.gcIntervalMs;
95
- this.gcMsStorageKey = `__kvStore:lastGcMs:${dbName}:v${this.dbVersion}:${this.storeName}`;
96
- }
97
- /** We'll init the DB only on first use. */
98
- db;
99
- /** Local storage key name for the last GC completed timestamp. */
100
- gcMsStorageKey;
101
- dbVersion;
102
- storeName;
103
- defaultExpiryMs;
104
- gcIntervalMs;
105
- async getOrCreateDb() {
106
- if (!this.db) {
107
- this.db = await new Promise((resolve, reject) => {
108
- const request = withOnError(
109
- globalThis.indexedDB.open(this.dbName, this.dbVersion),
110
- reject
111
- );
112
- request.onupgradeneeded = (event) => {
113
- const db = event.target.result;
114
- const objectStore = db.createObjectStore(this.storeName, {
115
- keyPath: "key"
116
- });
117
- objectStore.createIndex("key", "key", {
118
- unique: true
119
- });
120
- };
121
- request.onsuccess = (event) => {
122
- const db = event.target.result;
123
- resolve(db);
124
- };
125
- });
126
- }
127
- return this.db;
128
- }
129
- async transact(mode, callback) {
130
- const db = await this.getOrCreateDb();
131
- return await new Promise((resolve, reject) => {
132
- const transaction = withOnError(
133
- db.transaction(this.storeName, mode),
134
- reject
135
- );
136
- transaction.onabort = (event) => {
137
- reject(event);
138
- };
139
- const objectStore = transaction.objectStore(this.storeName);
140
- callback(objectStore, resolve, reject);
141
- });
142
- }
143
- /** Set a value in the store. */
144
- async set(key, value, expiryDeltaMs = this.defaultExpiryMs) {
145
- const nowMs = Date.now();
146
- const obj = {
147
- key,
148
- value,
149
- storedMs: nowMs,
150
- expiryMs: nowMs + durationOrMsToMs(expiryDeltaMs)
151
- };
152
- return await this.transact(
153
- "readwrite",
154
- (objectStore, resolve, reject) => {
155
- const request = withOnError(objectStore.put(obj), reject);
156
- request.onsuccess = () => {
157
- resolve(value);
158
- this.gc();
159
- };
160
- }
161
- );
162
- }
163
- /** Delete one or multiple keys. */
164
- async delete(key) {
165
- return await this.transact(
166
- "readwrite",
167
- (objectStore, resolve, reject) => {
168
- objectStore.transaction.oncomplete = () => {
169
- resolve();
170
- };
171
- if (typeof key === "string") {
172
- withOnError(objectStore.delete(key), reject);
173
- } else {
174
- for (const k of key) {
175
- withOnError(objectStore.delete(k), reject);
176
- }
177
- }
178
- }
179
- );
180
- }
181
- /** Mainly used to get the expiration timestamp of an object. */
182
- async getStoredObject(key) {
183
- const stored = await this.transact(
184
- "readonly",
185
- (objectStore, resolve, reject) => {
186
- const request = withOnError(objectStore.get(key), reject);
187
- request.onsuccess = () => {
188
- resolve(request.result);
189
- };
190
- }
191
- );
192
- if (!stored) {
193
- return void 0;
194
- }
195
- try {
196
- const obj = validateStoredObject(stored);
197
- if (!obj) {
198
- await this.delete(key);
199
- this.gc();
200
- return void 0;
201
- }
202
- return obj;
203
- } catch (e) {
204
- console.error(`Invalid kv value: ${key}=${JSON.stringify(stored)}:`, e);
205
- await this.delete(key);
206
- this.gc();
207
- return void 0;
208
- }
209
- }
210
- /** Get a value by key, or undefined if it does not exist. */
211
- async get(key) {
212
- const obj = await this.getStoredObject(key);
213
- return obj?.value;
214
- }
215
- /** Generic way to iterate through all entries. */
216
- async forEach(callback) {
217
- await this.transact("readonly", (objectStore, resolve, reject) => {
218
- const request = withOnError(objectStore.openCursor(), reject);
219
- request.onsuccess = async (event) => {
220
- const cursor = event.target.result;
221
- if (cursor) {
222
- if (cursor.key) {
223
- const obj = validateStoredObject(cursor.value);
224
- if (obj !== void 0) {
225
- await callback(
226
- String(cursor.key),
227
- obj.value,
228
- obj.expiryMs,
229
- obj.storedMs
230
- );
231
- }
232
- }
233
- cursor.continue();
234
- } else {
235
- resolve();
236
- }
237
- };
238
- });
239
- }
240
- /**
241
- * Returns the number of items in the store. Note that getting the size
242
- * requires iterating through the entire store because the items could expire
243
- * at any time, and hence the size is a dynamic number.
244
- */
245
- async size() {
246
- let count = 0;
247
- await this.forEach(() => {
248
- count++;
249
- });
250
- return count;
251
- }
252
- /** Remove all items from the store. */
253
- async clear() {
254
- await this.transact("readwrite", (objectStore, resolve, reject) => {
255
- const request = withOnError(objectStore.clear(), reject);
256
- request.onsuccess = () => {
257
- resolve();
258
- };
259
- });
260
- }
261
- /**
262
- * Returns all items as map of key to value, mainly used for debugging dumps.
263
- * The type T is applied to all values, even though they might not be of type
264
- * T (in the case when you store different data types in the same store).
265
- */
266
- async asMap() {
267
- const map = /* @__PURE__ */ new Map();
268
- await this.forEach((key, value, expiryMs, storedMs) => {
269
- map.set(key, { value, expiryMs, storedMs });
270
- });
271
- return map;
272
- }
273
- /** Returns the ms timestamp for the last GC (garbage collection). */
274
- get lastGcMs() {
275
- const lastGcMsStr = globalThis.localStorage.getItem(this.gcMsStorageKey);
276
- if (!lastGcMsStr) return 0;
277
- const ms = Number(lastGcMsStr);
278
- return isNaN(ms) ? 0 : ms;
279
- }
280
- /** Set the ms timestamp for the last GC (garbage collection). */
281
- set lastGcMs(ms) {
282
- globalThis.localStorage.setItem(this.gcMsStorageKey, String(ms));
283
- }
284
- /** Perform garbage-collection if due, else do nothing. */
285
- async gc() {
286
- const lastGcMs = this.lastGcMs;
287
- if (!lastGcMs) {
288
- this.lastGcMs = Date.now();
289
- return;
290
- }
291
- if (Date.now() < lastGcMs + this.gcIntervalMs) {
292
- return;
293
- }
294
- await this.gcNow();
295
- }
296
- /**
297
- * Perform garbage collection immediately without checking whether we are
298
- * due for the next GC or not.
299
- */
300
- async gcNow() {
301
- console.log(`Starting kvStore GC on ${this.dbName} v${this.dbVersion}...`);
302
- this.lastGcMs = Date.now();
303
- const keysToDelete = [];
304
- await this.forEach(
305
- async (key, value, expiryMs) => {
306
- if (value === void 0 || Date.now() >= expiryMs) {
307
- keysToDelete.push(key);
308
- }
309
- }
310
- );
311
- if (keysToDelete.length) {
312
- await this.delete(keysToDelete);
313
- }
314
- console.log(
315
- `Finished kvStore GC on ${this.dbName} v${this.dbVersion} - deleted ${keysToDelete.length} keys`
316
- );
317
- this.lastGcMs = Date.now();
318
- }
319
- /** Returns `this` casted into a StorageAdapter<T>. */
320
- asStorageAdapter() {
321
- return this;
322
- }
323
- };
324
- var kvStore = new KvStore(KvStoreConfig.dbName);
325
- var KvStoreItem = class {
326
- constructor(key, defaultExpiryMs = KvStoreConfig.expiryMs, store = kvStore) {
327
- this.key = key;
328
- this.store = store;
329
- this.defaultExpiryMs = defaultExpiryMs && durationOrMsToMs(defaultExpiryMs);
330
- }
331
- defaultExpiryMs;
332
- /** Set a value in the store. */
333
- async set(value, expiryDeltaMs = this.defaultExpiryMs) {
334
- await this.store.set(this.key, value, expiryDeltaMs);
335
- }
336
- /**
337
- * Example usage:
338
- *
339
- * const { value, storedMs, expiryMs, storedMs } =
340
- * await myKvItem.getStoredObject();
341
- */
342
- async getStoredObject() {
343
- return await this.store.getStoredObject(this.key);
344
- }
345
- /** Get a value by key, or undefined if it does not exist. */
346
- async get() {
347
- return await this.store.get(this.key);
348
- }
349
- /** Delete this key from the store. */
350
- async delete() {
351
- await this.store.delete(this.key);
352
- }
353
- };
354
- function kvStoreItem(key, expiryMs, store = kvStore) {
355
- expiryMs = expiryMs && durationOrMsToMs(expiryMs);
356
- return new KvStoreItem(key, expiryMs, store);
357
- }
358
- // Annotate the CommonJS export names for ESM import in node:
359
- 0 && (module.exports = {
360
- KvStore,
361
- KvStoreConfig,
362
- KvStoreItem,
363
- configureKvStore,
364
- kvStore,
365
- kvStoreItem
366
- });
6
+
7
+
8
+ var _chunkSULNMALNcjs = require('./chunk-SULNMALN.cjs');
9
+ require('./chunk-4GLOLTJ5.cjs');
10
+ require('./chunk-Y7MC73BZ.cjs');
11
+ require('./chunk-ILGTU46T.cjs');
12
+ _chunkSULNMALNcjs.init_kvStore.call(void 0, );
13
+
14
+
15
+
16
+
17
+
18
+
19
+ exports.KvStoreConfig = _chunkSULNMALNcjs.KvStoreConfig; exports.configureKvStore = _chunkSULNMALNcjs.configureKvStore; exports.createKvStore = _chunkSULNMALNcjs.createKvStore; exports.kvStore = _chunkSULNMALNcjs.kvStore; exports.kvStoreItem = _chunkSULNMALNcjs.kvStoreItem;