@ls-stack/utils 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/arrayUtils.d.ts +50 -0
- package/dist/arrayUtils.js +13 -0
- package/dist/arrayUtils.js.map +1 -0
- package/dist/assertions.d.ts +17 -0
- package/dist/assertions.js +25 -0
- package/dist/assertions.js.map +1 -0
- package/dist/castValues.d.ts +4 -0
- package/dist/castValues.js +16 -0
- package/dist/castValues.js.map +1 -0
- package/dist/chunk-4DRNU53E.js +70 -0
- package/dist/chunk-4DRNU53E.js.map +1 -0
- package/dist/chunk-5FQYH3ZJ.js +106 -0
- package/dist/chunk-5FQYH3ZJ.js.map +1 -0
- package/dist/chunk-5SB253CL.js +54 -0
- package/dist/chunk-5SB253CL.js.map +1 -0
- package/dist/chunk-HLFWWIDK.js +9 -0
- package/dist/chunk-HLFWWIDK.js.map +1 -0
- package/dist/chunk-HYFUWQ2E.js +218 -0
- package/dist/chunk-HYFUWQ2E.js.map +1 -0
- package/dist/chunk-J66LUDLH.js +13 -0
- package/dist/chunk-J66LUDLH.js.map +1 -0
- package/dist/chunk-JT3EBBCA.js +69 -0
- package/dist/chunk-JT3EBBCA.js.map +1 -0
- package/dist/chunk-JZUOIOMU.js +75 -0
- package/dist/chunk-JZUOIOMU.js.map +1 -0
- package/dist/chunk-MMKMF4GG.js +21 -0
- package/dist/chunk-MMKMF4GG.js.map +1 -0
- package/dist/chunk-SNAAKCTH.js +40 -0
- package/dist/chunk-SNAAKCTH.js.map +1 -0
- package/dist/consoleFmt.d.ts +48 -0
- package/dist/consoleFmt.js +60 -0
- package/dist/consoleFmt.js.map +1 -0
- package/dist/conversions.d.ts +3 -0
- package/dist/conversions.js +7 -0
- package/dist/conversions.js.map +1 -0
- package/dist/createThrottleController.d.ts +16 -0
- package/dist/createThrottleController.js +66 -0
- package/dist/createThrottleController.js.map +1 -0
- package/dist/dedent.d.ts +4 -0
- package/dist/dedent.js +33 -0
- package/dist/dedent.js.map +1 -0
- package/dist/deepEqual.d.ts +4 -0
- package/dist/deepEqual.js +7 -0
- package/dist/deepEqual.js.map +1 -0
- package/dist/enhancedMap.d.ts +22 -0
- package/dist/enhancedMap.js +10 -0
- package/dist/enhancedMap.js.map +1 -0
- package/dist/exhaustiveMatch.d.ts +5 -0
- package/dist/exhaustiveMatch.js +27 -0
- package/dist/exhaustiveMatch.js.map +1 -0
- package/dist/main.d.ts +25 -0
- package/dist/main.js +3 -0
- package/dist/main.js.map +1 -0
- package/dist/mathUtils.d.ts +4 -0
- package/dist/mathUtils.js +9 -0
- package/dist/mathUtils.js.map +1 -0
- package/dist/objUtils.d.ts +7 -0
- package/dist/objUtils.js +15 -0
- package/dist/objUtils.js.map +1 -0
- package/dist/parallelAsyncResultCalls.d.ts +76 -0
- package/dist/parallelAsyncResultCalls.js +126 -0
- package/dist/parallelAsyncResultCalls.js.map +1 -0
- package/dist/promiseUtils.d.ts +8 -0
- package/dist/promiseUtils.js +14 -0
- package/dist/promiseUtils.js.map +1 -0
- package/dist/rsResult.d.ts +118 -0
- package/dist/rsResult.js +21 -0
- package/dist/rsResult.js.map +1 -0
- package/dist/runShellCmd.d.ts +15 -0
- package/dist/runShellCmd.js +71 -0
- package/dist/runShellCmd.js.map +1 -0
- package/dist/shallowEqual.d.ts +4 -0
- package/dist/shallowEqual.js +74 -0
- package/dist/shallowEqual.js.map +1 -0
- package/dist/sleep.d.ts +3 -0
- package/dist/sleep.js +7 -0
- package/dist/sleep.js.map +1 -0
- package/dist/stringUtils.d.ts +18 -0
- package/dist/stringUtils.js +17 -0
- package/dist/stringUtils.js.map +1 -0
- package/dist/testUtils.d.ts +24 -0
- package/dist/testUtils.js +171 -0
- package/dist/testUtils.js.map +1 -0
- package/dist/typingFnUtils.d.ts +5 -0
- package/dist/typingFnUtils.js +8 -0
- package/dist/typingFnUtils.js.map +1 -0
- package/dist/typingTestUtils.d.ts +12 -0
- package/dist/typingTestUtils.js +19 -0
- package/dist/typingTestUtils.js.map +1 -0
- package/dist/typingUtils.d.ts +11 -0
- package/dist/typingUtils.js +1 -0
- package/dist/typingUtils.js.map +1 -0
- package/dist/yamlStringify.d.ts +8 -0
- package/dist/yamlStringify.js +292 -0
- package/dist/yamlStringify.js.map +1 -0
- package/package.json +235 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/mathUtils.ts
|
|
2
|
+
function clampMax(value, max) {
|
|
3
|
+
return value > max ? max : value;
|
|
4
|
+
}
|
|
5
|
+
function clampMin(value, min) {
|
|
6
|
+
return value < min ? min : value;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
clampMax,
|
|
11
|
+
clampMin
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chunk-J66LUDLH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mathUtils.ts"],"sourcesContent":["export function clampMax(value: number, max: number) {\n return value > max ? max : value;\n}\n\nexport function clampMin(value: number, min: number) {\n return value < min ? min : value;\n}\n"],"mappings":";AAAO,SAAS,SAAS,OAAe,KAAa;AACnD,SAAO,QAAQ,MAAM,MAAM;AAC7B;AAEO,SAAS,SAAS,OAAe,KAAa;AACnD,SAAO,QAAQ,MAAM,MAAM;AAC7B;","names":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// src/assertions.ts
|
|
2
|
+
var undefErrMsg = "not undefined assertion failed";
|
|
3
|
+
var nullishErrMsg = "not nullish assertion failed";
|
|
4
|
+
function notUndefined(value) {
|
|
5
|
+
if (value === void 0) {
|
|
6
|
+
throw new Error(undefErrMsg);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
function notNullish(value) {
|
|
11
|
+
if (value === void 0 || value === null) {
|
|
12
|
+
throw new Error(nullishErrMsg);
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function assertIsNotNullish(value, errorMsg = nullishErrMsg) {
|
|
17
|
+
if (value === void 0 || value === null) {
|
|
18
|
+
throw new Error(errorMsg);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function assertIsNotUndefined(value, errorMsg = undefErrMsg) {
|
|
22
|
+
if (value === void 0) {
|
|
23
|
+
throw new Error(errorMsg);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function invariant(condition, errorMsg = "Invariant violation") {
|
|
27
|
+
if (!condition) {
|
|
28
|
+
throw new Error(`Invariant violation: ${errorMsg}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function exhaustiveCheck(narrowedType) {
|
|
32
|
+
return new Error("This should never happen");
|
|
33
|
+
}
|
|
34
|
+
function isObject(value) {
|
|
35
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36
|
+
}
|
|
37
|
+
function isFunction(value) {
|
|
38
|
+
return typeof value === "function";
|
|
39
|
+
}
|
|
40
|
+
function isPromise(value) {
|
|
41
|
+
return isObject(value) && "then" in value;
|
|
42
|
+
}
|
|
43
|
+
function isPlainObject(value) {
|
|
44
|
+
if (!value || typeof value !== "object")
|
|
45
|
+
return false;
|
|
46
|
+
const proto = Object.getPrototypeOf(value);
|
|
47
|
+
if (proto === null) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
51
|
+
if (Ctor === Object)
|
|
52
|
+
return true;
|
|
53
|
+
const objectCtorString = Object.prototype.constructor.toString();
|
|
54
|
+
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
notUndefined,
|
|
59
|
+
notNullish,
|
|
60
|
+
assertIsNotNullish,
|
|
61
|
+
assertIsNotUndefined,
|
|
62
|
+
invariant,
|
|
63
|
+
exhaustiveCheck,
|
|
64
|
+
isObject,
|
|
65
|
+
isFunction,
|
|
66
|
+
isPromise,
|
|
67
|
+
isPlainObject
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=chunk-JT3EBBCA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/assertions.ts"],"sourcesContent":["const undefErrMsg = 'not undefined assertion failed';\nconst nullishErrMsg = 'not nullish assertion failed';\n\ntype NotUndefined<T> = T extends undefined ? never : T;\n\ntype StrictNonUndefined<T, N = unknown> =\n undefined extends T ? NotUndefined<T> : N;\n\nexport function notUndefined<T>(value: T): StrictNonUndefined<T> {\n if (value === undefined) {\n throw new Error(undefErrMsg);\n }\n\n return value as any;\n}\n\ntype StrictNonNullable<T, N = unknown> =\n undefined extends T ? NonNullable<T>\n : null extends T ? NonNullable<T>\n : N;\n\nexport function notNullish<T>(value: T): StrictNonNullable<T> {\n if (value === undefined || value === null) {\n throw new Error(nullishErrMsg);\n }\n\n return value as any;\n}\n\nexport function assertIsNotNullish<T>(\n value: T,\n errorMsg = nullishErrMsg,\n): asserts value is StrictNonNullable<T, never> {\n if (value === undefined || value === null) {\n throw new Error(errorMsg);\n }\n}\n\nexport function assertIsNotUndefined<T>(\n value: T,\n errorMsg = undefErrMsg,\n): asserts value is StrictNonUndefined<T, never> {\n if (value === undefined) {\n throw new Error(errorMsg);\n }\n}\n\n/** Use this function to assert that a certain condition is always true. */\nexport function invariant(\n condition: any,\n errorMsg = 'Invariant violation',\n): asserts condition {\n if (!condition) {\n throw new Error(`Invariant violation: ${errorMsg}`);\n }\n}\n\n/** ensures all type possibilities are being handled */\nexport function exhaustiveCheck<Except = never>(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars -- we use this function only for type checking\n narrowedType: NoInfer<Except>,\n): Error {\n return new Error('This should never happen');\n}\n\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function isFunction(value: unknown): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n\nexport function isPromise(value: unknown): value is Promise<unknown> {\n return isObject(value) && 'then' in value;\n}\n\nexport function isPlainObject(value: any): value is Record<string, unknown> {\n if (!value || typeof value !== 'object') return false;\n const proto = Object.getPrototypeOf(value);\n if (proto === null) {\n return true;\n }\n const Ctor =\n Object.hasOwnProperty.call(proto, 'constructor') && proto.constructor;\n\n if (Ctor === Object) return true;\n\n const objectCtorString = Object.prototype.constructor.toString();\n\n return (\n typeof Ctor == 'function' &&\n Function.toString.call(Ctor) === objectCtorString\n );\n}\n"],"mappings":";AAAA,IAAM,cAAc;AACpB,IAAM,gBAAgB;AAOf,SAAS,aAAgB,OAAiC;AAC/D,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,WAAW;AAAA,EAC7B;AAEA,SAAO;AACT;AAOO,SAAS,WAAc,OAAgC;AAC5D,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,UAAM,IAAI,MAAM,aAAa;AAAA,EAC/B;AAEA,SAAO;AACT;AAEO,SAAS,mBACd,OACA,WAAW,eACmC;AAC9C,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,UAAM,IAAI,MAAM,QAAQ;AAAA,EAC1B;AACF;AAEO,SAAS,qBACd,OACA,WAAW,aACoC;AAC/C,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,QAAQ;AAAA,EAC1B;AACF;AAGO,SAAS,UACd,WACA,WAAW,uBACQ;AACnB,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,wBAAwB,QAAQ,EAAE;AAAA,EACpD;AACF;AAGO,SAAS,gBAEd,cACO;AACP,SAAO,IAAI,MAAM,0BAA0B;AAC7C;AAEO,SAAS,SAAS,OAAkD;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEO,SAAS,WAAW,OAAkD;AAC3E,SAAO,OAAO,UAAU;AAC1B;AAEO,SAAS,UAAU,OAA2C;AACnE,SAAO,SAAS,KAAK,KAAK,UAAU;AACtC;AAEO,SAAS,cAAc,OAA8C;AAC1E,MAAI,CAAC,SAAS,OAAO,UAAU;AAAU,WAAO;AAChD,QAAM,QAAQ,OAAO,eAAe,KAAK;AACzC,MAAI,UAAU,MAAM;AAClB,WAAO;AAAA,EACT;AACA,QAAM,OACJ,OAAO,eAAe,KAAK,OAAO,aAAa,KAAK,MAAM;AAE5D,MAAI,SAAS;AAAQ,WAAO;AAE5B,QAAM,mBAAmB,OAAO,UAAU,YAAY,SAAS;AAE/D,SACE,OAAO,QAAQ,cACf,SAAS,SAAS,KAAK,IAAI,MAAM;AAErC;","names":[]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/deepEqual.ts
|
|
2
|
+
var has = Object.prototype.hasOwnProperty;
|
|
3
|
+
function find(iter, tar, key) {
|
|
4
|
+
for (key of iter.keys()) {
|
|
5
|
+
if (deepEqual(key, tar))
|
|
6
|
+
return key;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function deepEqual(foo, bar) {
|
|
10
|
+
var ctor, len, tmp;
|
|
11
|
+
if (foo === bar)
|
|
12
|
+
return true;
|
|
13
|
+
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
14
|
+
if (ctor === Date)
|
|
15
|
+
return deepEqual(foo.getTime(), bar.getTime());
|
|
16
|
+
if (ctor === RegExp)
|
|
17
|
+
return foo.toString() === bar.toString();
|
|
18
|
+
if (ctor === Array) {
|
|
19
|
+
if ((len = foo.length) === bar.length) {
|
|
20
|
+
while (len-- && deepEqual(foo[len], bar[len]))
|
|
21
|
+
;
|
|
22
|
+
}
|
|
23
|
+
return len === -1;
|
|
24
|
+
}
|
|
25
|
+
if (ctor === Set) {
|
|
26
|
+
if (foo.size !== bar.size) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
for (len of foo) {
|
|
30
|
+
tmp = len;
|
|
31
|
+
if (tmp && typeof tmp === "object") {
|
|
32
|
+
tmp = find(bar, tmp);
|
|
33
|
+
if (!tmp)
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (!bar.has(tmp))
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (ctor === Map) {
|
|
42
|
+
if (foo.size !== bar.size) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
for (len of foo) {
|
|
46
|
+
tmp = len[0];
|
|
47
|
+
if (tmp && typeof tmp === "object") {
|
|
48
|
+
tmp = find(bar, tmp);
|
|
49
|
+
if (!tmp)
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (!deepEqual(len[1], bar.get(tmp))) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (!ctor || typeof foo === "object") {
|
|
59
|
+
len = 0;
|
|
60
|
+
for (ctor in foo) {
|
|
61
|
+
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
|
|
62
|
+
return false;
|
|
63
|
+
if (!(ctor in bar) || !deepEqual(foo[ctor], bar[ctor]))
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return Object.keys(bar).length === len;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return foo !== foo && bar !== bar;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
deepEqual
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=chunk-JZUOIOMU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deepEqual.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable no-param-reassign */\n/** forked from https://github.com/lukeed/dequal to conside invalid dates as equal */\n\nvar has = Object.prototype.hasOwnProperty;\n\nfunction find(iter: any[], tar: any, key?: any) {\n for (key of iter.keys()) {\n if (deepEqual(key, tar)) return key;\n }\n}\n\nexport function deepEqual(foo: any, bar: any): boolean {\n var ctor, len, tmp;\n if (foo === bar) return true;\n\n if (foo && bar && (ctor = foo.constructor) === bar.constructor) {\n if (ctor === Date) return deepEqual(foo.getTime(), bar.getTime());\n if (ctor === RegExp) return foo.toString() === bar.toString();\n\n if (ctor === Array) {\n if ((len = foo.length) === bar.length) {\n while (len-- && deepEqual(foo[len], bar[len]));\n }\n return len === -1;\n }\n\n if (ctor === Set) {\n if (foo.size !== bar.size) {\n return false;\n }\n for (len of foo) {\n tmp = len;\n if (tmp && typeof tmp === 'object') {\n tmp = find(bar, tmp);\n if (!tmp) return false;\n }\n if (!bar.has(tmp)) return false;\n }\n return true;\n }\n\n if (ctor === Map) {\n if (foo.size !== bar.size) {\n return false;\n }\n for (len of foo) {\n tmp = len[0];\n if (tmp && typeof tmp === 'object') {\n tmp = find(bar, tmp);\n if (!tmp) return false;\n }\n if (!deepEqual(len[1], bar.get(tmp))) {\n return false;\n }\n }\n return true;\n }\n\n if (!ctor || typeof foo === 'object') {\n len = 0;\n for (ctor in foo) {\n if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;\n if (!(ctor in bar) || !deepEqual(foo[ctor], bar[ctor])) return false;\n }\n return Object.keys(bar).length === len;\n }\n }\n\n return foo !== foo && bar !== bar;\n}\n"],"mappings":";AAKA,IAAI,MAAM,OAAO,UAAU;AAE3B,SAAS,KAAK,MAAa,KAAU,KAAW;AAC9C,OAAK,OAAO,KAAK,KAAK,GAAG;AACvB,QAAI,UAAU,KAAK,GAAG;AAAG,aAAO;AAAA,EAClC;AACF;AAEO,SAAS,UAAU,KAAU,KAAmB;AACrD,MAAI,MAAM,KAAK;AACf,MAAI,QAAQ;AAAK,WAAO;AAExB,MAAI,OAAO,QAAQ,OAAO,IAAI,iBAAiB,IAAI,aAAa;AAC9D,QAAI,SAAS;AAAM,aAAO,UAAU,IAAI,QAAQ,GAAG,IAAI,QAAQ,CAAC;AAChE,QAAI,SAAS;AAAQ,aAAO,IAAI,SAAS,MAAM,IAAI,SAAS;AAE5D,QAAI,SAAS,OAAO;AAClB,WAAK,MAAM,IAAI,YAAY,IAAI,QAAQ;AACrC,eAAO,SAAS,UAAU,IAAI,GAAG,GAAG,IAAI,GAAG,CAAC;AAAE;AAAA,MAChD;AACA,aAAO,QAAQ;AAAA,IACjB;AAEA,QAAI,SAAS,KAAK;AAChB,UAAI,IAAI,SAAS,IAAI,MAAM;AACzB,eAAO;AAAA,MACT;AACA,WAAK,OAAO,KAAK;AACf,cAAM;AACN,YAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,gBAAM,KAAK,KAAK,GAAG;AACnB,cAAI,CAAC;AAAK,mBAAO;AAAA,QACnB;AACA,YAAI,CAAC,IAAI,IAAI,GAAG;AAAG,iBAAO;AAAA,MAC5B;AACA,aAAO;AAAA,IACT;AAEA,QAAI,SAAS,KAAK;AAChB,UAAI,IAAI,SAAS,IAAI,MAAM;AACzB,eAAO;AAAA,MACT;AACA,WAAK,OAAO,KAAK;AACf,cAAM,IAAI,CAAC;AACX,YAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,gBAAM,KAAK,KAAK,GAAG;AACnB,cAAI,CAAC;AAAK,mBAAO;AAAA,QACnB;AACA,YAAI,CAAC,UAAU,IAAI,CAAC,GAAG,IAAI,IAAI,GAAG,CAAC,GAAG;AACpC,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,QAAQ,OAAO,QAAQ,UAAU;AACpC,YAAM;AACN,WAAK,QAAQ,KAAK;AAChB,YAAI,IAAI,KAAK,KAAK,IAAI,KAAK,EAAE,OAAO,CAAC,IAAI,KAAK,KAAK,IAAI;AAAG,iBAAO;AACjE,YAAI,EAAE,QAAQ,QAAQ,CAAC,UAAU,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC;AAAG,iBAAO;AAAA,MACjE;AACA,aAAO,OAAO,KAAK,GAAG,EAAE,WAAW;AAAA,IACrC;AAAA,EACF;AAEA,SAAO,QAAQ,OAAO,QAAQ;AAChC;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/conversions.ts
|
|
2
|
+
function bytesToHumanReadable(bytes) {
|
|
3
|
+
if (bytes < 1024) {
|
|
4
|
+
return `${bytes} B`;
|
|
5
|
+
}
|
|
6
|
+
const kb = bytes / 1024;
|
|
7
|
+
if (kb < 1024) {
|
|
8
|
+
return `${kb.toFixed(2)} KB`;
|
|
9
|
+
}
|
|
10
|
+
const mb = kb / 1024;
|
|
11
|
+
if (mb < 1024) {
|
|
12
|
+
return `${mb.toFixed(2)} MB`;
|
|
13
|
+
}
|
|
14
|
+
const gb = mb / 1024;
|
|
15
|
+
return `${gb.toFixed(2)} GB`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
bytesToHumanReadable
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-MMKMF4GG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/conversions.ts"],"sourcesContent":["export function bytesToHumanReadable(bytes: number) {\n if (bytes < 1024) {\n return `${bytes} B`;\n }\n\n const kb = bytes / 1024;\n\n if (kb < 1024) {\n return `${kb.toFixed(2)} KB`;\n }\n\n const mb = kb / 1024;\n\n if (mb < 1024) {\n return `${mb.toFixed(2)} MB`;\n }\n\n const gb = mb / 1024;\n\n return `${gb.toFixed(2)} GB`;\n}\n"],"mappings":";AAAO,SAAS,qBAAqB,OAAe;AAClD,MAAI,QAAQ,MAAM;AAChB,WAAO,GAAG,KAAK;AAAA,EACjB;AAEA,QAAM,KAAK,QAAQ;AAEnB,MAAI,KAAK,MAAM;AACb,WAAO,GAAG,GAAG,QAAQ,CAAC,CAAC;AAAA,EACzB;AAEA,QAAM,KAAK,KAAK;AAEhB,MAAI,KAAK,MAAM;AACb,WAAO,GAAG,GAAG,QAAQ,CAAC,CAAC;AAAA,EACzB;AAEA,QAAM,KAAK,KAAK;AAEhB,SAAO,GAAG,GAAG,QAAQ,CAAC,CAAC;AACzB;","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/objUtils.ts
|
|
2
|
+
function objectTypedEntries(obj) {
|
|
3
|
+
return Object.entries(obj);
|
|
4
|
+
}
|
|
5
|
+
function pick(obj, keys, rename) {
|
|
6
|
+
const result = {};
|
|
7
|
+
if (!obj) {
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
for (const key of keys) {
|
|
11
|
+
result[rename?.[key] || key] = obj[key];
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
function mapArrayToObject(array, mapper) {
|
|
16
|
+
return Object.fromEntries(array.map(mapper));
|
|
17
|
+
}
|
|
18
|
+
function mapObjectToObject(obj, mapper) {
|
|
19
|
+
return Object.fromEntries(
|
|
20
|
+
objectTypedEntries(obj).map(([key, value]) => mapper(key, value))
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
function omit(obj, keys) {
|
|
24
|
+
const result = {};
|
|
25
|
+
for (const key of Object.keys(obj)) {
|
|
26
|
+
if (!keys.includes(key)) {
|
|
27
|
+
result[key] = obj[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
objectTypedEntries,
|
|
35
|
+
pick,
|
|
36
|
+
mapArrayToObject,
|
|
37
|
+
mapObjectToObject,
|
|
38
|
+
omit
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=chunk-SNAAKCTH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/objUtils.ts"],"sourcesContent":["export function objectTypedEntries<T extends Record<string, unknown>>(obj: T) {\n return Object.entries(obj) as [Extract<keyof T, string>, T[keyof T]][];\n}\n\nexport function pick<T, K extends keyof T>(\n obj: T | undefined,\n keys: K[],\n rename?: Partial<Record<K, string>>,\n): Record<string, unknown> {\n const result: any = {};\n\n if (!obj) {\n return result;\n }\n\n for (const key of keys) {\n result[rename?.[key] || key] = obj[key];\n }\n return result;\n}\n\nexport function mapArrayToObject<T, K extends string, O>(\n array: T[],\n mapper: (item: T, index: number) => [K, O],\n): Record<K, O> {\n return Object.fromEntries(array.map(mapper)) as any;\n}\n\nexport function mapObjectToObject<\n I extends Record<string | number | symbol, unknown>,\n K extends string | number | symbol,\n O,\n>(obj: I, mapper: (key: keyof I, value: I[keyof I]) => [K, O]): Record<K, O> {\n return Object.fromEntries(\n objectTypedEntries(obj).map(([key, value]) => mapper(key, value)),\n ) as any;\n}\n\nexport function omit<T extends Record<string, unknown>, K extends keyof T>(\n obj: T,\n keys: K[],\n): Omit<T, K> {\n const result: any = {};\n\n for (const key of Object.keys(obj)) {\n if (!keys.includes(key as K)) {\n result[key] = obj[key];\n }\n }\n\n return result;\n}\n"],"mappings":";AAAO,SAAS,mBAAsD,KAAQ;AAC5E,SAAO,OAAO,QAAQ,GAAG;AAC3B;AAEO,SAAS,KACd,KACA,MACA,QACyB;AACzB,QAAM,SAAc,CAAC;AAErB,MAAI,CAAC,KAAK;AACR,WAAO;AAAA,EACT;AAEA,aAAW,OAAO,MAAM;AACtB,WAAO,SAAS,GAAG,KAAK,GAAG,IAAI,IAAI,GAAG;AAAA,EACxC;AACA,SAAO;AACT;AAEO,SAAS,iBACd,OACA,QACc;AACd,SAAO,OAAO,YAAY,MAAM,IAAI,MAAM,CAAC;AAC7C;AAEO,SAAS,kBAId,KAAQ,QAAmE;AAC3E,SAAO,OAAO;AAAA,IACZ,mBAAmB,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,OAAO,KAAK,KAAK,CAAC;AAAA,EAClE;AACF;AAEO,SAAS,KACd,KACA,MACY;AACZ,QAAM,SAAc,CAAC;AAErB,aAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,QAAI,CAAC,KAAK,SAAS,GAAQ,GAAG;AAC5B,aAAO,GAAG,IAAI,IAAI,GAAG;AAAA,IACvB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
declare const colorToCodeASCII: {
|
|
2
|
+
red: string;
|
|
3
|
+
green: string;
|
|
4
|
+
yellow: string;
|
|
5
|
+
blue: string;
|
|
6
|
+
magenta: string;
|
|
7
|
+
cyan: string;
|
|
8
|
+
white: string;
|
|
9
|
+
black: string;
|
|
10
|
+
gray: string;
|
|
11
|
+
brightRed: string;
|
|
12
|
+
brightGreen: string;
|
|
13
|
+
brightYellow: string;
|
|
14
|
+
brightBlue: string;
|
|
15
|
+
brightMagenta: string;
|
|
16
|
+
brightCyan: string;
|
|
17
|
+
brightWhite: string;
|
|
18
|
+
};
|
|
19
|
+
declare function consoleColors(color: keyof typeof colorToCodeASCII, text: string): string;
|
|
20
|
+
declare function bold(text: string): string;
|
|
21
|
+
declare function underline(text: string): string;
|
|
22
|
+
declare const bgColorToCodeASCII: {
|
|
23
|
+
red: string;
|
|
24
|
+
green: string;
|
|
25
|
+
yellow: string;
|
|
26
|
+
blue: string;
|
|
27
|
+
magenta: string;
|
|
28
|
+
cyan: string;
|
|
29
|
+
white: string;
|
|
30
|
+
black: string;
|
|
31
|
+
gray: string;
|
|
32
|
+
brightRed: string;
|
|
33
|
+
brightGreen: string;
|
|
34
|
+
brightYellow: string;
|
|
35
|
+
brightBlue: string;
|
|
36
|
+
brightMagenta: string;
|
|
37
|
+
brightCyan: string;
|
|
38
|
+
brightWhite: string;
|
|
39
|
+
};
|
|
40
|
+
declare function bgColor(color: keyof typeof bgColorToCodeASCII, text: string): string;
|
|
41
|
+
declare const consoleFmt: {
|
|
42
|
+
color: typeof consoleColors;
|
|
43
|
+
bold: typeof bold;
|
|
44
|
+
underline: typeof underline;
|
|
45
|
+
bgColor: typeof bgColor;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { consoleFmt };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/consoleFmt.ts
|
|
2
|
+
var colorToCodeASCII = {
|
|
3
|
+
red: "\x1B[31m",
|
|
4
|
+
green: "\x1B[32m",
|
|
5
|
+
yellow: "\x1B[33m",
|
|
6
|
+
blue: "\x1B[34m",
|
|
7
|
+
magenta: "\x1B[35m",
|
|
8
|
+
cyan: "\x1B[36m",
|
|
9
|
+
white: "\x1B[37m",
|
|
10
|
+
black: "\x1B[30m",
|
|
11
|
+
gray: "\x1B[90m",
|
|
12
|
+
brightRed: "\x1B[91m",
|
|
13
|
+
brightGreen: "\x1B[92m",
|
|
14
|
+
brightYellow: "\x1B[93m",
|
|
15
|
+
brightBlue: "\x1B[94m",
|
|
16
|
+
brightMagenta: "\x1B[95m",
|
|
17
|
+
brightCyan: "\x1B[96m",
|
|
18
|
+
brightWhite: "\x1B[97m"
|
|
19
|
+
};
|
|
20
|
+
function consoleColors(color, text) {
|
|
21
|
+
return `${colorToCodeASCII[color]}${text}\x1B[0m`;
|
|
22
|
+
}
|
|
23
|
+
function bold(text) {
|
|
24
|
+
return `\x1B[1m${text}\x1B[0m`;
|
|
25
|
+
}
|
|
26
|
+
function underline(text) {
|
|
27
|
+
return `\x1B[4m${text}\x1B[0m`;
|
|
28
|
+
}
|
|
29
|
+
var bgColorToCodeASCII = {
|
|
30
|
+
red: "\x1B[41m",
|
|
31
|
+
green: "\x1B[42m",
|
|
32
|
+
yellow: "\x1B[43m",
|
|
33
|
+
blue: "\x1B[44m",
|
|
34
|
+
magenta: "\x1B[45m",
|
|
35
|
+
cyan: "\x1B[46m",
|
|
36
|
+
white: "\x1B[47m",
|
|
37
|
+
black: "\x1B[40m",
|
|
38
|
+
gray: "\x1B[100m",
|
|
39
|
+
brightRed: "\x1B[101m",
|
|
40
|
+
brightGreen: "\x1B[102m",
|
|
41
|
+
brightYellow: "\x1B[103m",
|
|
42
|
+
brightBlue: "\x1B[104m",
|
|
43
|
+
brightMagenta: "\x1B[105m",
|
|
44
|
+
brightCyan: "\x1B[106m",
|
|
45
|
+
brightWhite: "\x1B[107m"
|
|
46
|
+
};
|
|
47
|
+
function bgColor(color, text) {
|
|
48
|
+
const resetBgColor = "\x1B[49m";
|
|
49
|
+
return `${bgColorToCodeASCII[color]}${text}${resetBgColor}\x1B[0m`;
|
|
50
|
+
}
|
|
51
|
+
var consoleFmt = {
|
|
52
|
+
color: consoleColors,
|
|
53
|
+
bold,
|
|
54
|
+
underline,
|
|
55
|
+
bgColor
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
consoleFmt
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=consoleFmt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/consoleFmt.ts"],"sourcesContent":["const colorToCodeASCII = {\n red: '\\x1b[31m',\n green: '\\x1b[32m',\n yellow: '\\x1b[33m',\n blue: '\\x1b[34m',\n magenta: '\\x1b[35m',\n cyan: '\\x1b[36m',\n white: '\\x1b[37m',\n black: '\\x1b[30m',\n gray: '\\x1b[90m',\n brightRed: '\\x1b[91m',\n brightGreen: '\\x1b[92m',\n brightYellow: '\\x1b[93m',\n brightBlue: '\\x1b[94m',\n brightMagenta: '\\x1b[95m',\n brightCyan: '\\x1b[96m',\n brightWhite: '\\x1b[97m',\n};\n\nfunction consoleColors(color: keyof typeof colorToCodeASCII, text: string) {\n return `${colorToCodeASCII[color]}${text}\\x1b[0m`;\n}\n\nfunction bold(text: string) {\n return `\\x1b[1m${text}\\x1b[0m`;\n}\n\nfunction underline(text: string) {\n return `\\x1b[4m${text}\\x1b[0m`;\n}\n\nconst bgColorToCodeASCII = {\n red: '\\x1b[41m',\n green: '\\x1b[42m',\n yellow: '\\x1b[43m',\n blue: '\\x1b[44m',\n magenta: '\\x1b[45m',\n cyan: '\\x1b[46m',\n white: '\\x1b[47m',\n black: '\\x1b[40m',\n gray: '\\x1b[100m',\n brightRed: '\\x1b[101m',\n brightGreen: '\\x1b[102m',\n brightYellow: '\\x1b[103m',\n brightBlue: '\\x1b[104m',\n brightMagenta: '\\x1b[105m',\n brightCyan: '\\x1b[106m',\n brightWhite: '\\x1b[107m',\n};\n\nfunction bgColor(color: keyof typeof bgColorToCodeASCII, text: string) {\n const resetBgColor = '\\x1b[49m';\n return `${bgColorToCodeASCII[color]}${text}${resetBgColor}\\x1b[0m`;\n}\n\nexport const consoleFmt = {\n color: consoleColors,\n bold,\n underline,\n bgColor,\n};\n"],"mappings":";AAAA,IAAM,mBAAmB;AAAA,EACvB,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,aAAa;AACf;AAEA,SAAS,cAAc,OAAsC,MAAc;AACzE,SAAO,GAAG,iBAAiB,KAAK,CAAC,GAAG,IAAI;AAC1C;AAEA,SAAS,KAAK,MAAc;AAC1B,SAAO,UAAU,IAAI;AACvB;AAEA,SAAS,UAAU,MAAc;AAC/B,SAAO,UAAU,IAAI;AACvB;AAEA,IAAM,qBAAqB;AAAA,EACzB,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,YAAY;AAAA,EACZ,aAAa;AACf;AAEA,SAAS,QAAQ,OAAwC,MAAc;AACrE,QAAM,eAAe;AACrB,SAAO,GAAG,mBAAmB,KAAK,CAAC,GAAG,IAAI,GAAG,YAAY;AAC3D;AAEO,IAAM,aAAa;AAAA,EACxB,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type Options = {
|
|
2
|
+
maxCalls: number;
|
|
3
|
+
per: {
|
|
4
|
+
ms?: number;
|
|
5
|
+
seconds?: number;
|
|
6
|
+
minutes?: number;
|
|
7
|
+
hours?: number;
|
|
8
|
+
};
|
|
9
|
+
cleanupCheckSecsInterval?: number;
|
|
10
|
+
};
|
|
11
|
+
type ThrottleController = {
|
|
12
|
+
shouldSkip: (callId?: string | number | (string | number)[]) => boolean;
|
|
13
|
+
};
|
|
14
|
+
declare function createThrottleController({ maxCalls, per, cleanupCheckSecsInterval, }: Options): ThrottleController;
|
|
15
|
+
|
|
16
|
+
export { createThrottleController };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EnhancedMap
|
|
3
|
+
} from "./chunk-5FQYH3ZJ.js";
|
|
4
|
+
import "./chunk-JT3EBBCA.js";
|
|
5
|
+
|
|
6
|
+
// src/createThrottleController.ts
|
|
7
|
+
function createThrottleController({
|
|
8
|
+
maxCalls,
|
|
9
|
+
per,
|
|
10
|
+
cleanupCheckSecsInterval = 60 * 30
|
|
11
|
+
}) {
|
|
12
|
+
let msInterval = 0;
|
|
13
|
+
if (per.ms) {
|
|
14
|
+
msInterval = per.ms;
|
|
15
|
+
} else if (per.seconds) {
|
|
16
|
+
msInterval = per.seconds * 1e3;
|
|
17
|
+
} else if (per.minutes) {
|
|
18
|
+
msInterval = per.minutes * 1e3 * 60;
|
|
19
|
+
} else if (per.hours) {
|
|
20
|
+
msInterval = per.hours * 1e3 * 60 * 60;
|
|
21
|
+
}
|
|
22
|
+
if (msInterval === 0) {
|
|
23
|
+
throw new Error("Invalid interval");
|
|
24
|
+
}
|
|
25
|
+
let lastCleanupCheck = Date.now();
|
|
26
|
+
const windows = new EnhancedMap();
|
|
27
|
+
function cleanup(checkTime) {
|
|
28
|
+
const shouldCleanup = checkTime - lastCleanupCheck > cleanupCheckSecsInterval * 1e3;
|
|
29
|
+
if (!shouldCleanup)
|
|
30
|
+
return;
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
const now = Date.now();
|
|
33
|
+
lastCleanupCheck = now;
|
|
34
|
+
for (const [key, value] of windows) {
|
|
35
|
+
if (now - value.windowStartTime > msInterval) {
|
|
36
|
+
windows.delete(key);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, 2);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
shouldSkip(callId = "") {
|
|
43
|
+
const now = Date.now();
|
|
44
|
+
const serializedCallId = String(callId);
|
|
45
|
+
const window = windows.getOrInsert(serializedCallId, () => ({
|
|
46
|
+
windowStartTime: now,
|
|
47
|
+
calls: 0
|
|
48
|
+
}));
|
|
49
|
+
if (now - window.windowStartTime > msInterval) {
|
|
50
|
+
window.windowStartTime = now;
|
|
51
|
+
window.calls = 0;
|
|
52
|
+
}
|
|
53
|
+
window.calls++;
|
|
54
|
+
cleanup(now);
|
|
55
|
+
if (window.calls > maxCalls) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
},
|
|
60
|
+
_currentWindows: windows
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
createThrottleController
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=createThrottleController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createThrottleController.ts"],"sourcesContent":["import { EnhancedMap } from './enhancedMap';\n\ntype Options = {\n maxCalls: number;\n per: { ms?: number; seconds?: number; minutes?: number; hours?: number };\n cleanupCheckSecsInterval?: number;\n};\n\ntype ThrottleController = {\n shouldSkip: (callId?: string | number | (string | number)[]) => boolean;\n /** @internal */\n _currentWindows: EnhancedMap<\n string,\n { windowStartTime: number; calls: number }\n >;\n};\n\nexport function createThrottleController({\n maxCalls,\n per,\n cleanupCheckSecsInterval = 60 * 30,\n}: Options): ThrottleController {\n let msInterval = 0;\n\n if (per.ms) {\n msInterval = per.ms;\n } else if (per.seconds) {\n msInterval = per.seconds * 1000;\n } else if (per.minutes) {\n msInterval = per.minutes * 1000 * 60;\n } else if (per.hours) {\n msInterval = per.hours * 1000 * 60 * 60;\n }\n\n if (msInterval === 0) {\n throw new Error('Invalid interval');\n }\n\n let lastCleanupCheck = Date.now();\n\n const windows = new EnhancedMap<\n string,\n { windowStartTime: number; calls: number }\n >();\n\n function cleanup(checkTime: number) {\n const shouldCleanup =\n checkTime - lastCleanupCheck > cleanupCheckSecsInterval * 1000;\n\n if (!shouldCleanup) return;\n\n setTimeout(() => {\n const now = Date.now();\n\n lastCleanupCheck = now;\n\n for (const [key, value] of windows) {\n if (now - value.windowStartTime > msInterval) {\n windows.delete(key);\n }\n }\n }, 2);\n }\n\n return {\n shouldSkip(callId = '') {\n const now = Date.now();\n\n const serializedCallId = String(callId);\n\n const window = windows.getOrInsert(serializedCallId, () => ({\n windowStartTime: now,\n calls: 0,\n }));\n\n if (now - window.windowStartTime > msInterval) {\n window.windowStartTime = now;\n window.calls = 0;\n }\n\n window.calls++;\n\n cleanup(now);\n\n if (window.calls > maxCalls) {\n return true;\n }\n\n return false;\n },\n _currentWindows: windows,\n };\n}\n"],"mappings":";;;;;;AAiBO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AAAA,EACA,2BAA2B,KAAK;AAClC,GAAgC;AAC9B,MAAI,aAAa;AAEjB,MAAI,IAAI,IAAI;AACV,iBAAa,IAAI;AAAA,EACnB,WAAW,IAAI,SAAS;AACtB,iBAAa,IAAI,UAAU;AAAA,EAC7B,WAAW,IAAI,SAAS;AACtB,iBAAa,IAAI,UAAU,MAAO;AAAA,EACpC,WAAW,IAAI,OAAO;AACpB,iBAAa,IAAI,QAAQ,MAAO,KAAK;AAAA,EACvC;AAEA,MAAI,eAAe,GAAG;AACpB,UAAM,IAAI,MAAM,kBAAkB;AAAA,EACpC;AAEA,MAAI,mBAAmB,KAAK,IAAI;AAEhC,QAAM,UAAU,IAAI,YAGlB;AAEF,WAAS,QAAQ,WAAmB;AAClC,UAAM,gBACJ,YAAY,mBAAmB,2BAA2B;AAE5D,QAAI,CAAC;AAAe;AAEpB,eAAW,MAAM;AACf,YAAM,MAAM,KAAK,IAAI;AAErB,yBAAmB;AAEnB,iBAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,YAAI,MAAM,MAAM,kBAAkB,YAAY;AAC5C,kBAAQ,OAAO,GAAG;AAAA,QACpB;AAAA,MACF;AAAA,IACF,GAAG,CAAC;AAAA,EACN;AAEA,SAAO;AAAA,IACL,WAAW,SAAS,IAAI;AACtB,YAAM,MAAM,KAAK,IAAI;AAErB,YAAM,mBAAmB,OAAO,MAAM;AAEtC,YAAM,SAAS,QAAQ,YAAY,kBAAkB,OAAO;AAAA,QAC1D,iBAAiB;AAAA,QACjB,OAAO;AAAA,MACT,EAAE;AAEF,UAAI,MAAM,OAAO,kBAAkB,YAAY;AAC7C,eAAO,kBAAkB;AACzB,eAAO,QAAQ;AAAA,MACjB;AAEA,aAAO;AAEP,cAAQ,GAAG;AAEX,UAAI,OAAO,QAAQ,UAAU;AAC3B,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,IACA,iBAAiB;AAAA,EACnB;AACF;","names":[]}
|
package/dist/dedent.d.ts
ADDED
package/dist/dedent.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/dedent.ts
|
|
2
|
+
function dedent(strings, ...values) {
|
|
3
|
+
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
4
|
+
let result = "";
|
|
5
|
+
for (let i = 0; i < raw.length; i++) {
|
|
6
|
+
result += raw[i].replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`");
|
|
7
|
+
if (i < values.length) {
|
|
8
|
+
result += values[i];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const lines = result.split("\n");
|
|
12
|
+
let mindent = null;
|
|
13
|
+
lines.forEach((l) => {
|
|
14
|
+
const m = l.match(/^(\s+)\S+/);
|
|
15
|
+
if (m) {
|
|
16
|
+
const indent = m[1].length;
|
|
17
|
+
if (!mindent) {
|
|
18
|
+
mindent = indent;
|
|
19
|
+
} else {
|
|
20
|
+
mindent = Math.min(mindent, indent);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (mindent !== null) {
|
|
25
|
+
const m = mindent;
|
|
26
|
+
result = lines.map((l) => l.startsWith(" ") ? l.slice(m) : l).join("\n");
|
|
27
|
+
}
|
|
28
|
+
return result.trim().replace(/\\n/g, "\n");
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
dedent
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=dedent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/dedent.ts"],"sourcesContent":["// fork of https://github.com/dmnd/dedent\n\nexport function dedent(strings: string): string;\nexport function dedent(\n strings: TemplateStringsArray,\n ...values: string[]\n): string;\nexport function dedent(\n strings: TemplateStringsArray | string,\n ...values: string[]\n) {\n // $FlowFixMe: Flow doesn't undestand .raw\n const raw = typeof strings === 'string' ? [strings] : strings.raw;\n\n // first, perform interpolation\n let result = '';\n for (let i = 0; i < raw.length; i++) {\n result += raw[i]! // join lines when there is a suppressed newline\n .replace(/\\\\\\n[ \\t]*/g, '')\n // handle escaped backticks\n .replace(/\\\\`/g, '`');\n\n if (i < values.length) {\n result += values[i];\n }\n }\n\n // now strip indentation\n const lines = result.split('\\n');\n let mindent: number | null = null;\n lines.forEach((l) => {\n const m = l.match(/^(\\s+)\\S+/);\n if (m) {\n const indent = m[1]!.length;\n if (!mindent) {\n // this is the first indented line\n mindent = indent;\n } else {\n mindent = Math.min(mindent, indent);\n }\n }\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (mindent !== null) {\n const m = mindent; // appease Flow\n result = lines.map((l) => (l.startsWith(' ') ? l.slice(m) : l)).join('\\n');\n }\n\n return (\n result\n // dedent eats leading and trailing whitespace too\n .trim()\n // handle escaped newlines at the end to ensure they don't get stripped too\n .replace(/\\\\n/g, '\\n')\n );\n}\n"],"mappings":";AAOO,SAAS,OACd,YACG,QACH;AAEA,QAAM,MAAM,OAAO,YAAY,WAAW,CAAC,OAAO,IAAI,QAAQ;AAG9D,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,cAAU,IAAI,CAAC,EACZ,QAAQ,eAAe,EAAE,EAEzB,QAAQ,QAAQ,GAAG;AAEtB,QAAI,IAAI,OAAO,QAAQ;AACrB,gBAAU,OAAO,CAAC;AAAA,IACpB;AAAA,EACF;AAGA,QAAM,QAAQ,OAAO,MAAM,IAAI;AAC/B,MAAI,UAAyB;AAC7B,QAAM,QAAQ,CAAC,MAAM;AACnB,UAAM,IAAI,EAAE,MAAM,WAAW;AAC7B,QAAI,GAAG;AACL,YAAM,SAAS,EAAE,CAAC,EAAG;AACrB,UAAI,CAAC,SAAS;AAEZ,kBAAU;AAAA,MACZ,OAAO;AACL,kBAAU,KAAK,IAAI,SAAS,MAAM;AAAA,MACpC;AAAA,IACF;AAAA,EACF,CAAC;AAGD,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI;AACV,aAAS,MAAM,IAAI,CAAC,MAAO,EAAE,WAAW,GAAG,IAAI,EAAE,MAAM,CAAC,IAAI,CAAE,EAAE,KAAK,IAAI;AAAA,EAC3E;AAEA,SACE,OAEG,KAAK,EAEL,QAAQ,QAAQ,IAAI;AAE3B;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare const enhancedMapReject: unique symbol;
|
|
2
|
+
declare class EnhancedMap<K, V> extends Map<K, V> {
|
|
3
|
+
find(predicate: (value: V, key: K) => boolean): {
|
|
4
|
+
key: K;
|
|
5
|
+
value: V;
|
|
6
|
+
} | undefined;
|
|
7
|
+
setMultiple(values: Record<K & string, V>): this;
|
|
8
|
+
setMultiple(...values: [key: K, value: V][]): this;
|
|
9
|
+
getOrThrow(key: K): V;
|
|
10
|
+
getOrInsert(key: K, fallback: () => V): V;
|
|
11
|
+
toFilteredValues(predicate: (value: V, key: K) => boolean): V[];
|
|
12
|
+
toMap<T>(mapFunction: (value: V, key: K, reject: typeof enhancedMapReject) => T | typeof enhancedMapReject): T[];
|
|
13
|
+
toObjMap<ObjKey extends PropertyKey, ObjValue>(mapFunction: (value: V, key: K) => [key: ObjKey, value: ObjValue] | false): Record<ObjKey, ObjValue>;
|
|
14
|
+
toValues(): V[];
|
|
15
|
+
toKeys(): K[];
|
|
16
|
+
/** @deprecated, will be removed in v5 use `from` method instead */
|
|
17
|
+
static fromIterMap<T, K, V>(array: T[] | Iterable<T>, mapFunction: (item: T) => [key: K, value: V] | false): EnhancedMap<K, V>;
|
|
18
|
+
static from<T extends Record<string, unknown>, K extends keyof T>(array: T[] | Iterable<T> | null | undefined, key: K): EnhancedMap<T[K], T>;
|
|
19
|
+
static from<T, K, V>(array: T[] | Iterable<T> | null | undefined, mapFunction: (item: T) => [key: K, value: V] | false): EnhancedMap<K, V>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { EnhancedMap, enhancedMapReject };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/exhaustiveMatch.ts
|
|
2
|
+
function exhaustiveMatch(value) {
|
|
3
|
+
function matchWith(pattern) {
|
|
4
|
+
const result = pattern[value];
|
|
5
|
+
if (typeof result === "function") {
|
|
6
|
+
return result();
|
|
7
|
+
}
|
|
8
|
+
if (result === "_nxt") {
|
|
9
|
+
const keys = Object.keys(pattern);
|
|
10
|
+
const nextIndex = keys.indexOf(value) + 1;
|
|
11
|
+
for (let i = nextIndex; i < keys.length; i++) {
|
|
12
|
+
const nextMatch = pattern[keys[i]];
|
|
13
|
+
if (typeof nextMatch === "function") {
|
|
14
|
+
return nextMatch();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`Exhaustive match failed: no match for ${value}`);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
with: matchWith
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
exhaustiveMatch
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=exhaustiveMatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/exhaustiveMatch.ts"],"sourcesContent":["export function exhaustiveMatch<T extends string>(value: T) {\n type Pattern<R> = {\n [K in T]: (() => R) | '_nxt' | '_never';\n };\n\n /**\n * The pattern can be:\n * - a function that returns the result\n * - '_nxt' to try the next pattern\n * - '_never' to indicate that this pattern should never be matched\n */\n function matchWith<R>(pattern: Pattern<R>): R {\n const result = pattern[value];\n\n if (typeof result === 'function') {\n return result();\n }\n\n if (result === '_nxt') {\n const keys = Object.keys(pattern);\n\n const nextIndex = keys.indexOf(value) + 1;\n\n for (let i = nextIndex; i < keys.length; i++) {\n const nextMatch = pattern[keys[i] as T];\n\n if (typeof nextMatch === 'function') {\n return nextMatch();\n }\n }\n }\n\n throw new Error(`Exhaustive match failed: no match for ${value}`);\n }\n\n return {\n with: matchWith,\n };\n}\n"],"mappings":";AAAO,SAAS,gBAAkC,OAAU;AAW1D,WAAS,UAAa,SAAwB;AAC5C,UAAM,SAAS,QAAQ,KAAK;AAE5B,QAAI,OAAO,WAAW,YAAY;AAChC,aAAO,OAAO;AAAA,IAChB;AAEA,QAAI,WAAW,QAAQ;AACrB,YAAM,OAAO,OAAO,KAAK,OAAO;AAEhC,YAAM,YAAY,KAAK,QAAQ,KAAK,IAAI;AAExC,eAAS,IAAI,WAAW,IAAI,KAAK,QAAQ,KAAK;AAC5C,cAAM,YAAY,QAAQ,KAAK,CAAC,CAAM;AAEtC,YAAI,OAAO,cAAc,YAAY;AACnC,iBAAO,UAAU;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAEA,UAAM,IAAI,MAAM,yCAAyC,KAAK,EAAE;AAAA,EAClE;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,EACR;AACF;","names":[]}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
///<reference path="arrayUtils.d.ts" />
|
|
2
|
+
///<reference path="assertions.d.ts" />
|
|
3
|
+
///<reference path="castValues.d.ts" />
|
|
4
|
+
///<reference path="consoleFmt.d.ts" />
|
|
5
|
+
///<reference path="conversions.d.ts" />
|
|
6
|
+
///<reference path="createThrottleController.d.ts" />
|
|
7
|
+
///<reference path="dedent.d.ts" />
|
|
8
|
+
///<reference path="deepEqual.d.ts" />
|
|
9
|
+
///<reference path="enhancedMap.d.ts" />
|
|
10
|
+
///<reference path="exhaustiveMatch.d.ts" />
|
|
11
|
+
///<reference path="main.d.ts" />
|
|
12
|
+
///<reference path="mathUtils.d.ts" />
|
|
13
|
+
///<reference path="objUtils.d.ts" />
|
|
14
|
+
///<reference path="parallelAsyncResultCalls.d.ts" />
|
|
15
|
+
///<reference path="promiseUtils.d.ts" />
|
|
16
|
+
///<reference path="rsResult.d.ts" />
|
|
17
|
+
///<reference path="runShellCmd.d.ts" />
|
|
18
|
+
///<reference path="shallowEqual.d.ts" />
|
|
19
|
+
///<reference path="sleep.d.ts" />
|
|
20
|
+
///<reference path="stringUtils.d.ts" />
|
|
21
|
+
///<reference path="testUtils.d.ts" />
|
|
22
|
+
///<reference path="typingFnUtils.d.ts" />
|
|
23
|
+
///<reference path="typingTestUtils.d.ts" />
|
|
24
|
+
///<reference path="typingUtils.d.ts" />
|
|
25
|
+
///<reference path="yamlStringify.d.ts" />
|