@ls-stack/utils 1.13.2 → 2.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/dist/arrayUtils.cjs +91 -0
- package/dist/arrayUtils.d.cts +51 -0
- package/dist/arrayUtils.js +1 -2
- package/dist/assertions.cjs +99 -0
- package/dist/assertions.d.cts +17 -0
- package/dist/assertions.js +1 -2
- package/dist/castValues.cjs +41 -0
- package/dist/castValues.d.cts +4 -0
- package/dist/castValues.js +0 -1
- package/dist/{chunk-FYMTZQ42.js → chunk-4UGSP3L3.js} +0 -1
- package/dist/{chunk-HLFWWIDK.js → chunk-5DZT3Z5Z.js} +0 -1
- package/dist/{chunk-W7X6NSGR.js → chunk-AZBBTE33.js} +0 -1
- package/dist/{chunk-MMKMF4GG.js → chunk-IATIXMCE.js} +0 -1
- package/dist/chunk-JOBPQAI3.js +147 -0
- package/dist/{chunk-M74KKYE4.js → chunk-KCOXGSRA.js} +0 -1
- package/dist/{chunk-NKCC3375.js → chunk-NWXBMMHO.js} +0 -1
- package/dist/{chunk-SNAAKCTH.js → chunk-RVVH3MDA.js} +0 -1
- package/dist/{chunk-4QK76IRX.js → chunk-T5WDDPFI.js} +1 -6
- package/dist/{chunk-GLZ5MZC5.js → chunk-V2L472LS.js} +0 -30
- package/dist/consoleFmt.cjs +84 -0
- package/dist/consoleFmt.d.cts +48 -0
- package/dist/consoleFmt.js +0 -1
- package/dist/conversions.cjs +44 -0
- package/dist/conversions.d.cts +3 -0
- package/dist/conversions.js +1 -2
- package/dist/createThrottleController.cjs +183 -0
- package/dist/createThrottleController.d.cts +16 -0
- package/dist/createThrottleController.js +2 -3
- package/dist/debounce.cjs +125 -0
- package/dist/debounce.d.cts +45 -0
- package/dist/debounce.js +0 -1
- package/dist/dedent.cjs +57 -0
- package/dist/dedent.d.cts +4 -0
- package/dist/dedent.js +0 -1
- package/dist/deepEqual.cjs +88 -0
- package/dist/deepEqual.d.cts +4 -0
- package/dist/deepEqual.js +1 -2
- package/dist/enhancedMap.cjs +128 -0
- package/dist/enhancedMap.d.cts +20 -0
- package/dist/enhancedMap.d.ts +0 -2
- package/dist/enhancedMap.js +2 -3
- package/dist/exhaustiveMatch.cjs +55 -0
- package/dist/exhaustiveMatch.d.cts +6 -0
- package/dist/exhaustiveMatch.js +0 -1
- package/dist/interpolate.cjs +88 -0
- package/dist/interpolate.d.cts +11 -0
- package/dist/interpolate.js +2 -3
- package/dist/levenshtein.cjs +180 -0
- package/dist/levenshtein.d.cts +5 -0
- package/dist/levenshtein.js +0 -1
- package/dist/main.cjs +4 -0
- package/dist/main.d.cts +2 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.js +0 -1
- package/dist/mathUtils.cjs +50 -0
- package/dist/mathUtils.d.cts +6 -0
- package/dist/mathUtils.js +1 -2
- package/dist/objUtils.cjs +67 -0
- package/dist/objUtils.d.cts +7 -0
- package/dist/objUtils.js +1 -2
- package/dist/parallelAsyncCalls.cjs +265 -0
- package/dist/{parallelAsyncResultCalls.d.ts → parallelAsyncCalls.d.cts} +7 -7
- package/dist/parallelAsyncCalls.d.ts +76 -0
- package/dist/{parallelAsyncResultCalls.js → parallelAsyncCalls.js} +7 -9
- package/dist/promiseUtils.cjs +38 -0
- package/dist/promiseUtils.d.cts +8 -0
- package/dist/promiseUtils.js +0 -1
- package/dist/rsResult.cjs +179 -0
- package/dist/rsResult.d.cts +88 -0
- package/dist/rsResult.d.ts +33 -63
- package/dist/rsResult.js +6 -10
- package/dist/runShellCmd.cjs +127 -0
- package/dist/runShellCmd.d.cts +23 -0
- package/dist/runShellCmd.d.ts +2 -1
- package/dist/runShellCmd.js +9 -4
- package/dist/shallowEqual.cjs +88 -0
- package/dist/shallowEqual.d.cts +4 -0
- package/dist/shallowEqual.js +0 -1
- package/dist/sleep.cjs +32 -0
- package/dist/sleep.d.cts +3 -0
- package/dist/sleep.js +1 -2
- package/dist/stringUtils.cjs +66 -0
- package/dist/stringUtils.d.cts +16 -0
- package/dist/stringUtils.d.ts +1 -3
- package/dist/stringUtils.js +1 -4
- package/dist/testUtils.cjs +357 -0
- package/dist/testUtils.d.cts +38 -0
- package/dist/testUtils.js +5 -6
- package/dist/typingFnUtils.cjs +55 -0
- package/dist/typingFnUtils.d.cts +15 -0
- package/dist/typingFnUtils.js +0 -1
- package/dist/typingTestUtils.cjs +43 -0
- package/dist/typingTestUtils.d.cts +12 -0
- package/dist/typingTestUtils.js +0 -1
- package/dist/typingUtils.cjs +18 -0
- package/dist/typingUtils.d.cts +11 -0
- package/dist/typingUtils.js +0 -1
- package/dist/yamlStringify.cjs +346 -0
- package/dist/yamlStringify.d.cts +8 -0
- package/dist/yamlStringify.js +3 -4
- package/package.json +64 -34
- package/dist/arrayUtils.js.map +0 -1
- package/dist/assertions.js.map +0 -1
- package/dist/castValues.js.map +0 -1
- package/dist/chunk-4QK76IRX.js.map +0 -1
- package/dist/chunk-FYMTZQ42.js.map +0 -1
- package/dist/chunk-GLZ5MZC5.js.map +0 -1
- package/dist/chunk-HLFWWIDK.js.map +0 -1
- package/dist/chunk-I7ZDKDUM.js +0 -217
- package/dist/chunk-I7ZDKDUM.js.map +0 -1
- package/dist/chunk-M74KKYE4.js.map +0 -1
- package/dist/chunk-MMKMF4GG.js.map +0 -1
- package/dist/chunk-NKCC3375.js.map +0 -1
- package/dist/chunk-SNAAKCTH.js.map +0 -1
- package/dist/chunk-W7X6NSGR.js.map +0 -1
- package/dist/consoleFmt.js.map +0 -1
- package/dist/conversions.js.map +0 -1
- package/dist/createThrottleController.js.map +0 -1
- package/dist/debounce.js.map +0 -1
- package/dist/dedent.js.map +0 -1
- package/dist/deepEqual.js.map +0 -1
- package/dist/enhancedMap.js.map +0 -1
- package/dist/exhaustiveMatch.js.map +0 -1
- package/dist/interpolate.js.map +0 -1
- package/dist/levenshtein.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/mathUtils.js.map +0 -1
- package/dist/objUtils.js.map +0 -1
- package/dist/parallelAsyncResultCalls.js.map +0 -1
- package/dist/promiseUtils.js.map +0 -1
- package/dist/rsResult.js.map +0 -1
- package/dist/runShellCmd.js.map +0 -1
- package/dist/shallowEqual.js.map +0 -1
- package/dist/sleep.js.map +0 -1
- package/dist/stringUtils.js.map +0 -1
- package/dist/testUtils.js.map +0 -1
- package/dist/typingFnUtils.js.map +0 -1
- package/dist/typingTestUtils.js.map +0 -1
- package/dist/typingUtils.js.map +0 -1
- package/dist/yamlStringify.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Typescript utils",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -12,122 +12,152 @@
|
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"types": "./dist/main.d.ts",
|
|
14
14
|
"module": "./dist/main.js",
|
|
15
|
+
"main": "./dist/main.cjs",
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
17
18
|
"import": "./dist/main.js",
|
|
18
|
-
"types": "./dist/main.d.ts"
|
|
19
|
+
"types": "./dist/main.d.ts",
|
|
20
|
+
"require": "./dist/main.cjs"
|
|
19
21
|
},
|
|
20
22
|
"./arrayUtils": {
|
|
21
23
|
"import": "./dist/arrayUtils.js",
|
|
22
|
-
"types": "./dist/arrayUtils.d.ts"
|
|
24
|
+
"types": "./dist/arrayUtils.d.ts",
|
|
25
|
+
"require": "./dist/arrayUtils.cjs"
|
|
23
26
|
},
|
|
24
27
|
"./assertions": {
|
|
25
28
|
"import": "./dist/assertions.js",
|
|
26
|
-
"types": "./dist/assertions.d.ts"
|
|
29
|
+
"types": "./dist/assertions.d.ts",
|
|
30
|
+
"require": "./dist/assertions.cjs"
|
|
27
31
|
},
|
|
28
32
|
"./castValues": {
|
|
29
33
|
"import": "./dist/castValues.js",
|
|
30
|
-
"types": "./dist/castValues.d.ts"
|
|
34
|
+
"types": "./dist/castValues.d.ts",
|
|
35
|
+
"require": "./dist/castValues.cjs"
|
|
31
36
|
},
|
|
32
37
|
"./consoleFmt": {
|
|
33
38
|
"import": "./dist/consoleFmt.js",
|
|
34
|
-
"types": "./dist/consoleFmt.d.ts"
|
|
39
|
+
"types": "./dist/consoleFmt.d.ts",
|
|
40
|
+
"require": "./dist/consoleFmt.cjs"
|
|
35
41
|
},
|
|
36
42
|
"./conversions": {
|
|
37
43
|
"import": "./dist/conversions.js",
|
|
38
|
-
"types": "./dist/conversions.d.ts"
|
|
44
|
+
"types": "./dist/conversions.d.ts",
|
|
45
|
+
"require": "./dist/conversions.cjs"
|
|
39
46
|
},
|
|
40
47
|
"./createThrottleController": {
|
|
41
48
|
"import": "./dist/createThrottleController.js",
|
|
42
|
-
"types": "./dist/createThrottleController.d.ts"
|
|
49
|
+
"types": "./dist/createThrottleController.d.ts",
|
|
50
|
+
"require": "./dist/createThrottleController.cjs"
|
|
43
51
|
},
|
|
44
52
|
"./debounce": {
|
|
45
53
|
"import": "./dist/debounce.js",
|
|
46
|
-
"types": "./dist/debounce.d.ts"
|
|
54
|
+
"types": "./dist/debounce.d.ts",
|
|
55
|
+
"require": "./dist/debounce.cjs"
|
|
47
56
|
},
|
|
48
57
|
"./dedent": {
|
|
49
58
|
"import": "./dist/dedent.js",
|
|
50
|
-
"types": "./dist/dedent.d.ts"
|
|
59
|
+
"types": "./dist/dedent.d.ts",
|
|
60
|
+
"require": "./dist/dedent.cjs"
|
|
51
61
|
},
|
|
52
62
|
"./deepEqual": {
|
|
53
63
|
"import": "./dist/deepEqual.js",
|
|
54
|
-
"types": "./dist/deepEqual.d.ts"
|
|
64
|
+
"types": "./dist/deepEqual.d.ts",
|
|
65
|
+
"require": "./dist/deepEqual.cjs"
|
|
55
66
|
},
|
|
56
67
|
"./enhancedMap": {
|
|
57
68
|
"import": "./dist/enhancedMap.js",
|
|
58
|
-
"types": "./dist/enhancedMap.d.ts"
|
|
69
|
+
"types": "./dist/enhancedMap.d.ts",
|
|
70
|
+
"require": "./dist/enhancedMap.cjs"
|
|
59
71
|
},
|
|
60
72
|
"./exhaustiveMatch": {
|
|
61
73
|
"import": "./dist/exhaustiveMatch.js",
|
|
62
|
-
"types": "./dist/exhaustiveMatch.d.ts"
|
|
74
|
+
"types": "./dist/exhaustiveMatch.d.ts",
|
|
75
|
+
"require": "./dist/exhaustiveMatch.cjs"
|
|
63
76
|
},
|
|
64
77
|
"./interpolate": {
|
|
65
78
|
"import": "./dist/interpolate.js",
|
|
66
|
-
"types": "./dist/interpolate.d.ts"
|
|
79
|
+
"types": "./dist/interpolate.d.ts",
|
|
80
|
+
"require": "./dist/interpolate.cjs"
|
|
67
81
|
},
|
|
68
82
|
"./levenshtein": {
|
|
69
83
|
"import": "./dist/levenshtein.js",
|
|
70
|
-
"types": "./dist/levenshtein.d.ts"
|
|
84
|
+
"types": "./dist/levenshtein.d.ts",
|
|
85
|
+
"require": "./dist/levenshtein.cjs"
|
|
71
86
|
},
|
|
72
87
|
"./main": {
|
|
73
88
|
"import": "./dist/main.js",
|
|
74
|
-
"types": "./dist/main.d.ts"
|
|
89
|
+
"types": "./dist/main.d.ts",
|
|
90
|
+
"require": "./dist/main.cjs"
|
|
75
91
|
},
|
|
76
92
|
"./mathUtils": {
|
|
77
93
|
"import": "./dist/mathUtils.js",
|
|
78
|
-
"types": "./dist/mathUtils.d.ts"
|
|
94
|
+
"types": "./dist/mathUtils.d.ts",
|
|
95
|
+
"require": "./dist/mathUtils.cjs"
|
|
79
96
|
},
|
|
80
97
|
"./objUtils": {
|
|
81
98
|
"import": "./dist/objUtils.js",
|
|
82
|
-
"types": "./dist/objUtils.d.ts"
|
|
99
|
+
"types": "./dist/objUtils.d.ts",
|
|
100
|
+
"require": "./dist/objUtils.cjs"
|
|
83
101
|
},
|
|
84
|
-
"./
|
|
85
|
-
"import": "./dist/
|
|
86
|
-
"types": "./dist/
|
|
102
|
+
"./parallelAsyncCalls": {
|
|
103
|
+
"import": "./dist/parallelAsyncCalls.js",
|
|
104
|
+
"types": "./dist/parallelAsyncCalls.d.ts",
|
|
105
|
+
"require": "./dist/parallelAsyncCalls.cjs"
|
|
87
106
|
},
|
|
88
107
|
"./promiseUtils": {
|
|
89
108
|
"import": "./dist/promiseUtils.js",
|
|
90
|
-
"types": "./dist/promiseUtils.d.ts"
|
|
109
|
+
"types": "./dist/promiseUtils.d.ts",
|
|
110
|
+
"require": "./dist/promiseUtils.cjs"
|
|
91
111
|
},
|
|
92
112
|
"./rsResult": {
|
|
93
113
|
"import": "./dist/rsResult.js",
|
|
94
|
-
"types": "./dist/rsResult.d.ts"
|
|
114
|
+
"types": "./dist/rsResult.d.ts",
|
|
115
|
+
"require": "./dist/rsResult.cjs"
|
|
95
116
|
},
|
|
96
117
|
"./runShellCmd": {
|
|
97
118
|
"import": "./dist/runShellCmd.js",
|
|
98
|
-
"types": "./dist/runShellCmd.d.ts"
|
|
119
|
+
"types": "./dist/runShellCmd.d.ts",
|
|
120
|
+
"require": "./dist/runShellCmd.cjs"
|
|
99
121
|
},
|
|
100
122
|
"./shallowEqual": {
|
|
101
123
|
"import": "./dist/shallowEqual.js",
|
|
102
|
-
"types": "./dist/shallowEqual.d.ts"
|
|
124
|
+
"types": "./dist/shallowEqual.d.ts",
|
|
125
|
+
"require": "./dist/shallowEqual.cjs"
|
|
103
126
|
},
|
|
104
127
|
"./sleep": {
|
|
105
128
|
"import": "./dist/sleep.js",
|
|
106
|
-
"types": "./dist/sleep.d.ts"
|
|
129
|
+
"types": "./dist/sleep.d.ts",
|
|
130
|
+
"require": "./dist/sleep.cjs"
|
|
107
131
|
},
|
|
108
132
|
"./stringUtils": {
|
|
109
133
|
"import": "./dist/stringUtils.js",
|
|
110
|
-
"types": "./dist/stringUtils.d.ts"
|
|
134
|
+
"types": "./dist/stringUtils.d.ts",
|
|
135
|
+
"require": "./dist/stringUtils.cjs"
|
|
111
136
|
},
|
|
112
137
|
"./testUtils": {
|
|
113
138
|
"import": "./dist/testUtils.js",
|
|
114
|
-
"types": "./dist/testUtils.d.ts"
|
|
139
|
+
"types": "./dist/testUtils.d.ts",
|
|
140
|
+
"require": "./dist/testUtils.cjs"
|
|
115
141
|
},
|
|
116
142
|
"./typingFnUtils": {
|
|
117
143
|
"import": "./dist/typingFnUtils.js",
|
|
118
|
-
"types": "./dist/typingFnUtils.d.ts"
|
|
144
|
+
"types": "./dist/typingFnUtils.d.ts",
|
|
145
|
+
"require": "./dist/typingFnUtils.cjs"
|
|
119
146
|
},
|
|
120
147
|
"./typingTestUtils": {
|
|
121
148
|
"import": "./dist/typingTestUtils.js",
|
|
122
|
-
"types": "./dist/typingTestUtils.d.ts"
|
|
149
|
+
"types": "./dist/typingTestUtils.d.ts",
|
|
150
|
+
"require": "./dist/typingTestUtils.cjs"
|
|
123
151
|
},
|
|
124
152
|
"./typingUtils": {
|
|
125
153
|
"import": "./dist/typingUtils.js",
|
|
126
|
-
"types": "./dist/typingUtils.d.ts"
|
|
154
|
+
"types": "./dist/typingUtils.d.ts",
|
|
155
|
+
"require": "./dist/typingUtils.cjs"
|
|
127
156
|
},
|
|
128
157
|
"./yamlStringify": {
|
|
129
158
|
"import": "./dist/yamlStringify.js",
|
|
130
|
-
"types": "./dist/yamlStringify.d.ts"
|
|
159
|
+
"types": "./dist/yamlStringify.d.ts",
|
|
160
|
+
"require": "./dist/yamlStringify.cjs"
|
|
131
161
|
}
|
|
132
162
|
},
|
|
133
163
|
"engines": {
|
|
@@ -203,8 +233,8 @@
|
|
|
203
233
|
"objUtils": [
|
|
204
234
|
"./dist/objUtils.d.ts"
|
|
205
235
|
],
|
|
206
|
-
"
|
|
207
|
-
"./dist/
|
|
236
|
+
"parallelAsyncCalls": [
|
|
237
|
+
"./dist/parallelAsyncCalls.d.ts"
|
|
208
238
|
],
|
|
209
239
|
"promiseUtils": [
|
|
210
240
|
"./dist/promiseUtils.d.ts"
|
package/dist/arrayUtils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/assertions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/castValues.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/castValues.ts"],"sourcesContent":["export function castToString(value: unknown): string | null {\n return value !== null && value !== undefined ? String(value) : null;\n}\n\nexport function castToNumber(value: unknown): number | null {\n return isNumeric(value) ? Number(value) : null;\n}\n\nfunction isNumeric(num: unknown) {\n const str = String(num);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return !isNaN(str as any) && !isNaN(parseFloat(str));\n}\n"],"mappings":";AAAO,SAAS,aAAa,OAA+B;AAC1D,SAAO,UAAU,QAAQ,UAAU,SAAY,OAAO,KAAK,IAAI;AACjE;AAEO,SAAS,aAAa,OAA+B;AAC1D,SAAO,UAAU,KAAK,IAAI,OAAO,KAAK,IAAI;AAC5C;AAEA,SAAS,UAAU,KAAc;AAC/B,QAAM,MAAM,OAAO,GAAG;AAGtB,SAAO,CAAC,MAAM,GAAU,KAAK,CAAC,MAAM,WAAW,GAAG,CAAC;AACrD;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/enhancedMap.ts"],"sourcesContent":["import { isFunction } from './assertions';\n\nexport const enhancedMapReject = Symbol();\n\nexport class EnhancedMap<K, V> extends Map<K, V> {\n find(\n predicate: (value: V, key: K) => boolean,\n ): { key: K; value: V } | undefined {\n for (const [key, value] of this) {\n if (predicate(value, key)) {\n return { key, value };\n }\n }\n\n return undefined;\n }\n\n setMultiple(values: Record<K & string, V>): this;\n setMultiple(...values: [key: K, value: V][]): this;\n setMultiple(...values: [key: K, value: V][] | [Record<K & string, V>]): this {\n if (Array.isArray(values[0])) {\n for (const [key, value] of values as [key: K, value: V][]) {\n this.set(key, value);\n }\n } else {\n for (const [key, value] of Object.entries(values[0])) {\n this.set(key as K, value as V);\n }\n }\n\n return this;\n }\n\n getOrThrow(key: K): V {\n const value = this.get(key);\n\n if (value === undefined) {\n throw new Error(`Key ${key} not found in EnhancedMap`);\n }\n\n return value;\n }\n\n getOrInsert(key: K, fallback: () => V): V {\n if (!this.has(key)) {\n this.set(key, fallback());\n }\n\n return this.getOrThrow(key);\n }\n\n toFilteredValues(predicate: (value: V, key: K) => boolean): V[] {\n const values: V[] = [];\n\n for (const [key, value] of this) {\n if (predicate(value, key)) {\n values.push(value);\n }\n }\n\n return values;\n }\n\n toMap<T>(\n mapFunction: (\n value: V,\n key: K,\n reject: typeof enhancedMapReject,\n ) => T | typeof enhancedMapReject,\n ): T[] {\n const values: T[] = [];\n\n for (const [key, value] of this) {\n const result = mapFunction(value, key, enhancedMapReject);\n\n if (result !== enhancedMapReject) {\n values.push(result);\n }\n }\n\n return values;\n }\n\n toObjMap<ObjKey extends PropertyKey, ObjValue>(\n mapFunction: (value: V, key: K) => [key: ObjKey, value: ObjValue] | false,\n ): Record<ObjKey, ObjValue> {\n const values: Record<ObjKey, ObjValue> = {} as any;\n\n for (const [key, value] of this) {\n const result = mapFunction(value, key);\n\n if (result) {\n values[result[0]] = result[1];\n }\n }\n\n return values;\n }\n\n toValues(): V[] {\n return [...this.values()];\n }\n\n toKeys(): K[] {\n return [...this.keys()];\n }\n\n /** @deprecated, will be removed in v5 use `from` method instead */\n static fromIterMap<T, K, V>(\n array: T[] | Iterable<T>,\n mapFunction: (item: T) => [key: K, value: V] | false,\n ): EnhancedMap<K, V> {\n return this.from(array, mapFunction);\n }\n\n static from<T extends Record<string, unknown>, K extends keyof T>(\n array: T[] | Iterable<T> | null | undefined,\n key: K,\n ): EnhancedMap<T[K], T>;\n static from<T, K, V>(\n array: T[] | Iterable<T> | null | undefined,\n mapFunction: (item: T) => [key: K, value: V] | false,\n ): EnhancedMap<K, V>;\n static from(\n array: any[] | Iterable<any> | null | undefined,\n mapFunction: ((item: any) => [key: any, value: any] | false) | string,\n ): EnhancedMap<any, any> {\n const map = new EnhancedMap<any, any>();\n\n if (!array) return map;\n\n const isFn = isFunction(mapFunction);\n\n for (const item of array) {\n if (isFn) {\n const result = mapFunction(item);\n\n if (result) {\n map.set(result[0], result[1]);\n }\n } else {\n const key = item[mapFunction];\n\n if (key !== undefined) {\n map.set(key, item);\n }\n }\n }\n\n return map;\n }\n}\n"],"mappings":";;;;;AAEO,IAAM,oBAAoB,OAAO;AAEjC,IAAM,cAAN,MAAM,qBAA0B,IAAU;AAAA,EAC/C,KACE,WACkC;AAClC,eAAW,CAAC,KAAK,KAAK,KAAK,MAAM;AAC/B,UAAI,UAAU,OAAO,GAAG,GAAG;AACzB,eAAO,EAAE,KAAK,MAAM;AAAA,MACtB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAIA,eAAe,QAA8D;AAC3E,QAAI,MAAM,QAAQ,OAAO,CAAC,CAAC,GAAG;AAC5B,iBAAW,CAAC,KAAK,KAAK,KAAK,QAAgC;AACzD,aAAK,IAAI,KAAK,KAAK;AAAA,MACrB;AAAA,IACF,OAAO;AACL,iBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,CAAC,CAAC,GAAG;AACpD,aAAK,IAAI,KAAU,KAAU;AAAA,MAC/B;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,KAAW;AACpB,UAAM,QAAQ,KAAK,IAAI,GAAG;AAE1B,QAAI,UAAU,QAAW;AACvB,YAAM,IAAI,MAAM,OAAO,GAAG,2BAA2B;AAAA,IACvD;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,KAAQ,UAAsB;AACxC,QAAI,CAAC,KAAK,IAAI,GAAG,GAAG;AAClB,WAAK,IAAI,KAAK,SAAS,CAAC;AAAA,IAC1B;AAEA,WAAO,KAAK,WAAW,GAAG;AAAA,EAC5B;AAAA,EAEA,iBAAiB,WAA+C;AA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,QAAW;AACrB,cAAI,IAAI,KAAK,IAAI;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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,SAAU,QAAO;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,OAAQ,QAAO;AAE5B,QAAM,mBAAmB,OAAO,UAAU,YAAY,SAAS;AAE/D,SACE,OAAO,QAAQ,cACf,SAAS,SAAS,KAAK,IAAI,MAAM;AAErC;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/stringUtils.ts"],"sourcesContent":["type Arg = string | false | undefined | null;\n\n/**\n * A util to create more legible conditional concatenated strings\n *\n * @example\n * joinStrings('a', 'b', 'c') // 'abc'\n * joinStrings('a', false, 'c') // 'ac'\n * joinStrings('a', addBString ? 'b' : null, 'c') // 'ac' if addBString is false, 'abc' if addBString is true\n */\nexport function joinStrings(...args: (Arg | Arg[])[]) {\n const strings: string[] = [];\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n\n if (!arg) continue;\n\n if (Array.isArray(arg)) {\n strings.push(joinStrings(...arg));\n continue;\n }\n\n strings.push(arg);\n }\n\n return strings.join('');\n}\n\n// fork of https://github.com/dmnd/dedent\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\nexport function formatNum(num: number) {\n return num.toLocaleString('en-US', {\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n });\n}\n\nexport function isSnakeCase(str: string) {\n return /^[a-z0-9_]+$/.test(str);\n}\n\nexport function convertToSnakeCase(str: string) {\n return str\n .replace(/([A-Z])/g, '_$1')\n .replace(/[^a-z0-9_]/g, '')\n .toLowerCase();\n}\n\nexport function truncateString(str: string, length: number, ellipsis = '…') {\n if (str.length <= length) return str;\n\n return str.slice(0, length - 1) + ellipsis;\n}\n"],"mappings":";AAUO,SAAS,eAAe,MAAuB;AACpD,QAAM,UAAoB,CAAC;AAE3B,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,MAAM,KAAK,CAAC;AAElB,QAAI,CAAC,IAAK;AAEV,QAAI,MAAM,QAAQ,GAAG,GAAG;AACtB,cAAQ,KAAK,YAAY,GAAG,GAAG,CAAC;AAChC;AAAA,IACF;AAEA,YAAQ,KAAK,GAAG;AAAA,EAClB;AAEA,SAAO,QAAQ,KAAK,EAAE;AACxB;AAQO,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;AAEO,SAAS,UAAU,KAAa;AACrC,SAAO,IAAI,eAAe,SAAS;AAAA,IACjC,uBAAuB;AAAA,IACvB,uBAAuB;AAAA,EACzB,CAAC;AACH;AAEO,SAAS,YAAY,KAAa;AACvC,SAAO,eAAe,KAAK,GAAG;AAChC;AAEO,SAAS,mBAAmB,KAAa;AAC9C,SAAO,IACJ,QAAQ,YAAY,KAAK,EACzB,QAAQ,eAAe,EAAE,EACzB,YAAY;AACjB;AAEO,SAAS,eAAe,KAAa,QAAgB,WAAW,UAAK;AAC1E,MAAI,IAAI,UAAU,OAAQ,QAAO;AAEjC,SAAO,IAAI,MAAM,GAAG,SAAS,CAAC,IAAI;AACpC;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sleep.ts"],"sourcesContent":["export function sleep(ms: number) {\n return new Promise(resolve => setTimeout(resolve, ms))\n}\n"],"mappings":";AAAO,SAAS,MAAM,IAAY;AAChC,SAAO,IAAI,QAAQ,aAAW,WAAW,SAAS,EAAE,CAAC;AACvD;","names":[]}
|
package/dist/chunk-I7ZDKDUM.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
joinStrings
|
|
3
|
-
} from "./chunk-GLZ5MZC5.js";
|
|
4
|
-
import {
|
|
5
|
-
isObject
|
|
6
|
-
} from "./chunk-FYMTZQ42.js";
|
|
7
|
-
|
|
8
|
-
// src/rsResult.ts
|
|
9
|
-
function okUnwrapOr() {
|
|
10
|
-
return this.value;
|
|
11
|
-
}
|
|
12
|
-
function ok(value = void 0) {
|
|
13
|
-
return {
|
|
14
|
-
ok: true,
|
|
15
|
-
error: false,
|
|
16
|
-
value,
|
|
17
|
-
unwrapOrNull: okUnwrapOr,
|
|
18
|
-
unwrapOr: okUnwrapOr,
|
|
19
|
-
unwrap: okUnwrapOr
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function err(error) {
|
|
23
|
-
return {
|
|
24
|
-
ok: false,
|
|
25
|
-
error,
|
|
26
|
-
unwrapOrNull: () => null,
|
|
27
|
-
unwrapOr: (defaultValue) => defaultValue,
|
|
28
|
-
errorResult() {
|
|
29
|
-
return err(error);
|
|
30
|
-
},
|
|
31
|
-
normalizedErrorResult(normalizedErr2) {
|
|
32
|
-
return err(
|
|
33
|
-
"withMetadata" in normalizedErr2 && error instanceof NormalizedError ? new NormalizedErrorWithMetadata({
|
|
34
|
-
error,
|
|
35
|
-
metadata: {
|
|
36
|
-
...error.metadata,
|
|
37
|
-
...normalizedErr2.withMetadata
|
|
38
|
-
}
|
|
39
|
-
}) : new NormalizedError({
|
|
40
|
-
id: normalizedErr2.id,
|
|
41
|
-
message: normalizedErr2.message,
|
|
42
|
-
code: normalizedErr2.code,
|
|
43
|
-
cause: error instanceof Error ? error : void 0
|
|
44
|
-
})
|
|
45
|
-
);
|
|
46
|
-
},
|
|
47
|
-
unwrap: () => {
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function normalizedUnknownErr(error) {
|
|
53
|
-
return err(normalizeError(error));
|
|
54
|
-
}
|
|
55
|
-
function normalizedErr(idOrMessageOrErr, message) {
|
|
56
|
-
if (typeof idOrMessageOrErr === "object") {
|
|
57
|
-
return err(
|
|
58
|
-
new NormalizedError({
|
|
59
|
-
id: idOrMessageOrErr.id,
|
|
60
|
-
message: idOrMessageOrErr.message,
|
|
61
|
-
code: idOrMessageOrErr.code,
|
|
62
|
-
cause: idOrMessageOrErr.cause,
|
|
63
|
-
metadata: idOrMessageOrErr.metadata
|
|
64
|
-
})
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
if (message !== void 0) {
|
|
68
|
-
return err(
|
|
69
|
-
new NormalizedError({
|
|
70
|
-
id: idOrMessageOrErr,
|
|
71
|
-
message
|
|
72
|
-
})
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
return err(
|
|
76
|
-
new NormalizedError({
|
|
77
|
-
id: "unknown",
|
|
78
|
-
message: idOrMessageOrErr
|
|
79
|
-
})
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
async function unwrap(result) {
|
|
83
|
-
const unwrapped = await result;
|
|
84
|
-
if (unwrapped.ok) {
|
|
85
|
-
return unwrapped.value;
|
|
86
|
-
}
|
|
87
|
-
throw unwrapped.error;
|
|
88
|
-
}
|
|
89
|
-
var Result = {
|
|
90
|
-
ok,
|
|
91
|
-
err,
|
|
92
|
-
normalizedErr,
|
|
93
|
-
normalizedUnknownErr,
|
|
94
|
-
unwrap
|
|
95
|
-
};
|
|
96
|
-
function resultify(fn, errorNormalizer) {
|
|
97
|
-
try {
|
|
98
|
-
return ok(fn());
|
|
99
|
-
} catch (error) {
|
|
100
|
-
return err(
|
|
101
|
-
errorNormalizer ? errorNormalizer(error) : normalizeError(error)
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async function asyncResultify(fn, errorNormalizer) {
|
|
106
|
-
try {
|
|
107
|
-
return ok(await fn());
|
|
108
|
-
} catch (error) {
|
|
109
|
-
return err(
|
|
110
|
-
errorNormalizer ? errorNormalizer(error) : normalizeError(error)
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
var normalizedErrorSideEffects = void 0;
|
|
115
|
-
function setNormalizedErrorSideEffects(callback) {
|
|
116
|
-
normalizedErrorSideEffects = callback;
|
|
117
|
-
}
|
|
118
|
-
var NormalizedError = class extends Error {
|
|
119
|
-
id;
|
|
120
|
-
metadata;
|
|
121
|
-
cause;
|
|
122
|
-
code;
|
|
123
|
-
constructor({
|
|
124
|
-
id,
|
|
125
|
-
message,
|
|
126
|
-
metadata,
|
|
127
|
-
cause,
|
|
128
|
-
code = 0
|
|
129
|
-
}) {
|
|
130
|
-
super(message);
|
|
131
|
-
this.id = id;
|
|
132
|
-
this.name = "NormalizedError";
|
|
133
|
-
this.metadata = metadata;
|
|
134
|
-
this.cause = cause;
|
|
135
|
-
this.code = code;
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
if (normalizedErrorSideEffects) {
|
|
138
|
-
normalizedErrorSideEffects(this);
|
|
139
|
-
}
|
|
140
|
-
}, 1);
|
|
141
|
-
}
|
|
142
|
-
toString() {
|
|
143
|
-
return joinStrings(
|
|
144
|
-
!!this.code && `${this.code}#`,
|
|
145
|
-
String(this.id),
|
|
146
|
-
`: ${this.message}`,
|
|
147
|
-
!!this.cause && `
|
|
148
|
-
Caused by: ${this.cause}`,
|
|
149
|
-
!!this.metadata && `
|
|
150
|
-
Metadata: ${JSON.stringify(this.metadata)}`
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
toJSON() {
|
|
154
|
-
return {
|
|
155
|
-
id: this.id,
|
|
156
|
-
message: this.message,
|
|
157
|
-
metadata: this.metadata,
|
|
158
|
-
code: this.code,
|
|
159
|
-
cause: this.cause ? "toJSON" in this.cause ? this.cause : String(this.cause) : void 0
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
var NormalizedErrorWithMetadata = class extends NormalizedError {
|
|
164
|
-
metadata;
|
|
165
|
-
constructor(props) {
|
|
166
|
-
if ("error" in props) {
|
|
167
|
-
super({
|
|
168
|
-
id: props.error.id,
|
|
169
|
-
message: props.error.message,
|
|
170
|
-
cause: props.error.cause
|
|
171
|
-
});
|
|
172
|
-
this.metadata = props.metadata;
|
|
173
|
-
this.stack = props.error.stack;
|
|
174
|
-
} else {
|
|
175
|
-
super(props);
|
|
176
|
-
this.metadata = props.metadata;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
function normalizeError(error) {
|
|
181
|
-
if (error instanceof NormalizedError) return error;
|
|
182
|
-
if (typeof error === "string") {
|
|
183
|
-
return new NormalizedError({
|
|
184
|
-
id: "unknown",
|
|
185
|
-
message: error
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
if (error instanceof Error) {
|
|
189
|
-
return new NormalizedError({
|
|
190
|
-
id: error.name,
|
|
191
|
-
message: error.message,
|
|
192
|
-
cause: error
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
if (isObject(error)) {
|
|
196
|
-
return new NormalizedError({
|
|
197
|
-
id: "id" in error ? String(error.id) : "unknown",
|
|
198
|
-
message: "message" in error ? String(error.message) : JSON.stringify(error),
|
|
199
|
-
metadata: error
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
return new NormalizedError({
|
|
203
|
-
message: JSON.stringify(error),
|
|
204
|
-
id: "unknown"
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export {
|
|
209
|
-
Result,
|
|
210
|
-
resultify,
|
|
211
|
-
asyncResultify,
|
|
212
|
-
setNormalizedErrorSideEffects,
|
|
213
|
-
NormalizedError,
|
|
214
|
-
NormalizedErrorWithMetadata,
|
|
215
|
-
normalizeError
|
|
216
|
-
};
|
|
217
|
-
//# sourceMappingURL=chunk-I7ZDKDUM.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rsResult.ts"],"sourcesContent":["import { isObject } from './assertions';\nimport { joinStrings } from './stringUtils';\n\ntype Ok<T> = {\n ok: true;\n error: false;\n value: T;\n};\n\ntype NormalizedErrorResultProps = {\n id: string;\n message: string;\n code?: number;\n metadata?: ValidErrorMetadata;\n};\n\ntype IsExactlyAny<T> =\n boolean extends (T extends never ? true : false) ? true : false;\n\ntype Err<E extends ResultValidErrors> = {\n ok: false;\n error: E;\n errorResult: () => Result<any, E>;\n normalizedErrorResult: (\n normalizedErr: E extends NormalizedError ?\n { withMetadata: ValidErrorMetadata } | NormalizedErrorResultProps\n : NormalizedErrorResultProps,\n ) => Result<any, NormalizedError>;\n};\n\ntype Unwrap<E, T> =\n IsExactlyAny<E> extends true ? any\n : E extends Error ? () => T\n : unknown;\n\ntype ResultMethods<T, E> = {\n /** Returns the value if the result is Ok, otherwise returns null */\n unwrapOrNull: () => T | null;\n /** Returns the value if the result is Ok, otherwise returns the provided default value */\n unwrapOr: <R extends T>(defaultValue: R) => T | R;\n unwrap: Unwrap<E, T>;\n};\n\n/**\n * Util for implementing something similar to Result<T, E> in Rust, for better error handling.\n *\n * Usage:\n *\n * @example\n * function doSomething(): Result<string, Error> {\n * if (something) {\n * return ok('success');\n * }\n *\n * return err(new Error('something went wrong'));\n * }\n *\n * const result = doSomething();\n *\n * if (result.ok) {\n * // result.value is a string\n * } else {\n * // result.error is an Error\n * }\n */\nexport type Result<T, E extends ResultValidErrors = NormalizedError> =\n | OkResult<T, E, T>\n | ErrResult<E, T>;\n\nfunction okUnwrapOr<T>(this: Ok<T>) {\n return this.value;\n}\n\ntype OkResult<T, E extends ResultValidErrors, M = any> = Ok<T> &\n ResultMethods<M, E>;\n\ntype ResultValidErrors = Error | Record<string, unknown> | string[];\n\nfunction ok(): OkResult<void, any>;\nfunction ok<T>(value: T): OkResult<T, any>;\nfunction ok(value: any = undefined): OkResult<any, any> {\n return {\n ok: true,\n error: false,\n value,\n unwrapOrNull: okUnwrapOr,\n unwrapOr: okUnwrapOr,\n unwrap: okUnwrapOr,\n };\n}\n\ntype ErrResult<E extends ResultValidErrors, T = any> = Err<E> &\n ResultMethods<T, E>;\n\nfunction err<E extends ResultValidErrors>(error: E): ErrResult<E> {\n return {\n ok: false,\n error,\n unwrapOrNull: () => null,\n unwrapOr: (defaultValue) => defaultValue,\n errorResult() {\n return err(error);\n },\n normalizedErrorResult(normalizedErr) {\n return err(\n 'withMetadata' in normalizedErr && error instanceof NormalizedError ?\n new NormalizedErrorWithMetadata({\n error,\n metadata: {\n ...error.metadata,\n ...normalizedErr.withMetadata,\n },\n })\n : new NormalizedError({\n id: (normalizedErr as NormalizedErrorResultProps).id,\n message: (normalizedErr as NormalizedErrorResultProps).message,\n code: (normalizedErr as NormalizedErrorResultProps).code,\n cause: error instanceof Error ? error : undefined,\n }),\n );\n },\n unwrap: (() => {\n throw error;\n }) as any,\n };\n}\n\nfunction normalizedUnknownErr(error: unknown) {\n return err(normalizeError(error));\n}\n\nfunction normalizedErr(message: string): ErrResult<NormalizedError>;\nfunction normalizedErr<T extends string>(\n id: T,\n message: string,\n): ErrResult<NormalizedError<T>>;\nfunction normalizedErr<T extends string>(errorProps: {\n id: T;\n message: string;\n code?: number;\n cause?: Error;\n metadata?: ValidErrorMetadata;\n}): ErrResult<NormalizedError<T>>;\nfunction normalizedErr(\n idOrMessageOrErr:\n | string\n | {\n id: string;\n message: string;\n code?: number;\n metadata?: ValidErrorMetadata;\n cause?: Error;\n },\n message?: string,\n): ErrResult<NormalizedError> {\n if (typeof idOrMessageOrErr === 'object') {\n return err(\n new NormalizedError({\n id: idOrMessageOrErr.id,\n message: idOrMessageOrErr.message,\n code: idOrMessageOrErr.code,\n cause: idOrMessageOrErr.cause,\n metadata: idOrMessageOrErr.metadata,\n }),\n );\n }\n\n if (message !== undefined) {\n return err(\n new NormalizedError({\n id: idOrMessageOrErr,\n message,\n }),\n );\n }\n\n return err(\n new NormalizedError({\n id: 'unknown',\n message: idOrMessageOrErr,\n }),\n );\n}\n\n/** Unwraps a promise result */\nasync function unwrap<T>(result: Promise<Result<T, Error>>): Promise<T> {\n const unwrapped = await result;\n\n if (unwrapped.ok) {\n return unwrapped.value;\n }\n\n throw unwrapped.error;\n}\n\nexport const Result = {\n ok,\n err,\n normalizedErr,\n normalizedUnknownErr,\n unwrap,\n};\n\n/** transfor a function in a result function */\nexport function resultify<T, E extends ResultValidErrors = NormalizedError>(\n fn: () => T,\n errorNormalizer?: (err: unknown) => E,\n): Result<T, E> {\n try {\n return ok(fn());\n } catch (error) {\n return err(\n errorNormalizer ?\n errorNormalizer(error)\n : (normalizeError(error) as unknown as E),\n );\n }\n}\n\n/** transform a async function in a result function */\nexport async function asyncResultify<T, E extends Error = NormalizedError>(\n fn: () => Promise<T>,\n errorNormalizer?: (err: unknown) => E,\n): Promise<Result<Awaited<T>, E>> {\n try {\n return ok(await fn());\n } catch (error) {\n return err(\n errorNormalizer ?\n errorNormalizer(error)\n : (normalizeError(error) as unknown as E),\n );\n }\n}\n\nexport type ValidErrorMetadata = Record<string, unknown> | undefined;\n\nlet normalizedErrorSideEffects:\n | ((normalizedError: NormalizedError) => void)\n | undefined = undefined;\n\nexport function setNormalizedErrorSideEffects(\n callback: (normalizedError: NormalizedError) => void,\n) {\n normalizedErrorSideEffects = callback;\n}\n\nexport class NormalizedError<T = string> extends Error {\n id: T;\n metadata?: ValidErrorMetadata;\n cause?: Error;\n code: number;\n\n constructor({\n id,\n message,\n metadata,\n cause,\n code = 0,\n }: {\n id: T;\n message: string;\n metadata?: ValidErrorMetadata;\n cause?: Error;\n code?: number;\n }) {\n super(message);\n this.id = id;\n this.name = 'NormalizedError';\n this.metadata = metadata;\n this.cause = cause;\n this.code = code;\n\n setTimeout(() => {\n if (normalizedErrorSideEffects) {\n normalizedErrorSideEffects(this as NormalizedError);\n }\n }, 1);\n }\n\n toString() {\n return joinStrings(\n !!this.code && `${this.code}#`,\n String(this.id),\n `: ${this.message}`,\n !!this.cause && `\\n Caused by: ${this.cause}`,\n !!this.metadata && `\\n Metadata: ${JSON.stringify(this.metadata)}`,\n );\n }\n\n toJSON() {\n return {\n id: this.id,\n message: this.message,\n metadata: this.metadata,\n code: this.code,\n cause:\n this.cause ?\n 'toJSON' in this.cause ?\n this.cause\n : String(this.cause)\n : undefined,\n };\n }\n}\n\nexport class NormalizedErrorWithMetadata<\n M extends ValidErrorMetadata,\n T = string,\n> extends NormalizedError<T> {\n metadata: M;\n\n constructor(\n props:\n | {\n id: T;\n message: string;\n metadata: M;\n cause?: Error;\n }\n | {\n error: NormalizedError<T>;\n metadata: M;\n },\n ) {\n if ('error' in props) {\n super({\n id: props.error.id,\n message: props.error.message,\n cause: props.error.cause,\n });\n this.metadata = props.metadata;\n this.stack = props.error.stack;\n } else {\n super(props);\n this.metadata = props.metadata;\n }\n }\n}\n\nexport function normalizeError(error: unknown): NormalizedError {\n if (error instanceof NormalizedError) return error;\n\n if (typeof error === 'string') {\n return new NormalizedError({\n id: 'unknown',\n message: error,\n });\n }\n\n if (error instanceof Error) {\n return new NormalizedError({\n id: error.name,\n message: error.message,\n cause: error,\n });\n }\n\n if (isObject(error)) {\n return new NormalizedError({\n id: 'id' in error ? String(error.id) : 'unknown',\n message:\n 'message' in error ? String(error.message) : JSON.stringify(error),\n metadata: error,\n });\n }\n\n return new NormalizedError({\n message: JSON.stringify(error),\n id: 'unknown',\n });\n}\n"],"mappings":";;;;;;;;AAqEA,SAAS,aAA2B;AAClC,SAAO,KAAK;AACd;AASA,SAAS,GAAG,QAAa,QAA+B;AACtD,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,OAAO;AAAA,IACP;AAAA,IACA,cAAc;AAAA,IACd,UAAU;AAAA,IACV,QAAQ;AAAA,EACV;AACF;AAKA,SAAS,IAAiC,OAAwB;AAChE,SAAO;AAAA,IACL,IAAI;AAAA,IACJ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A,EACN,CAAC;AACH;","names":["normalizedErr"]}
|
|
@@ -1 +0,0 @@
|
|
|
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 consider invalid dates as equal */\n\nconst 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 let 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,IAAM,MAAM,OAAO,UAAU;AAE7B,SAAS,KAAK,MAAa,KAAU,KAAW;AA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AAI,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,EAAG,QAAO;AACjE,YAAI,EAAE,QAAQ,QAAQ,CAAC,UAAU,IAAI,IAAI,GAAG,IAAI,IAAI,CAAC,EAAG,QAAO;AAAA,MACjE;AACA,aAAO,OAAO,KAAK,GAAG,EAAE,WAAW;AAAA,IACrC;AAAA,EACF;AAEA,SAAO,QAAQ,OAAO,QAAQ;AAChC;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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\nexport function clampRange(num: number, v1: number, v2: number) {\n if (v2 > v1) {\n return clamp(num, v1, v2);\n }\n\n return clamp(num, v2, v1);\n}\n\nexport function clamp(num: number, min: number, max: number) {\n return (\n num > max ? max\n : num < min ? min\n : num\n );\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;AAEO,SAAS,WAAW,KAAa,IAAY,IAAY;AAC9D,MAAI,KAAK,IAAI;AACX,WAAO,MAAM,KAAK,IAAI,EAAE;AAAA,EAC1B;AAEA,SAAO,MAAM,KAAK,IAAI,EAAE;AAC1B;AAEO,SAAS,MAAM,KAAa,KAAa,KAAa;AAC3D,SACE,MAAM,MAAM,MACV,MAAM,MAAM,MACZ;AAEN;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/arrayUtils.ts"],"sourcesContent":["/**\n * allow to filter and map with better typing ergonomics\n *\n * In the `mapFilter` function return `false` to reject the item, or any other\n * value to map it.\n *\n * @example\n * // Filter reject and turn value into `value mapped`\n * const items = ['value', 'value', 'reject', 'reject'];\n *\n * const mappedItems = filterAndMap(items, (item) =>\n * item === 'reject'\n * ? false\n * : `${item} mapped`,\n * );\n *\n * mappedItems; // ['value mapped', 'value mapped']\n */\nexport function filterAndMap<T, R>(\n array: IterableIterator<T> | readonly T[],\n mapFilter: (item: T, index: number) => false | R,\n): R[] {\n const result: R[] = [];\n\n let i = -1;\n for (const item of array) {\n i += 1;\n const filterResult = mapFilter(item, i);\n\n if (filterResult !== false) {\n result.push(filterResult);\n }\n }\n\n return result;\n}\n\nexport type FilterAndMapReturn<T> = false | T;\n\ntype SortOrder = 'desc' | 'asc';\n\n/**\n * Sort an array based on a value\n *\n * Sort by `ascending` order by default\n *\n * Use `Infinity` as as wildcard to absolute max and min values\n *\n * @example\n * const items = [1, 3, 2, 4];\n *\n * const sortedItems = sortBy(items, (item) => item);\n * // [1, 2, 3, 4]\n *\n * const items2 = [{ a: 1, b: 2 }, { a: 2, b: 1 }, { a: 1, b: 1}]\n *\n * // return a array to sort by multiple values\n * const sortedItems = sortBy(items, (item) => [item.a, item.b]);\n **/\nexport function sortBy<T>(\n arr: T[],\n sortByValue: (item: T) => (number | string)[] | number | string,\n props: { order?: SortOrder | SortOrder[] } | SortOrder | SortOrder[] = 'asc',\n) {\n const order =\n Array.isArray(props) || typeof props === 'string' ?\n props\n : props.order ?? 'asc';\n\n return [...arr].sort((a, b) => {\n const _aPriority = sortByValue(a);\n const _bPriority = sortByValue(b);\n\n const aPriority = Array.isArray(_aPriority) ? _aPriority : [_aPriority];\n const bPriority = Array.isArray(_bPriority) ? _bPriority : [_bPriority];\n\n for (let i = 0; i < aPriority.length; i++) {\n const levelOrder: SortOrder =\n typeof order === 'string' ? order : order[i] ?? 'asc';\n\n const aP = aPriority[i] ?? 0;\n const bP = bPriority[i] ?? 0;\n\n if (aP === bP) {\n continue;\n }\n\n if (bP === Infinity || aP === -Infinity || aP < bP) {\n return levelOrder === 'asc' ? -1 : 1;\n }\n\n if (aP === Infinity || bP === -Infinity || aP > bP) {\n return levelOrder === 'asc' ? 1 : -1;\n }\n }\n\n return 0;\n });\n}\n\nexport function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][] {\n return array.map((item, i) => [item, array[i - 1] ?? null]);\n}\n\nexport function arrayWithPrevAndIndex<T>(\n array: T[],\n): { item: T; prev: T | null; index: number }[] {\n return array.map((item, i) => ({\n item,\n prev: array[i - 1] ?? null,\n index: i,\n }));\n}\n\nexport function isInArray<T, const U extends T>(\n value: T,\n oneOf: readonly U[],\n): value is U {\n for (let i = 0; i < oneOf.length; i++) {\n if (oneOf[i] === value) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":";AAkBO,SAAS,aACd,OACA,WACK;AACL,QAAM,SAAc,CAAC;AAErB,MAAI,IAAI;AACR,aAAW,QAAQ,OAAO;AACxB,SAAK;AACL,UAAM,eAAe,UAAU,MAAM,CAAC;AAEtC,QAAI,iBAAiB,OAAO;AAC1B,aAAO,KAAK,YAAY;AAAA,IAC1B;AAAA,EACF;AAEA,SAAO;AACT;AAwBO,SAAS,OACd,KACA,aACA,QAAuE,OACvE;AACA,QAAM,QACJ,MAAM,QAAQ,KAAK,KAAK,OAAO,UAAU,WACvC,QACA,MAAM,SAAS;AAEnB,SAAO,CAAC,GAAG,GAAG,EAAE,KAAK,CAAC,GAAG,MAAM;AAC7B,UAAM,aAAa,YAAY,CAAC;AAChC,UAAM,aAAa,YAAY,CAAC;AAEhC,UAAM,YAAY,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,UAAU;AACtE,UAAM,YAAY,MAAM,QAAQ,UAAU,IAAI,aAAa,CAAC,UAAU;AAEtE,aAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACzC,YAAM,aACJ,OAAO,UAAU,WAAW,QAAQ,MAAM,CAAC,KAAK;AAElD,YAAM,KAAK,UAAU,CAAC,KAAK;AAC3B,YAAM,KAAK,UAAU,CAAC,KAAK;AAE3B,UAAI,OAAO,IAAI;AACb;AAAA,MACF;AAEA,UAAI,OAAO,YAAY,OAAO,aAAa,KAAK,IAAI;AAClD,eAAO,eAAe,QAAQ,KAAK;AAAA,MACrC;AAEA,UAAI,OAAO,YAAY,OAAO,aAAa,KAAK,IAAI;AAClD,eAAO,eAAe,QAAQ,IAAI;AAAA,MACpC;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,cAAiB,OAA4C;AAC3E,SAAO,MAAM,IAAI,CAAC,MAAM,MAAM,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,IAAI,CAAC;AAC5D;AAEO,SAAS,sBACd,OAC8C;AAC9C,SAAO,MAAM,IAAI,CAAC,MAAM,OAAO;AAAA,IAC7B;AAAA,IACA,MAAM,MAAM,IAAI,CAAC,KAAK;AAAA,IACtB,OAAO;AAAA,EACT,EAAE;AACJ;AAEO,SAAS,UACd,OACA,OACY;AACZ,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,QAAI,MAAM,CAAC,MAAM,OAAO;AACtB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/consoleFmt.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
package/dist/conversions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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,cAAe;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/debounce.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/debounce.ts"],"sourcesContent":["export type DebounceOptions = {\n /**\n * @see _.leading\n */\n leading?: boolean;\n /**\n * @see _.maxWait\n */\n maxWait?: number;\n /**\n * @see _.trailing\n */\n trailing?: boolean;\n};\n\nexport interface DebouncedFunc<T extends (...args: any[]) => void> {\n /**\n * Call the original function, but applying the debounce rules.\n *\n * If the debounced function can be run immediately, this calls it and returns its return\n * value.\n *\n * Otherwise, it returns the return value of the last invocation, or undefined if the debounced\n * function was not invoked yet.\n */\n (...args: Parameters<T>): ReturnType<T> | undefined;\n\n /**\n * Throw away any pending invocation of the debounced function.\n */\n cancel: () => void;\n\n /**\n * If there is a pending invocation of the debounced function, invoke it immediately and return\n * its return value.\n *\n * Otherwise, return the value from the last invocation, or undefined if the debounced function\n * was never invoked.\n */\n flush: () => ReturnType<T> | undefined;\n}\n\n// forked from lodash/debounce\nexport function debounce<T extends (...args: any[]) => void>(\n func: T,\n wait: number,\n options?: DebounceOptions,\n): DebouncedFunc<T> {\n let lastArgs: IArguments | undefined;\n let lastThis: undefined;\n let maxWait: number | undefined;\n let result: any;\n let timerId: NodeJS.Timeout | undefined;\n let lastCallTime: number | undefined;\n let lastInvokeTime = 0;\n let leading = false;\n let maxing = false;\n let trailing = true;\n\n if (options) {\n leading = !!options.leading;\n maxing = 'maxWait' in options;\n maxWait = maxing ? Math.max(options.maxWait || 0, wait) : maxWait;\n trailing = 'trailing' in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time: number) {\n const args = lastArgs;\n const thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n result = func.apply(thisArg, args as any);\n return result;\n }\n\n function leadingEdge(time: number) {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = setTimeout(timerExpired, wait);\n // Invoke the leading edge.\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time: number) {\n const timeSinceLastCall = time - (lastCallTime ?? 0);\n const timeSinceLastInvoke = time - lastInvokeTime;\n const timeWaiting = wait - timeSinceLastCall;\n\n return maxing ?\n Math.min(timeWaiting, (maxWait ?? 0) - timeSinceLastInvoke)\n : timeWaiting;\n }\n\n function shouldInvoke(time: number) {\n const timeSinceLastCall = time - (lastCallTime ?? 0);\n const timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n lastCallTime === undefined ||\n timeSinceLastCall >= wait ||\n timeSinceLastCall < 0 ||\n (maxing && timeSinceLastInvoke >= (maxWait ?? 0))\n );\n }\n\n function timerExpired() {\n const time = Date.now();\n if (shouldInvoke(time)) {\n return trailingEdge(time);\n }\n // Restart the timer.\n timerId = setTimeout(timerExpired, remainingWait(time));\n }\n\n function trailingEdge(time: number) {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n return result;\n }\n\n function cancel() {\n if (timerId !== undefined) {\n clearTimeout(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush() {\n return timerId === undefined ? result : trailingEdge(Date.now());\n }\n\n function debounced(this: any) {\n const time = Date.now();\n const isInvoking = shouldInvoke(time);\n\n // eslint-disable-next-line prefer-rest-params\n lastArgs = arguments;\n // eslint-disable-next-line @typescript-eslint/no-this-alias -- this is a forked code, so a refactor is not worth it\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n return leadingEdge(lastCallTime);\n }\n if (maxing) {\n // Handle invocations in a tight loop.\n clearTimeout(timerId);\n timerId = setTimeout(timerExpired, wait);\n return invokeFunc(lastCallTime);\n }\n }\n if (timerId === undefined) {\n timerId = setTimeout(timerExpired, wait);\n }\n return result;\n }\n debounced.cancel = cancel;\n debounced.flush = flush;\n\n return debounced;\n}\n\nexport function isDebouncedFn<T extends (...args: any[]) => void>(\n fn: T,\n): fn is T & {\n cancel: () => void;\n flush: () => ReturnType<T> | undefined;\n} {\n return typeof fn === 'function' && 'cancel' in fn && 'flush' in fn;\n}\n"],"mappings":";AA2CO,SAAS,SACd,MACA,MACA,SACkB;AAClB,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI,iBAAiB;AACrB,MAAI,UAAU;AACd,MAAI,SAAS;AACb,MAAI,WAAW;AAEf,MAAI,SAAS;AACX,cAAU,CAAC,CAAC,QAAQ;AACpB,aAAS,aAAa;AACtB,cAAU,SAAS,KAAK,IAAI,QAAQ,WAAW,GAAG,IAAI,IAAI;AAC1D,eAAW,cAAc,UAAU,CAAC,CAAC,QAAQ,WAAW;AAAA,EAC1D;AAEA,WAAS,WAAW,MAAc;AAChC,UAAM,OAAO;AACb,UAAM,UAAU;AAEhB,eAAW,WAAW;AACtB,qBAAiB;AAEjB,aAAS,KAAK,MAAM,SAAS,IAAW;AACxC,WAAO;AAAA,EACT;AAEA,WAAS,YAAY,MAAc;AAEjC,qBAAiB;AAEjB,cAAU,WAAW,cAAc,IAAI;AAEvC,WAAO,UAAU,WAAW,IAAI,IAAI;AAAA,EACtC;AAEA,WAAS,cAAc,MAAc;AACnC,UAAM,oBAAoB,QAAQ,gBAAgB;AAClD,UAAM,sBAAsB,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AAElB,SAAO;AACT;AAEO,SAAS,cACd,IAIA;AACA,SAAO,OAAO,OAAO,cAAc,YAAY,MAAM,WAAW;AAClE;","names":[]}
|
package/dist/dedent.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dedent.ts"],"sourcesContent":["// fork of https://github.com/dmnd/dedent\n\nexport function dedent(\n strings: TemplateStringsArray,\n ...values: string[]\n): string;\nexport function dedent(strings: string): 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":[]}
|
package/dist/deepEqual.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/enhancedMap.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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 /** match with early evaluation of the values */\n function withObject<R>(pattern: Record<T, R>): R {\n return pattern[value];\n }\n\n return {\n with: matchWith,\n withObject,\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;AAGA,WAAS,WAAc,SAA0B;AAC/C,WAAO,QAAQ,KAAK;AAAA,EACtB;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN;AAAA,EACF;AACF;","names":[]}
|
package/dist/interpolate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interpolate.ts"],"sourcesContent":["import { invariant } from './assertions';\nimport { clampMax, clampMin, clampRange } from './mathUtils';\n\ntype Interval = [number, number];\n\nfunction mod(n: number, m: number) {\n return ((n % m) + m) % m;\n}\n\nexport function cyclicLerp(\n input: number,\n [inStart, inEnd]: Interval,\n [outStart, outEnd]: Interval,\n) {\n return (\n mod((input - inStart) / (inEnd - inStart), 1) * (outEnd - outStart) +\n outStart\n );\n}\n\nfunction findRange(input: number, inputRange: number[]) {\n for (let i = 1; i < inputRange.length - 1; i++) {\n if (inputRange[i]! >= input) return i - 1;\n }\n\n return inputRange.length - 2;\n}\n\ntype InterpolateArgs = {\n input: number;\n in: number[];\n out: number[];\n clamp?: boolean | 'start' | 'end';\n};\n\nexport function interpolate({\n input,\n in: inputRange,\n out,\n clamp = true,\n}: InterpolateArgs): number {\n invariant(\n inputRange.length === out.length,\n 'Ranges must have the same length',\n );\n\n const range = findRange(input, inputRange);\n const inStart = inputRange[range]!;\n const inEnd = inputRange[range + 1]!;\n const outStart = out[range]!;\n const outEnd = out[range + 1]!;\n\n const interpolatedValue =\n ((input - inStart) / (inEnd - inStart)) * (outEnd - outStart) + outStart;\n\n const outputIsAscending = outStart < outEnd;\n\n return (\n clamp === 'start' ?\n outputIsAscending ? clampMin(interpolatedValue, outStart)\n : clampMax(interpolatedValue, outStart)\n : clamp === 'end' ?\n outputIsAscending ? clampMax(interpolatedValue, outEnd)\n : clampMin(interpolatedValue, outEnd)\n : clamp ? clampRange(interpolatedValue, outStart, outEnd)\n : interpolatedValue\n );\n}\n"],"mappings":";;;;;;;;;;AAKA,SAAS,IAAI,GAAW,GAAW;AACjC,UAAS,IAAI,IAAK,KAAK;AACzB;AAEO,SAAS,WACd,OACA,CAAC,SAAS,KAAK,GACf,CAAC,UAAU,MAAM,GACjB;AACA,SACE,KAAK,QAAQ,YAAY,QAAQ,UAAU,CAAC,KAAK,SAAS,YAC1D;AAEJ;AAEA,SAAS,UAAU,OAAe,YAAsB;AACtD,WAAS,IAAI,GAAG,IAAI,WAAW,SAAS,GAAG,KAAK;AAC9C,QAAI,WAAW,CAAC,KAAM,MAAO,QAAO,IAAI;AAAA,EAC1C;AAEA,SAAO,WAAW,SAAS;AAC7B;AASO,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA,IAAI;AAAA,EACJ;AAAA,EACA,QAAQ;AACV,GAA4B;AAC1B;AAAA,IACE,WAAW,WAAW,IAAI;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,QAAQ,UAAU,OAAO,UAAU;AACzC,QAAM,UAAU,WAAW,KAAK;AAChC,QAAM,QAAQ,WAAW,QAAQ,CAAC;AAClC,QAAM,WAAW,IAAI,KAAK;AAC1B,QAAM,SAAS,IAAI,QAAQ,CAAC;AAE5B,QAAM,qBACF,QAAQ,YAAY,QAAQ,YAAa,SAAS,YAAY;AAElE,QAAM,oBAAoB,WAAW;AAErC,SACE,UAAU,UACR,oBAAoB,SAAS,mBAAmB,QAAQ,IACtD,SAAS,mBAAmB,QAAQ,IACtC,UAAU,QACV,oBAAoB,SAAS,mBAAmB,MAAM,IACpD,SAAS,mBAAmB,MAAM,IACpC,QAAQ,WAAW,mBAAmB,UAAU,MAAM,IACtD;AAEN;","names":[]}
|