@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.
- package/README.md +9 -3
- package/arrayBuffer.cjs +10 -39
- package/arrayBuffer.min.cjs +1 -1
- package/arrayBuffer.min.cjs.map +1 -1
- package/arrayBuffer.min.mjs +1 -1
- package/arrayBuffer.min.mjs.map +1 -1
- package/arrayBuffer.mjs +7 -10
- package/asNumber.cjs +6 -38
- package/asNumber.d.mts +1 -1
- package/asNumber.d.ts +1 -1
- package/asNumber.min.cjs +1 -1
- package/asNumber.min.cjs.map +1 -1
- package/asNumber.min.mjs +1 -1
- package/asNumber.min.mjs.map +1 -1
- package/asNumber.mjs +4 -11
- package/assert.cjs +4 -27
- package/assert.min.cjs +1 -1
- package/assert.min.cjs.map +1 -1
- package/assert.min.mjs +1 -1
- package/assert.min.mjs.map +1 -1
- package/assert.mjs +2 -0
- package/base64Url.cjs +5 -29
- package/base64Url.min.cjs +1 -1
- package/base64Url.min.cjs.map +1 -1
- package/base64Url.min.mjs +1 -1
- package/base64Url.min.mjs.map +1 -1
- package/base64Url.mjs +2 -0
- package/capLength.cjs +7 -71
- package/capLength.min.cjs +1 -5
- package/capLength.min.cjs.map +1 -1
- package/capLength.min.mjs +1 -5
- package/capLength.min.mjs.map +1 -1
- package/capLength.mjs +4 -41
- package/chunk-22JDWCOS.min.cjs +2 -0
- package/chunk-22JDWCOS.min.cjs.map +1 -0
- package/chunk-244NBT4Q.min.mjs +2 -0
- package/chunk-244NBT4Q.min.mjs.map +1 -0
- package/chunk-27MBP3ES.min.cjs +2 -0
- package/chunk-27MBP3ES.min.cjs.map +1 -0
- package/chunk-34ENP2B3.min.mjs +438 -0
- package/chunk-34ENP2B3.min.mjs.map +1 -0
- package/chunk-3EBQ2GO2.min.cjs +2 -0
- package/chunk-3EBQ2GO2.min.cjs.map +1 -0
- package/chunk-4GLOLTJ5.cjs +167 -0
- package/chunk-6TQBMXTL.min.cjs +2 -0
- package/chunk-6TQBMXTL.min.cjs.map +1 -0
- package/chunk-AWZBCFMG.min.cjs +2 -0
- package/chunk-AWZBCFMG.min.cjs.map +1 -0
- package/chunk-AXNETZET.cjs +20 -0
- package/chunk-BKZM6NWX.min.cjs +2 -0
- package/chunk-BKZM6NWX.min.cjs.map +1 -0
- package/chunk-BZKQXX3A.cjs +40 -0
- package/chunk-CERFUU5I.cjs +93 -0
- package/chunk-CSTKFJ6G.mjs +239 -0
- package/chunk-DUN4UY2Q.cjs +239 -0
- package/chunk-EDJJUP4K.min.cjs +6 -0
- package/chunk-EDJJUP4K.min.cjs.map +1 -0
- package/chunk-FFNQBZH5.cjs +14 -0
- package/chunk-FZZRSHSH.min.mjs +6 -0
- package/chunk-FZZRSHSH.min.mjs.map +1 -0
- package/chunk-GAP2HS5M.min.cjs +2 -0
- package/chunk-GAP2HS5M.min.cjs.map +1 -0
- package/chunk-GLYMAPS4.min.mjs +2 -0
- package/chunk-GLYMAPS4.min.mjs.map +1 -0
- package/chunk-I65KPVMO.min.cjs +438 -0
- package/chunk-I65KPVMO.min.cjs.map +1 -0
- package/chunk-ILGTU46T.cjs +39 -0
- package/chunk-IOKRXHKE.min.mjs +2 -0
- package/chunk-IOKRXHKE.min.mjs.map +1 -0
- package/chunk-ISP4SMRC.min.cjs +2 -0
- package/chunk-ISP4SMRC.min.cjs.map +1 -0
- package/chunk-KETP5HBF.cjs +24 -0
- package/chunk-KLHNGJ4Y.min.mjs +2 -0
- package/chunk-KLHNGJ4Y.min.mjs.map +1 -0
- package/chunk-KMNTU3DJ.mjs +45 -0
- package/chunk-LDVEXETI.cjs +45 -0
- package/chunk-LZENHV35.min.cjs +2 -0
- package/chunk-LZENHV35.min.cjs.map +1 -0
- package/chunk-M5PIM2HB.mjs +42 -0
- package/chunk-M6PYQYOX.mjs +39 -0
- package/chunk-MN5EYNZN.min.mjs +2 -0
- package/chunk-MN5EYNZN.min.mjs.map +1 -0
- package/chunk-NRIBJ2OJ.mjs +16031 -0
- package/chunk-NVLYXWLX.cjs +32 -0
- package/chunk-O352F2MT.mjs +24 -0
- package/chunk-O6B2TKFK.min.mjs +2 -0
- package/chunk-O6B2TKFK.min.mjs.map +1 -0
- package/chunk-OGF34H4T.min.cjs +2 -0
- package/chunk-OGF34H4T.min.cjs.map +1 -0
- package/chunk-OXSWWWOM.min.mjs +2 -0
- package/chunk-OXSWWWOM.min.mjs.map +1 -0
- package/chunk-PRUGHVRT.mjs +14 -0
- package/chunk-Q4WCMSOW.min.mjs +2 -0
- package/chunk-Q4WCMSOW.min.mjs.map +1 -0
- package/chunk-QH74JZCK.mjs +9 -0
- package/chunk-QNNJNLGK.min.cjs +2 -0
- package/chunk-QNNJNLGK.min.cjs.map +1 -0
- package/chunk-QWCFN7ZM.mjs +15 -0
- package/chunk-SDM2OPT6.mjs +32 -0
- package/chunk-SHKRZCF2.cjs +16031 -0
- package/chunk-SJDJDNDN.min.cjs +2 -0
- package/chunk-SJDJDNDN.min.cjs.map +1 -0
- package/chunk-SULNMALN.cjs +328 -0
- package/chunk-SV35RBZ7.min.mjs +2 -0
- package/chunk-SV35RBZ7.min.mjs.map +1 -0
- package/chunk-TJFYGFOW.mjs +328 -0
- package/chunk-UHRYBUUX.min.mjs +2 -0
- package/chunk-UHRYBUUX.min.mjs.map +1 -0
- package/chunk-UOU6IP3S.min.mjs +2 -0
- package/chunk-UOU6IP3S.min.mjs.map +1 -0
- package/chunk-V76XVNZ5.mjs +20 -0
- package/chunk-VFYQ7I5V.min.mjs +2 -0
- package/chunk-VFYQ7I5V.min.mjs.map +1 -0
- package/chunk-VG7VV7J2.mjs +167 -0
- package/chunk-VJCV56DO.cjs +15 -0
- package/chunk-VREA6AKG.cjs +9 -0
- package/chunk-W5I6Y5FK.min.mjs +2 -0
- package/chunk-W5I6Y5FK.min.mjs.map +1 -0
- package/chunk-Y7MC73BZ.cjs +42 -0
- package/chunk-YVWROQKU.mjs +40 -0
- package/chunk-ZKIZ5SWK.min.cjs +2 -0
- package/chunk-ZKIZ5SWK.min.cjs.map +1 -0
- package/chunk-ZZZB7NJX.mjs +93 -0
- package/concatIterators.cjs +4 -27
- package/concatIterators.min.cjs +1 -1
- package/concatIterators.min.cjs.map +1 -1
- package/concatIterators.min.mjs +1 -1
- package/concatIterators.min.mjs.map +1 -1
- package/concatIterators.mjs +2 -0
- package/dateTimeStr.cjs +31 -119
- package/dateTimeStr.min.cjs +1 -1
- package/dateTimeStr.min.cjs.map +1 -1
- package/dateTimeStr.min.mjs +1 -1
- package/dateTimeStr.min.mjs.map +1 -1
- package/dateTimeStr.mjs +17 -69
- package/duration.cjs +24 -188
- package/duration.min.cjs +1 -1
- package/duration.min.cjs.map +1 -1
- package/duration.min.mjs +1 -1
- package/duration.min.mjs.map +1 -1
- package/duration.mjs +14 -144
- package/getEnv.cjs +20 -0
- package/getEnv.d.mts +11 -0
- package/getEnv.d.ts +11 -0
- package/getEnv.min.cjs +2 -0
- package/getEnv.min.cjs.map +1 -0
- package/getEnv.min.mjs +2 -0
- package/getEnv.min.mjs.map +1 -0
- package/getEnv.mjs +20 -0
- package/isEmpty.cjs +8 -46
- package/isEmpty.min.cjs +1 -1
- package/isEmpty.min.cjs.map +1 -1
- package/isEmpty.min.mjs +1 -1
- package/isEmpty.min.mjs.map +1 -1
- package/isEmpty.mjs +6 -19
- package/isPromise.cjs +5 -29
- package/isPromise.min.cjs +1 -1
- package/isPromise.min.cjs.map +1 -1
- package/isPromise.min.mjs +1 -1
- package/isPromise.min.mjs.map +1 -1
- package/isPromise.mjs +2 -0
- package/kvStore.cjs +15 -362
- package/kvStore.d.mts +142 -44
- package/kvStore.d.ts +142 -44
- package/kvStore.min.cjs +1 -1
- package/kvStore.min.cjs.map +1 -1
- package/kvStore.min.mjs +1 -1
- package/kvStore.min.mjs.map +1 -1
- package/kvStore.mjs +13 -328
- package/localStore.cjs +15 -263
- package/localStore.d.mts +135 -34
- package/localStore.d.ts +135 -34
- package/localStore.min.cjs +1 -1
- package/localStore.min.cjs.map +1 -1
- package/localStore.min.mjs +1 -1
- package/localStore.min.mjs.map +1 -1
- package/localStore.mjs +13 -229
- package/magic-string.es-4UY437WL.min.mjs +14 -0
- package/magic-string.es-4UY437WL.min.mjs.map +1 -0
- package/magic-string.es-OAQWZQTY.mjs +1323 -0
- package/magic-string.es-UE2UVQEL.cjs +1323 -0
- package/magic-string.es-X6DNUB6Y.min.cjs +14 -0
- package/magic-string.es-X6DNUB6Y.min.cjs.map +1 -0
- package/mean.cjs +8 -48
- package/mean.min.cjs +1 -1
- package/mean.min.cjs.map +1 -1
- package/mean.min.mjs +1 -1
- package/mean.min.mjs.map +1 -1
- package/mean.mjs +5 -18
- package/median.cjs +7 -41
- package/median.min.cjs +1 -1
- package/median.min.cjs.map +1 -1
- package/median.min.mjs +1 -1
- package/median.min.mjs.map +1 -1
- package/median.mjs +5 -12
- package/nonEmpty.cjs +8 -48
- package/nonEmpty.min.cjs +1 -1
- package/nonEmpty.min.cjs.map +1 -1
- package/nonEmpty.min.mjs +1 -1
- package/nonEmpty.min.mjs.map +1 -1
- package/nonEmpty.mjs +6 -19
- package/nonNil.cjs +4 -27
- package/nonNil.min.cjs +1 -1
- package/nonNil.min.cjs.map +1 -1
- package/nonNil.min.mjs +1 -1
- package/nonNil.min.mjs.map +1 -1
- package/nonNil.mjs +2 -0
- package/package.json +274 -34
- package/round.cjs +6 -32
- package/round.min.cjs +1 -1
- package/round.min.cjs.map +1 -1
- package/round.min.mjs +1 -1
- package/round.min.mjs.map +1 -1
- package/round.mjs +4 -5
- package/roundToString.cjs +7 -35
- package/roundToString.min.cjs +1 -1
- package/roundToString.min.cjs.map +1 -1
- package/roundToString.min.mjs +1 -1
- package/roundToString.min.mjs.map +1 -1
- package/roundToString.mjs +4 -5
- package/safeBtoa.cjs +4 -27
- package/safeBtoa.d.mts +7 -0
- package/safeBtoa.d.ts +7 -0
- package/safeBtoa.min.cjs +1 -1
- package/safeBtoa.min.cjs.map +1 -1
- package/safeBtoa.min.mjs +1 -1
- package/safeBtoa.min.mjs.map +1 -1
- package/safeBtoa.mjs +2 -0
- package/sha256.cjs +8 -34
- package/sha256.min.cjs +1 -1
- package/sha256.min.cjs.map +1 -1
- package/sha256.min.mjs +1 -1
- package/sha256.min.mjs.map +1 -1
- package/sha256.mjs +6 -7
- package/sleep.cjs +4 -27
- package/sleep.min.cjs +1 -1
- package/sleep.min.cjs.map +1 -1
- package/sleep.min.mjs +1 -1
- package/sleep.min.mjs.map +1 -1
- package/sleep.mjs +2 -0
- package/storageAdapter.cjs +1 -18
- package/storageAdapter.min.cjs +1 -2
- package/storageAdapter.min.cjs.map +1 -1
- package/sum.cjs +5 -45
- package/sum.min.cjs +1 -1
- package/sum.min.cjs.map +1 -1
- package/sum.min.mjs +1 -1
- package/sum.min.mjs.map +1 -1
- package/sum.mjs +5 -18
- package/timeConstants.cjs +35 -69
- package/timeConstants.min.cjs +1 -1
- package/timeConstants.min.cjs.map +1 -1
- package/timeConstants.min.mjs +1 -1
- package/timeConstants.min.mjs.map +1 -1
- package/timeConstants.mjs +19 -15
- package/timer.cjs +7 -185
- package/timer.d.mts +9 -6
- package/timer.d.ts +9 -6
- package/timer.min.cjs +1 -1
- package/timer.min.cjs.map +1 -1
- package/timer.min.mjs +1 -1
- package/timer.min.mjs.map +1 -1
- package/timer.mjs +8 -158
- package/toReadableString.cjs +6 -68
- package/toReadableString.min.cjs +1 -5
- package/toReadableString.min.cjs.map +1 -1
- package/toReadableString.min.mjs +1 -5
- package/toReadableString.min.mjs.map +1 -1
- package/toReadableString.mjs +4 -41
- package/safeParseFloat.cjs +0 -33
- package/safeParseFloat.d.mts +0 -6
- package/safeParseFloat.d.ts +0 -6
- package/safeParseFloat.min.cjs +0 -2
- package/safeParseFloat.min.cjs.map +0 -1
- package/safeParseFloat.min.mjs +0 -2
- package/safeParseFloat.min.mjs.map +0 -1
- package/safeParseFloat.mjs +0 -8
- package/safeParseInt.cjs +0 -33
- package/safeParseInt.d.mts +0 -6
- package/safeParseInt.d.ts +0 -6
- package/safeParseInt.min.cjs +0 -2
- package/safeParseInt.min.cjs.map +0 -1
- package/safeParseInt.min.mjs +0 -2
- package/safeParseInt.min.mjs.map +0 -1
- 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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
exports.isNativePromise = isNativePromise; exports.isPromise = isPromise;
|
package/isPromise.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
package/isPromise.min.cjs.map
CHANGED
|
@@ -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"]
|
|
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
|
package/isPromise.min.mjs.map
CHANGED
|
@@ -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":"
|
|
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
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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;
|