@vinicunca/perkakas 0.4.4 → 0.5.3
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/index.d.cts +4629 -3246
- package/dist/index.d.mts +4629 -3246
- package/dist/index.d.ts +4629 -3246
- package/dist/index.mjs +1239 -1324
- package/dist/metadata.json +12090 -13268
- package/package.json +13 -16
- package/dist/index.cjs +0 -2375
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
const KEY_CODES = {
|
|
2
|
-
ALT: "Alt",
|
|
3
|
-
ARROW_DOWN: "ArrowDown",
|
|
4
|
-
ARROW_LEFT: "ArrowLeft",
|
|
5
|
-
ARROW_RIGHT: "ArrowRight",
|
|
6
|
-
ARROW_UP: "ArrowUp",
|
|
7
|
-
AT: "@",
|
|
8
|
-
BACKSPACE: "Backspace",
|
|
9
|
-
CTRL: "Control",
|
|
10
|
-
DELETE: "Delete",
|
|
11
|
-
END: "End",
|
|
12
|
-
ENTER: "Enter",
|
|
13
|
-
ESC: "Escape",
|
|
14
|
-
HOME: "Home",
|
|
15
|
-
KEY_F: "KEY_F",
|
|
16
|
-
META: "Meta",
|
|
17
|
-
PAGE_DOWN: "PageDown",
|
|
18
|
-
PAGE_UP: "PageUp",
|
|
19
|
-
SHIFT: "Shift",
|
|
20
|
-
SPACE: "Space",
|
|
21
|
-
TAB: "Tab"
|
|
22
|
-
};
|
|
23
|
-
|
|
24
1
|
function purry(fn, args, lazyFactory) {
|
|
25
2
|
const callArgs = Array.from(args);
|
|
26
3
|
const diff = fn.length - args.length;
|
|
@@ -35,6 +12,23 @@ function purry(fn, args, lazyFactory) {
|
|
|
35
12
|
throw new Error("Wrong number of arguments");
|
|
36
13
|
}
|
|
37
14
|
|
|
15
|
+
function addProp(...args) {
|
|
16
|
+
return purry(addProp_, args);
|
|
17
|
+
}
|
|
18
|
+
function addProp_(obj, prop, value) {
|
|
19
|
+
return {
|
|
20
|
+
...obj,
|
|
21
|
+
[prop]: value
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function add(...args) {
|
|
26
|
+
return purry(add_, args);
|
|
27
|
+
}
|
|
28
|
+
function add_(value, addend) {
|
|
29
|
+
return value + addend;
|
|
30
|
+
}
|
|
31
|
+
|
|
38
32
|
function allPass(...args) {
|
|
39
33
|
return purry(allPass_, args);
|
|
40
34
|
}
|
|
@@ -49,6 +43,113 @@ function anyPass_(data, fns) {
|
|
|
49
43
|
return fns.some((fn) => fn(data));
|
|
50
44
|
}
|
|
51
45
|
|
|
46
|
+
function isString(data) {
|
|
47
|
+
return typeof data === "string";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const RE_NUMBER_CHAR = /\d/;
|
|
51
|
+
const STR_SPLITTERS = ["-", "_", "/", "."];
|
|
52
|
+
function isUppercase(char = "") {
|
|
53
|
+
if (RE_NUMBER_CHAR.test(char)) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
return char !== char.toLowerCase();
|
|
57
|
+
}
|
|
58
|
+
function splitByCase(str, separators) {
|
|
59
|
+
const splitters = separators ?? STR_SPLITTERS;
|
|
60
|
+
const parts = [];
|
|
61
|
+
if (!str || !isString(str)) {
|
|
62
|
+
return parts;
|
|
63
|
+
}
|
|
64
|
+
let buff = "";
|
|
65
|
+
let previousUpper;
|
|
66
|
+
let previousSplitter;
|
|
67
|
+
for (const char of str) {
|
|
68
|
+
const isSplitter = splitters.includes(char);
|
|
69
|
+
if (isSplitter === true) {
|
|
70
|
+
parts.push(buff);
|
|
71
|
+
buff = "";
|
|
72
|
+
previousUpper = void 0;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const isUpper = isUppercase(char);
|
|
76
|
+
if (previousSplitter === false) {
|
|
77
|
+
if (previousUpper === false && isUpper === true) {
|
|
78
|
+
parts.push(buff);
|
|
79
|
+
buff = char;
|
|
80
|
+
previousUpper = isUpper;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
84
|
+
const lastChar = buff.at(-1);
|
|
85
|
+
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
86
|
+
buff = lastChar + char;
|
|
87
|
+
previousUpper = isUpper;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
buff += char;
|
|
92
|
+
previousUpper = isUpper;
|
|
93
|
+
previousSplitter = isSplitter;
|
|
94
|
+
}
|
|
95
|
+
parts.push(buff);
|
|
96
|
+
return parts;
|
|
97
|
+
}
|
|
98
|
+
function toUpperFirst(str) {
|
|
99
|
+
var _a;
|
|
100
|
+
return str ? ((_a = str[0]) == null ? void 0 : _a.toUpperCase()) + str.slice(1) : "";
|
|
101
|
+
}
|
|
102
|
+
function toLowerFirst(str) {
|
|
103
|
+
var _a;
|
|
104
|
+
return str ? ((_a = str[0]) == null ? void 0 : _a.toLowerCase()) + str.slice(1) : "";
|
|
105
|
+
}
|
|
106
|
+
function toPascalCase(str, opts) {
|
|
107
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => toUpperFirst((opts == null ? void 0 : opts.normalize) ? p.toLowerCase() : p)).join("") : "";
|
|
108
|
+
}
|
|
109
|
+
function toCamelCase(str, opts) {
|
|
110
|
+
return toLowerFirst(toPascalCase(str || "", opts));
|
|
111
|
+
}
|
|
112
|
+
function toKebabCase(str, joiner) {
|
|
113
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
114
|
+
}
|
|
115
|
+
function toSnakeCase(str) {
|
|
116
|
+
return toKebabCase(str || "", "_");
|
|
117
|
+
}
|
|
118
|
+
function toFlatCase(str) {
|
|
119
|
+
return toKebabCase(str || "", "");
|
|
120
|
+
}
|
|
121
|
+
function toTrainCase(str, opts) {
|
|
122
|
+
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => toUpperFirst((opts == null ? void 0 : opts.normalize) ? p.toLowerCase() : p)).join("-");
|
|
123
|
+
}
|
|
124
|
+
const titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
|
|
125
|
+
function toTitleCase(str, opts) {
|
|
126
|
+
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => titleCaseExceptions.test(p) ? p.toLowerCase() : toUpperFirst((opts == null ? void 0 : opts.normalize) ? p.toLowerCase() : p)).join(" ");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const MAX_PRECISION = 15;
|
|
130
|
+
function _withPrecision(roundingFn) {
|
|
131
|
+
return (value, precision) => {
|
|
132
|
+
if (precision === 0) {
|
|
133
|
+
return roundingFn(value);
|
|
134
|
+
}
|
|
135
|
+
if (!Number.isInteger(precision)) {
|
|
136
|
+
throw new TypeError(`precision must be an integer: ${precision}`);
|
|
137
|
+
}
|
|
138
|
+
if (precision > MAX_PRECISION || precision < -MAX_PRECISION) {
|
|
139
|
+
throw new RangeError(`precision must be between ${-MAX_PRECISION} and ${MAX_PRECISION}`);
|
|
140
|
+
}
|
|
141
|
+
if (Number.isNaN(value) || !Number.isFinite(value)) {
|
|
142
|
+
return roundingFn(value);
|
|
143
|
+
}
|
|
144
|
+
const multiplier = 10 ** precision;
|
|
145
|
+
return roundingFn(value * multiplier) / multiplier;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function ceil(...args) {
|
|
150
|
+
return purry(_withPrecision(Math.ceil), args);
|
|
151
|
+
}
|
|
152
|
+
|
|
52
153
|
function chunk(...args) {
|
|
53
154
|
return purry(chunk_, args);
|
|
54
155
|
}
|
|
@@ -62,86 +163,251 @@ function chunk_(array, size) {
|
|
|
62
163
|
return ret;
|
|
63
164
|
}
|
|
64
165
|
|
|
65
|
-
function
|
|
66
|
-
return purry(
|
|
166
|
+
function clamp(...args) {
|
|
167
|
+
return purry(clamp_, args);
|
|
67
168
|
}
|
|
68
|
-
function
|
|
69
|
-
|
|
169
|
+
function clamp_(value, { max, min }) {
|
|
170
|
+
if (min !== void 0 && value < min) {
|
|
171
|
+
return min;
|
|
172
|
+
}
|
|
173
|
+
if (max !== void 0 && value > max) {
|
|
174
|
+
return max;
|
|
175
|
+
}
|
|
176
|
+
return value;
|
|
70
177
|
}
|
|
71
178
|
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
179
|
+
function cloneRegExp_(pattern) {
|
|
180
|
+
return new RegExp(
|
|
181
|
+
pattern.source,
|
|
182
|
+
(pattern.global ? "g" : "") + (pattern.ignoreCase ? "i" : "") + (pattern.multiline ? "m" : "") + (pattern.sticky ? "y" : "") + (pattern.unicode ? "u" : "")
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
function clone_(value, refFrom, refTo, deep) {
|
|
186
|
+
function copy(copiedValue) {
|
|
187
|
+
const len = refFrom.length;
|
|
188
|
+
let idx = 0;
|
|
189
|
+
while (idx < len) {
|
|
190
|
+
if (value === refFrom[idx]) {
|
|
191
|
+
return refTo[idx];
|
|
192
|
+
}
|
|
193
|
+
idx += 1;
|
|
81
194
|
}
|
|
82
|
-
|
|
83
|
-
|
|
195
|
+
refFrom[idx + 1] = value;
|
|
196
|
+
refTo[idx + 1] = copiedValue;
|
|
197
|
+
for (const key in value) {
|
|
198
|
+
copiedValue[key] = deep ? clone_(value[key], refFrom, refTo, true) : value[key];
|
|
84
199
|
}
|
|
200
|
+
return copiedValue;
|
|
201
|
+
}
|
|
202
|
+
switch (type(value)) {
|
|
203
|
+
case "Object":
|
|
204
|
+
return copy({});
|
|
205
|
+
case "Array":
|
|
206
|
+
return copy([]);
|
|
207
|
+
case "Date":
|
|
208
|
+
return new Date(value.valueOf());
|
|
209
|
+
case "RegExp":
|
|
210
|
+
return cloneRegExp_(value);
|
|
211
|
+
default:
|
|
212
|
+
return value;
|
|
85
213
|
}
|
|
86
|
-
return out;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function differenceWith(...args) {
|
|
90
|
-
return purry(differenceWith_, args, differenceWith.lazy);
|
|
91
214
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
return reduceLazy(array, lazy);
|
|
215
|
+
function clone(value) {
|
|
216
|
+
return value != null && typeof value.clone === "function" ? value.clone() : clone_(value, [], [], true);
|
|
95
217
|
}
|
|
96
|
-
(
|
|
97
|
-
|
|
98
|
-
return
|
|
218
|
+
function type(val) {
|
|
219
|
+
if (val === null) {
|
|
220
|
+
return "Null";
|
|
99
221
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
function dropLast(...args) {
|
|
104
|
-
return purry(dropLast_, args);
|
|
105
|
-
}
|
|
106
|
-
function dropLast_(array, n) {
|
|
107
|
-
const copy = array.slice();
|
|
108
|
-
if (n > 0) {
|
|
109
|
-
copy.splice(-n);
|
|
222
|
+
if (val === void 0) {
|
|
223
|
+
return "Undefined";
|
|
110
224
|
}
|
|
111
|
-
return
|
|
225
|
+
return Object.prototype.toString.call(val).slice(8, -1);
|
|
112
226
|
}
|
|
113
227
|
|
|
114
|
-
function
|
|
115
|
-
return purry(
|
|
228
|
+
function concat(...args) {
|
|
229
|
+
return purry(concat_, args);
|
|
116
230
|
}
|
|
117
|
-
function
|
|
118
|
-
return
|
|
231
|
+
function concat_(arr1, arr2) {
|
|
232
|
+
return arr1.concat(arr2);
|
|
119
233
|
}
|
|
120
|
-
((drop2) => {
|
|
121
|
-
function lazy(n) {
|
|
122
|
-
let left = n;
|
|
123
|
-
return (value) => {
|
|
124
|
-
if (left > 0) {
|
|
125
|
-
left -= 1;
|
|
126
|
-
return { done: false, hasNext: false };
|
|
127
|
-
}
|
|
128
|
-
return { done: false, hasNext: true, next: value };
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
drop2.lazy = lazy;
|
|
132
|
-
})(drop || (drop = {}));
|
|
133
234
|
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
function hasAtLeastImplementation(data, minimum) {
|
|
138
|
-
return data.length >= minimum;
|
|
235
|
+
function purryOn(isArg, implementation, args) {
|
|
236
|
+
const callArgs = Array.from(args);
|
|
237
|
+
return isArg(args[0]) ? (data) => implementation(data, ...callArgs) : implementation(...callArgs);
|
|
139
238
|
}
|
|
140
239
|
|
|
141
|
-
function
|
|
142
|
-
|
|
240
|
+
function conditional(...args) {
|
|
241
|
+
return purryOn(isCase, conditionalImplementation, args);
|
|
143
242
|
}
|
|
144
|
-
|
|
243
|
+
function conditionalImplementation(data, ...cases) {
|
|
244
|
+
for (const [when, then] of cases) {
|
|
245
|
+
if (when(data)) {
|
|
246
|
+
return then(data);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
throw new Error("conditional: data failed for all cases");
|
|
250
|
+
}
|
|
251
|
+
function isCase(maybeCase) {
|
|
252
|
+
if (!Array.isArray(maybeCase)) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
const [when, then, ...rest] = maybeCase;
|
|
256
|
+
return typeof when === "function" && when.length <= 1 && typeof then === "function" && then.length <= 1 && rest.length === 0;
|
|
257
|
+
}
|
|
258
|
+
const trivialDefaultCase = () => void 0;
|
|
259
|
+
((conditional2) => {
|
|
260
|
+
function defaultCase(then = trivialDefaultCase) {
|
|
261
|
+
return [() => true, then];
|
|
262
|
+
}
|
|
263
|
+
conditional2.defaultCase = defaultCase;
|
|
264
|
+
})(conditional || (conditional = {}));
|
|
265
|
+
|
|
266
|
+
function debounce(func, {
|
|
267
|
+
maxWaitMs,
|
|
268
|
+
timing = "trailing",
|
|
269
|
+
waitMs
|
|
270
|
+
}) {
|
|
271
|
+
if (maxWaitMs !== void 0 && waitMs !== void 0 && maxWaitMs < waitMs) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`debounce: maxWaitMs (${maxWaitMs}) cannot be less than waitMs (${waitMs})`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
let coolDownTimeoutId;
|
|
277
|
+
let maxWaitTimeoutId;
|
|
278
|
+
let latestCallArgs;
|
|
279
|
+
let result;
|
|
280
|
+
function handleDebouncedCall(args) {
|
|
281
|
+
latestCallArgs = args;
|
|
282
|
+
if (maxWaitMs !== void 0 && maxWaitTimeoutId === void 0) {
|
|
283
|
+
maxWaitTimeoutId = setTimeout(handleInvoke, maxWaitMs);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function handleInvoke() {
|
|
287
|
+
if (latestCallArgs === void 0) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (maxWaitTimeoutId !== void 0) {
|
|
291
|
+
const timeoutId = maxWaitTimeoutId;
|
|
292
|
+
maxWaitTimeoutId = void 0;
|
|
293
|
+
clearTimeout(timeoutId);
|
|
294
|
+
}
|
|
295
|
+
const args = latestCallArgs;
|
|
296
|
+
latestCallArgs = void 0;
|
|
297
|
+
result = func(...args);
|
|
298
|
+
}
|
|
299
|
+
function handleCoolDownEnd() {
|
|
300
|
+
if (coolDownTimeoutId === void 0) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const timeoutId = coolDownTimeoutId;
|
|
304
|
+
coolDownTimeoutId = void 0;
|
|
305
|
+
clearTimeout(timeoutId);
|
|
306
|
+
if (latestCallArgs !== void 0) {
|
|
307
|
+
handleInvoke();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
get cachedValue() {
|
|
312
|
+
return result;
|
|
313
|
+
},
|
|
314
|
+
call: (...args) => {
|
|
315
|
+
if (coolDownTimeoutId === void 0) {
|
|
316
|
+
if (timing === "trailing") {
|
|
317
|
+
handleDebouncedCall(args);
|
|
318
|
+
} else {
|
|
319
|
+
result = func(...args);
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
if (timing !== "leading") {
|
|
323
|
+
handleDebouncedCall(args);
|
|
324
|
+
}
|
|
325
|
+
const timeoutId = coolDownTimeoutId;
|
|
326
|
+
coolDownTimeoutId = void 0;
|
|
327
|
+
clearTimeout(timeoutId);
|
|
328
|
+
}
|
|
329
|
+
coolDownTimeoutId = setTimeout(
|
|
330
|
+
handleCoolDownEnd,
|
|
331
|
+
// If waitMs is not defined but maxWaitMs *is* it means the user is only
|
|
332
|
+
// interested in the leaky-bucket nature of the debouncer which is
|
|
333
|
+
// achieved by setting waitMs === maxWaitMs. If both are not defined we
|
|
334
|
+
// default to 0 which would wait until the end of the execution frame.
|
|
335
|
+
waitMs ?? maxWaitMs ?? 0
|
|
336
|
+
);
|
|
337
|
+
return result;
|
|
338
|
+
},
|
|
339
|
+
cancel: () => {
|
|
340
|
+
if (coolDownTimeoutId !== void 0) {
|
|
341
|
+
const timeoutId = coolDownTimeoutId;
|
|
342
|
+
coolDownTimeoutId = void 0;
|
|
343
|
+
clearTimeout(timeoutId);
|
|
344
|
+
}
|
|
345
|
+
if (maxWaitTimeoutId !== void 0) {
|
|
346
|
+
const timeoutId = maxWaitTimeoutId;
|
|
347
|
+
maxWaitTimeoutId = void 0;
|
|
348
|
+
clearTimeout(timeoutId);
|
|
349
|
+
}
|
|
350
|
+
latestCallArgs = void 0;
|
|
351
|
+
},
|
|
352
|
+
flush: () => {
|
|
353
|
+
handleCoolDownEnd();
|
|
354
|
+
return result;
|
|
355
|
+
},
|
|
356
|
+
get isPending() {
|
|
357
|
+
return coolDownTimeoutId !== void 0;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function _reduceLazy(array, lazy, isIndexed = false) {
|
|
363
|
+
const out = [];
|
|
364
|
+
for (let index = 0; index < array.length; index++) {
|
|
365
|
+
const item = array[index];
|
|
366
|
+
const result = isIndexed ? lazy(item, index, array) : lazy(item);
|
|
367
|
+
if (result.hasMany === true) {
|
|
368
|
+
out.push(...result.next);
|
|
369
|
+
} else if (result.hasNext) {
|
|
370
|
+
out.push(result.next);
|
|
371
|
+
}
|
|
372
|
+
if (result.done) {
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return out;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function differenceWith(...args) {
|
|
380
|
+
return purry(differenceWith_, args, differenceWith.lazy);
|
|
381
|
+
}
|
|
382
|
+
function differenceWith_(array, other, isEquals) {
|
|
383
|
+
const lazy = differenceWith.lazy(other, isEquals);
|
|
384
|
+
return _reduceLazy(array, lazy);
|
|
385
|
+
}
|
|
386
|
+
((differenceWith2) => {
|
|
387
|
+
function lazy(other, isEquals) {
|
|
388
|
+
return (value) => other.every((otherValue) => !isEquals(value, otherValue)) ? { done: false, hasNext: true, next: value } : { done: false, hasNext: false };
|
|
389
|
+
}
|
|
390
|
+
differenceWith2.lazy = lazy;
|
|
391
|
+
})(differenceWith || (differenceWith = {}));
|
|
392
|
+
|
|
393
|
+
function divide(...args) {
|
|
394
|
+
return purry(divide_, args);
|
|
395
|
+
}
|
|
396
|
+
function divide_(value, divisor) {
|
|
397
|
+
return value / divisor;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function swapInPlace(data, i, j) {
|
|
401
|
+
[data[i], data[j]] = [data[j], data[i]];
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function hasAtLeast(...args) {
|
|
405
|
+
return purry(hasAtLeastImplementation, args);
|
|
406
|
+
}
|
|
407
|
+
function hasAtLeastImplementation(data, minimum) {
|
|
408
|
+
return data.length >= minimum;
|
|
409
|
+
}
|
|
410
|
+
|
|
145
411
|
function heapify(heap, compareFn) {
|
|
146
412
|
for (let i = Math.floor(heap.length / 2) - 1; i >= 0; i--) {
|
|
147
413
|
heapSiftDown(heap, i, compareFn);
|
|
@@ -216,7 +482,7 @@ function orderRuleComparer(primaryRule, secondaryRule, ...otherRules) {
|
|
|
216
482
|
if (comparator(projectedB, projectedA)) {
|
|
217
483
|
return -1;
|
|
218
484
|
}
|
|
219
|
-
return nextComparer
|
|
485
|
+
return (nextComparer == null ? void 0 : nextComparer(a, b)) ?? 0;
|
|
220
486
|
};
|
|
221
487
|
}
|
|
222
488
|
function isOrderRule(x) {
|
|
@@ -266,6 +532,17 @@ function dropLastWhile_(data, predicate) {
|
|
|
266
532
|
return [];
|
|
267
533
|
}
|
|
268
534
|
|
|
535
|
+
function dropLast(...args) {
|
|
536
|
+
return purry(dropLast_, args);
|
|
537
|
+
}
|
|
538
|
+
function dropLast_(array, n) {
|
|
539
|
+
const copy = array.slice();
|
|
540
|
+
if (n > 0) {
|
|
541
|
+
copy.splice(-n);
|
|
542
|
+
}
|
|
543
|
+
return copy;
|
|
544
|
+
}
|
|
545
|
+
|
|
269
546
|
function dropWhile(...args) {
|
|
270
547
|
return purry(dropWhile_, args);
|
|
271
548
|
}
|
|
@@ -278,7 +555,34 @@ function dropWhile_(data, predicate) {
|
|
|
278
555
|
return [];
|
|
279
556
|
}
|
|
280
557
|
|
|
281
|
-
function
|
|
558
|
+
function drop(...args) {
|
|
559
|
+
return purry(drop_, args, drop.lazy);
|
|
560
|
+
}
|
|
561
|
+
function drop_(array, n) {
|
|
562
|
+
return _reduceLazy(array, drop.lazy(n));
|
|
563
|
+
}
|
|
564
|
+
((drop2) => {
|
|
565
|
+
function lazy(n) {
|
|
566
|
+
let left = n;
|
|
567
|
+
return (value) => {
|
|
568
|
+
if (left > 0) {
|
|
569
|
+
left -= 1;
|
|
570
|
+
return { done: false, hasNext: false };
|
|
571
|
+
}
|
|
572
|
+
return { done: false, hasNext: true, next: value };
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
drop2.lazy = lazy;
|
|
576
|
+
})(drop || (drop = {}));
|
|
577
|
+
|
|
578
|
+
function entries(...args) {
|
|
579
|
+
return purry(Object.entries, args);
|
|
580
|
+
}
|
|
581
|
+
((entries2) => {
|
|
582
|
+
entries2.strict = entries2;
|
|
583
|
+
})(entries || (entries = {}));
|
|
584
|
+
|
|
585
|
+
function _toLazyIndexed(fn) {
|
|
282
586
|
return Object.assign(fn, { indexed: true });
|
|
283
587
|
}
|
|
284
588
|
|
|
@@ -287,14 +591,14 @@ function filter(...args) {
|
|
|
287
591
|
}
|
|
288
592
|
function filter_(indexed) {
|
|
289
593
|
return (array, fn) => {
|
|
290
|
-
return
|
|
594
|
+
return _reduceLazy(
|
|
291
595
|
array,
|
|
292
596
|
indexed ? filter.lazyIndexed(fn) : filter.lazy(fn),
|
|
293
597
|
indexed
|
|
294
598
|
);
|
|
295
599
|
};
|
|
296
600
|
}
|
|
297
|
-
function lazy_$
|
|
601
|
+
function lazy_$5(indexed) {
|
|
298
602
|
return (fn) => (value, index, array) => (indexed ? fn(value, index, array) : fn(value)) ? { done: false, hasNext: true, next: value } : { done: false, hasNext: false };
|
|
299
603
|
}
|
|
300
604
|
((filter2) => {
|
|
@@ -302,11 +606,11 @@ function lazy_$6(indexed) {
|
|
|
302
606
|
return purry(filter_(true), args, filter2.lazyIndexed);
|
|
303
607
|
}
|
|
304
608
|
filter2.indexed = indexed;
|
|
305
|
-
filter2.lazy = lazy_$
|
|
306
|
-
filter2.lazyIndexed =
|
|
609
|
+
filter2.lazy = lazy_$5(false);
|
|
610
|
+
filter2.lazyIndexed = _toLazyIndexed(lazy_$5(true));
|
|
307
611
|
})(filter || (filter = {}));
|
|
308
612
|
|
|
309
|
-
function
|
|
613
|
+
function _toSingle(fn) {
|
|
310
614
|
return Object.assign(fn, { single: true });
|
|
311
615
|
}
|
|
312
616
|
|
|
@@ -316,7 +620,7 @@ function findIndex(...args) {
|
|
|
316
620
|
function findIndex_(indexed) {
|
|
317
621
|
return (array, fn) => array.findIndex((item, index, input) => indexed ? fn(item, index, input) : fn(item));
|
|
318
622
|
}
|
|
319
|
-
function lazy_$
|
|
623
|
+
function lazy_$4(indexed) {
|
|
320
624
|
return (fn) => {
|
|
321
625
|
let actualIndex = 0;
|
|
322
626
|
return (value, index, array) => {
|
|
@@ -333,8 +637,8 @@ function lazy_$5(indexed) {
|
|
|
333
637
|
return purry(findIndex_(true), args, findIndex2.lazyIndexed);
|
|
334
638
|
}
|
|
335
639
|
findIndex2.indexed = indexed;
|
|
336
|
-
findIndex2.lazy =
|
|
337
|
-
findIndex2.lazyIndexed =
|
|
640
|
+
findIndex2.lazy = _toSingle(lazy_$4(false));
|
|
641
|
+
findIndex2.lazyIndexed = _toSingle(_toLazyIndexed(lazy_$4(true)));
|
|
338
642
|
})(findIndex || (findIndex = {}));
|
|
339
643
|
|
|
340
644
|
function findLastIndex(...args) {
|
|
@@ -383,7 +687,7 @@ function find(...args) {
|
|
|
383
687
|
function find_(indexed) {
|
|
384
688
|
return (array, fn) => array.find((item, index, input) => indexed ? fn(item, index, input) : fn(item));
|
|
385
689
|
}
|
|
386
|
-
function lazy_$
|
|
690
|
+
function lazy_$3(indexed) {
|
|
387
691
|
return (fn) => (value, index, array) => (indexed ? fn(value, index, array) : fn(value)) ? { done: true, hasNext: true, next: value } : { done: false, hasNext: false };
|
|
388
692
|
}
|
|
389
693
|
((find2) => {
|
|
@@ -391,26 +695,10 @@ function lazy_$4(indexed) {
|
|
|
391
695
|
return purry(find_(true), args, find2.lazyIndexed);
|
|
392
696
|
}
|
|
393
697
|
find2.indexed = indexed;
|
|
394
|
-
find2.lazy =
|
|
395
|
-
find2.lazyIndexed =
|
|
698
|
+
find2.lazy = _toSingle(lazy_$3(false));
|
|
699
|
+
find2.lazyIndexed = _toSingle(_toLazyIndexed(lazy_$3(true)));
|
|
396
700
|
})(find || (find = {}));
|
|
397
701
|
|
|
398
|
-
function first(...args) {
|
|
399
|
-
return purry(first_, args, first.lazy);
|
|
400
|
-
}
|
|
401
|
-
function first_([item]) {
|
|
402
|
-
return item;
|
|
403
|
-
}
|
|
404
|
-
((first2) => {
|
|
405
|
-
function lazy() {
|
|
406
|
-
return (value) => ({ done: true, hasNext: true, next: value });
|
|
407
|
-
}
|
|
408
|
-
first2.lazy = lazy;
|
|
409
|
-
((lazy2) => {
|
|
410
|
-
lazy2.single = true;
|
|
411
|
-
})(lazy = first2.lazy || (first2.lazy = {}));
|
|
412
|
-
})(first || (first = {}));
|
|
413
|
-
|
|
414
702
|
function firstBy(...args) {
|
|
415
703
|
return purryOrderRules(firstByImplementation, args);
|
|
416
704
|
}
|
|
@@ -428,33 +716,27 @@ function firstByImplementation(data, compareFn) {
|
|
|
428
716
|
return currentFirst;
|
|
429
717
|
}
|
|
430
718
|
|
|
431
|
-
function
|
|
432
|
-
return purry(
|
|
719
|
+
function first(...args) {
|
|
720
|
+
return purry(first_, args, first.lazy);
|
|
433
721
|
}
|
|
434
|
-
function
|
|
435
|
-
return
|
|
436
|
-
const out = {};
|
|
437
|
-
for (const [index, element] of array.entries()) {
|
|
438
|
-
const items = indexed ? fn(element, index, array) : fn(element);
|
|
439
|
-
for (const [key, value] of items) {
|
|
440
|
-
out[key] = value;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
return out;
|
|
444
|
-
};
|
|
722
|
+
function first_([item]) {
|
|
723
|
+
return item;
|
|
445
724
|
}
|
|
446
|
-
((
|
|
447
|
-
function
|
|
448
|
-
return
|
|
725
|
+
((first2) => {
|
|
726
|
+
function lazy() {
|
|
727
|
+
return (value) => ({ done: true, hasNext: true, next: value });
|
|
449
728
|
}
|
|
450
|
-
|
|
451
|
-
|
|
729
|
+
first2.lazy = lazy;
|
|
730
|
+
((lazy2) => {
|
|
731
|
+
lazy2.single = true;
|
|
732
|
+
})(lazy = first2.lazy || (first2.lazy = {}));
|
|
733
|
+
})(first || (first = {}));
|
|
452
734
|
|
|
453
735
|
function flatten(...args) {
|
|
454
736
|
return purry(flatten_, args, flatten.lazy);
|
|
455
737
|
}
|
|
456
738
|
function flatten_(items) {
|
|
457
|
-
return
|
|
739
|
+
return _reduceLazy(items, flatten.lazy());
|
|
458
740
|
}
|
|
459
741
|
((flatten2) => {
|
|
460
742
|
function lazy() {
|
|
@@ -486,7 +768,7 @@ function flattenDeep(...args) {
|
|
|
486
768
|
return purry(flattenDeep_, args, flattenDeep.lazy);
|
|
487
769
|
}
|
|
488
770
|
function flattenDeep_(items) {
|
|
489
|
-
return
|
|
771
|
+
return _reduceLazy(items, flattenDeep.lazy());
|
|
490
772
|
}
|
|
491
773
|
function flattenDeepValue_(value) {
|
|
492
774
|
if (!Array.isArray(value)) {
|
|
@@ -512,21 +794,50 @@ function flattenDeepValue_(value) {
|
|
|
512
794
|
flattenDeep2.lazy = lazy;
|
|
513
795
|
})(flattenDeep || (flattenDeep = {}));
|
|
514
796
|
|
|
515
|
-
function
|
|
516
|
-
return purry(
|
|
797
|
+
function floor(...args) {
|
|
798
|
+
return purry(_withPrecision(Math.floor), args);
|
|
517
799
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
indexed ? forEach.lazyIndexed(fn) : forEach.lazy(fn),
|
|
522
|
-
indexed
|
|
523
|
-
);
|
|
800
|
+
|
|
801
|
+
function forEachObj(...args) {
|
|
802
|
+
return purry(forEachObj_(false), args);
|
|
524
803
|
}
|
|
525
|
-
function
|
|
526
|
-
return (
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
804
|
+
function forEachObj_(indexed) {
|
|
805
|
+
return (data, fn) => {
|
|
806
|
+
for (const key in data) {
|
|
807
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
808
|
+
const { [key]: val } = data;
|
|
809
|
+
if (indexed) {
|
|
810
|
+
fn(val, key, data);
|
|
811
|
+
} else {
|
|
812
|
+
fn(val);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return data;
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
((forEachObj2) => {
|
|
820
|
+
function indexed(...args) {
|
|
821
|
+
return purry(forEachObj_(true), args);
|
|
822
|
+
}
|
|
823
|
+
forEachObj2.indexed = indexed;
|
|
824
|
+
})(forEachObj || (forEachObj = {}));
|
|
825
|
+
|
|
826
|
+
function forEach(...args) {
|
|
827
|
+
return purry(forEach_(false), args, forEach.lazy);
|
|
828
|
+
}
|
|
829
|
+
function forEach_(indexed) {
|
|
830
|
+
return (array, fn) => _reduceLazy(
|
|
831
|
+
array,
|
|
832
|
+
indexed ? forEach.lazyIndexed(fn) : forEach.lazy(fn),
|
|
833
|
+
indexed
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
function lazy_$2(indexed) {
|
|
837
|
+
return (fn) => (value, index, array) => {
|
|
838
|
+
if (indexed) {
|
|
839
|
+
fn(value, index, array);
|
|
840
|
+
} else {
|
|
530
841
|
fn(value);
|
|
531
842
|
}
|
|
532
843
|
return {
|
|
@@ -541,10 +852,35 @@ function lazy_$3(indexed) {
|
|
|
541
852
|
return purry(forEach_(true), args, forEach2.lazyIndexed);
|
|
542
853
|
}
|
|
543
854
|
forEach2.indexed = indexed;
|
|
544
|
-
forEach2.lazy = lazy_$
|
|
545
|
-
forEach2.lazyIndexed =
|
|
855
|
+
forEach2.lazy = lazy_$2(false);
|
|
856
|
+
forEach2.lazyIndexed = _toLazyIndexed(lazy_$2(true));
|
|
546
857
|
})(forEach || (forEach = {}));
|
|
547
858
|
|
|
859
|
+
function fromEntries(...args) {
|
|
860
|
+
return purry(fromEntriesImplementation, args);
|
|
861
|
+
}
|
|
862
|
+
function fromEntriesImplementation(entries) {
|
|
863
|
+
const out = {};
|
|
864
|
+
for (const [key, value] of entries) {
|
|
865
|
+
out[key] = value;
|
|
866
|
+
}
|
|
867
|
+
return out;
|
|
868
|
+
}
|
|
869
|
+
((fromEntries2) => {
|
|
870
|
+
fromEntries2.strict = fromEntries2;
|
|
871
|
+
})(fromEntries || (fromEntries = {}));
|
|
872
|
+
|
|
873
|
+
function fromKeys(...args) {
|
|
874
|
+
return purry(fromKeysImplementation, args);
|
|
875
|
+
}
|
|
876
|
+
function fromKeysImplementation(data, mapper) {
|
|
877
|
+
const result = {};
|
|
878
|
+
for (const key of data) {
|
|
879
|
+
result[key] = mapper(key);
|
|
880
|
+
}
|
|
881
|
+
return result;
|
|
882
|
+
}
|
|
883
|
+
|
|
548
884
|
function groupBy(...args) {
|
|
549
885
|
return purry(groupBy_(false), args);
|
|
550
886
|
}
|
|
@@ -574,6 +910,92 @@ function groupBy_(indexed) {
|
|
|
574
910
|
groupBy2.strict = groupBy2;
|
|
575
911
|
})(groupBy || (groupBy = {}));
|
|
576
912
|
|
|
913
|
+
function isDeepEqual(...args) {
|
|
914
|
+
return purry(isDeepEqualImplementation, args);
|
|
915
|
+
}
|
|
916
|
+
function isDeepEqualImplementation(data, other) {
|
|
917
|
+
if (data === other) {
|
|
918
|
+
return true;
|
|
919
|
+
}
|
|
920
|
+
if (typeof data === "number" && typeof other === "number") {
|
|
921
|
+
return data !== data && other !== other;
|
|
922
|
+
}
|
|
923
|
+
if (typeof data !== "object" || typeof other !== "object") {
|
|
924
|
+
return false;
|
|
925
|
+
}
|
|
926
|
+
if (data === null || other === null) {
|
|
927
|
+
return false;
|
|
928
|
+
}
|
|
929
|
+
if (Object.getPrototypeOf(data) !== Object.getPrototypeOf(other)) {
|
|
930
|
+
return false;
|
|
931
|
+
}
|
|
932
|
+
if (Array.isArray(data)) {
|
|
933
|
+
if (data.length !== other.length) {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
for (let i = 0; i < data.length; i++) {
|
|
937
|
+
if (!isDeepEqualImplementation(
|
|
938
|
+
data[i],
|
|
939
|
+
other[i]
|
|
940
|
+
)) {
|
|
941
|
+
return false;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
return true;
|
|
945
|
+
}
|
|
946
|
+
if (data instanceof Date) {
|
|
947
|
+
return data.getTime() === other.getTime();
|
|
948
|
+
}
|
|
949
|
+
if (data instanceof RegExp) {
|
|
950
|
+
return data.toString() === other.toString();
|
|
951
|
+
}
|
|
952
|
+
const keys = Object.keys(data);
|
|
953
|
+
if (keys.length !== Object.keys(other).length) {
|
|
954
|
+
return false;
|
|
955
|
+
}
|
|
956
|
+
for (const key of keys) {
|
|
957
|
+
if (!Object.prototype.hasOwnProperty.call(other, key)) {
|
|
958
|
+
return false;
|
|
959
|
+
}
|
|
960
|
+
if (!isDeepEqualImplementation(data[key], other[key])) {
|
|
961
|
+
return false;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return true;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
function hasSubObject(...args) {
|
|
968
|
+
return purry(_hasSubObject, args);
|
|
969
|
+
}
|
|
970
|
+
function _hasSubObject(data, subObject) {
|
|
971
|
+
for (const key of Object.keys(subObject)) {
|
|
972
|
+
if (!Object.prototype.hasOwnProperty.call(data, key)) {
|
|
973
|
+
return false;
|
|
974
|
+
}
|
|
975
|
+
if (!isDeepEqual(subObject[key], data[key])) {
|
|
976
|
+
return false;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return true;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
function humanReadableFileSize(bytes, base = 1e3) {
|
|
983
|
+
if (bytes < base) {
|
|
984
|
+
return `${bytes} B`;
|
|
985
|
+
}
|
|
986
|
+
const prefix = base === 1024 ? ["Ki", "Mi", "Gi"] : ["k", "M", "G"];
|
|
987
|
+
let unit = -1;
|
|
988
|
+
while (Math.abs(bytes) >= base && unit < prefix.length - 1) {
|
|
989
|
+
bytes /= base;
|
|
990
|
+
++unit;
|
|
991
|
+
}
|
|
992
|
+
return `${bytes.toFixed(1)} ${prefix[unit]}B`;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
function identity(value) {
|
|
996
|
+
return value;
|
|
997
|
+
}
|
|
998
|
+
|
|
577
999
|
function indexBy(...args) {
|
|
578
1000
|
return purry(indexBy_(false), args);
|
|
579
1001
|
}
|
|
@@ -612,7 +1034,7 @@ function intersectionWith(...args) {
|
|
|
612
1034
|
}
|
|
613
1035
|
function intersectionWith_(array, other, comparator) {
|
|
614
1036
|
const lazy = intersectionWith.lazy(other, comparator);
|
|
615
|
-
return
|
|
1037
|
+
return _reduceLazy(array, lazy);
|
|
616
1038
|
}
|
|
617
1039
|
((intersectionWith2) => {
|
|
618
1040
|
function lazy(other, comparator) {
|
|
@@ -621,101 +1043,229 @@ function intersectionWith_(array, other, comparator) {
|
|
|
621
1043
|
intersectionWith2.lazy = lazy;
|
|
622
1044
|
})(intersectionWith || (intersectionWith = {}));
|
|
623
1045
|
|
|
624
|
-
function
|
|
625
|
-
return purry(
|
|
1046
|
+
function invert(...args) {
|
|
1047
|
+
return purry(invert_, args);
|
|
626
1048
|
}
|
|
627
|
-
function
|
|
628
|
-
|
|
1049
|
+
function invert_(object) {
|
|
1050
|
+
const result = {};
|
|
1051
|
+
for (const key in object) {
|
|
1052
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
1053
|
+
result[object[key]] = key;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
return result;
|
|
629
1057
|
}
|
|
630
1058
|
|
|
631
|
-
function
|
|
632
|
-
return
|
|
633
|
-
}
|
|
634
|
-
function last_(array) {
|
|
635
|
-
return array[array.length - 1];
|
|
1059
|
+
function isArray(data) {
|
|
1060
|
+
return Array.isArray(data);
|
|
636
1061
|
}
|
|
637
1062
|
|
|
638
|
-
function
|
|
639
|
-
return
|
|
640
|
-
}
|
|
641
|
-
function length_(items) {
|
|
642
|
-
return "length" in items ? items.length : Array.from(items).length;
|
|
1063
|
+
function isBoolean(data) {
|
|
1064
|
+
return typeof data === "boolean";
|
|
643
1065
|
}
|
|
644
1066
|
|
|
645
|
-
function
|
|
646
|
-
return
|
|
647
|
-
}
|
|
648
|
-
function map_(indexed) {
|
|
649
|
-
return (array, fn) => {
|
|
650
|
-
return reduceLazy(
|
|
651
|
-
array,
|
|
652
|
-
indexed ? map.lazyIndexed(fn) : map.lazy(fn),
|
|
653
|
-
indexed
|
|
654
|
-
);
|
|
655
|
-
};
|
|
1067
|
+
function isDate(data) {
|
|
1068
|
+
return data instanceof Date;
|
|
656
1069
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
hasNext: true,
|
|
661
|
-
next: indexed ? fn(value, index, array) : fn(value)
|
|
662
|
-
});
|
|
1070
|
+
|
|
1071
|
+
function isDefined(data) {
|
|
1072
|
+
return data !== void 0 && data !== null;
|
|
663
1073
|
}
|
|
664
|
-
((
|
|
665
|
-
function
|
|
666
|
-
return
|
|
1074
|
+
((isDefined2) => {
|
|
1075
|
+
function strict(data) {
|
|
1076
|
+
return data !== void 0;
|
|
667
1077
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
map2.lazyIndexed = toLazyIndexed(lazy_$2(true));
|
|
671
|
-
map2.strict = map2;
|
|
672
|
-
})(map || (map = {}));
|
|
1078
|
+
isDefined2.strict = strict;
|
|
1079
|
+
})(isDefined || (isDefined = {}));
|
|
673
1080
|
|
|
674
|
-
function
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
for (const [index, element] of array.entries()) {
|
|
681
|
-
const [key, value] = indexed ? fn(element, index, array) : fn(element);
|
|
682
|
-
out[key] = value;
|
|
683
|
-
}
|
|
684
|
-
return out;
|
|
685
|
-
};
|
|
1081
|
+
function isObject(data) {
|
|
1082
|
+
if (typeof data !== "object" || data === null) {
|
|
1083
|
+
return false;
|
|
1084
|
+
}
|
|
1085
|
+
const proto = Object.getPrototypeOf(data);
|
|
1086
|
+
return proto === null || proto === Object.prototype;
|
|
686
1087
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
1088
|
+
|
|
1089
|
+
function isEmpty(data) {
|
|
1090
|
+
if (data === void 0) {
|
|
1091
|
+
return true;
|
|
690
1092
|
}
|
|
691
|
-
|
|
692
|
-
|
|
1093
|
+
if (isArray(data) || isString(data)) {
|
|
1094
|
+
return data.length === 0;
|
|
1095
|
+
}
|
|
1096
|
+
if (isObject(data)) {
|
|
1097
|
+
return Object.keys(data).length === 0;
|
|
1098
|
+
}
|
|
1099
|
+
return false;
|
|
1100
|
+
}
|
|
693
1101
|
|
|
694
|
-
function
|
|
695
|
-
return
|
|
696
|
-
let ret;
|
|
697
|
-
let retMax;
|
|
698
|
-
for (const [index, item] of array.entries()) {
|
|
699
|
-
const max = indexed ? fn(item, index, array) : fn(item);
|
|
700
|
-
if (retMax === void 0 || max > retMax) {
|
|
701
|
-
ret = item;
|
|
702
|
-
retMax = max;
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
return ret;
|
|
706
|
-
};
|
|
1102
|
+
function isError(data) {
|
|
1103
|
+
return data instanceof Error;
|
|
707
1104
|
}
|
|
708
|
-
|
|
709
|
-
|
|
1105
|
+
|
|
1106
|
+
function isFunction(data) {
|
|
1107
|
+
return typeof data === "function";
|
|
710
1108
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
1109
|
+
|
|
1110
|
+
function isIncludedIn(dataOrContainer, container) {
|
|
1111
|
+
if (container === void 0) {
|
|
1112
|
+
const asSet = new Set(dataOrContainer);
|
|
1113
|
+
return (data) => asSet.has(data);
|
|
714
1114
|
}
|
|
715
|
-
|
|
716
|
-
}
|
|
1115
|
+
return container.includes(dataOrContainer);
|
|
1116
|
+
}
|
|
717
1117
|
|
|
718
|
-
function
|
|
1118
|
+
function isNonNull(data) {
|
|
1119
|
+
return data !== null;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
function isNot(predicate) {
|
|
1123
|
+
return (data) => !predicate(data);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
function isNullish(data) {
|
|
1127
|
+
return data === null || data === void 0;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
function isNumber(data) {
|
|
1131
|
+
return typeof data === "number" && !Number.isNaN(data);
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
function isPromise(data) {
|
|
1135
|
+
return data instanceof Promise;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
function isSymbol(data) {
|
|
1139
|
+
return typeof data === "symbol";
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
function isTruthy(data) {
|
|
1143
|
+
return !!data;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
function join(...args) {
|
|
1147
|
+
return purry(joinImplementation, args);
|
|
1148
|
+
}
|
|
1149
|
+
function joinImplementation(data, glue) {
|
|
1150
|
+
return data.join(glue);
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
const KEY_CODES = {
|
|
1154
|
+
ALT: "Alt",
|
|
1155
|
+
ARROW_DOWN: "ArrowDown",
|
|
1156
|
+
ARROW_LEFT: "ArrowLeft",
|
|
1157
|
+
ARROW_RIGHT: "ArrowRight",
|
|
1158
|
+
ARROW_UP: "ArrowUp",
|
|
1159
|
+
AT: "@",
|
|
1160
|
+
BACKSPACE: "Backspace",
|
|
1161
|
+
CTRL: "Control",
|
|
1162
|
+
DELETE: "Delete",
|
|
1163
|
+
END: "End",
|
|
1164
|
+
ENTER: "Enter",
|
|
1165
|
+
ESC: "Escape",
|
|
1166
|
+
HOME: "Home",
|
|
1167
|
+
KEY_F: "KEY_F",
|
|
1168
|
+
META: "Meta",
|
|
1169
|
+
PAGE_DOWN: "PageDown",
|
|
1170
|
+
PAGE_UP: "PageUp",
|
|
1171
|
+
SHIFT: "Shift",
|
|
1172
|
+
SPACE: "Space",
|
|
1173
|
+
TAB: "Tab"
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
function keys(...args) {
|
|
1177
|
+
return purry(Object.keys, args);
|
|
1178
|
+
}
|
|
1179
|
+
((keys2) => {
|
|
1180
|
+
keys2.strict = keys2;
|
|
1181
|
+
})(keys || (keys = {}));
|
|
1182
|
+
|
|
1183
|
+
function last(...args) {
|
|
1184
|
+
return purry(last_, args);
|
|
1185
|
+
}
|
|
1186
|
+
function last_(array) {
|
|
1187
|
+
return array[array.length - 1];
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
function length(...args) {
|
|
1191
|
+
return purry(length_, args);
|
|
1192
|
+
}
|
|
1193
|
+
function length_(items) {
|
|
1194
|
+
return "length" in items ? items.length : Array.from(items).length;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function mapKeys(...args) {
|
|
1198
|
+
return purry(mapKeys_, args);
|
|
1199
|
+
}
|
|
1200
|
+
function mapKeys_(data, fn) {
|
|
1201
|
+
const out = {};
|
|
1202
|
+
for (const [key, value] of entries.strict(data)) {
|
|
1203
|
+
out[fn(key, value)] = value;
|
|
1204
|
+
}
|
|
1205
|
+
return out;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
function mapToObj(...args) {
|
|
1209
|
+
return purry(mapToObj_(false), args);
|
|
1210
|
+
}
|
|
1211
|
+
function mapToObj_(indexed) {
|
|
1212
|
+
return (array, fn) => {
|
|
1213
|
+
const out = {};
|
|
1214
|
+
for (const [index, element] of array.entries()) {
|
|
1215
|
+
const [key, value] = indexed ? fn(element, index, array) : fn(element);
|
|
1216
|
+
out[key] = value;
|
|
1217
|
+
}
|
|
1218
|
+
return out;
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
((mapToObj2) => {
|
|
1222
|
+
function indexed(...args) {
|
|
1223
|
+
return purry(mapToObj_(true), args);
|
|
1224
|
+
}
|
|
1225
|
+
mapToObj2.indexed = indexed;
|
|
1226
|
+
})(mapToObj || (mapToObj = {}));
|
|
1227
|
+
|
|
1228
|
+
function mapValues(...args) {
|
|
1229
|
+
return purry(mapValues_, args);
|
|
1230
|
+
}
|
|
1231
|
+
function mapValues_(data, fn) {
|
|
1232
|
+
const out = {};
|
|
1233
|
+
for (const [key, value] of entries.strict(data)) {
|
|
1234
|
+
out[key] = fn(value, key);
|
|
1235
|
+
}
|
|
1236
|
+
return out;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
function map(...args) {
|
|
1240
|
+
return purry(map_(false), args, map.lazy);
|
|
1241
|
+
}
|
|
1242
|
+
function map_(indexed) {
|
|
1243
|
+
return (array, fn) => {
|
|
1244
|
+
return _reduceLazy(
|
|
1245
|
+
array,
|
|
1246
|
+
indexed ? map.lazyIndexed(fn) : map.lazy(fn),
|
|
1247
|
+
indexed
|
|
1248
|
+
);
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
function lazy_$1(indexed) {
|
|
1252
|
+
return (fn) => (value, index, array) => ({
|
|
1253
|
+
done: false,
|
|
1254
|
+
hasNext: true,
|
|
1255
|
+
next: indexed ? fn(value, index, array) : fn(value)
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
((map2) => {
|
|
1259
|
+
function indexed(...args) {
|
|
1260
|
+
return purry(map_(true), args, map2.lazyIndexed);
|
|
1261
|
+
}
|
|
1262
|
+
map2.indexed = indexed;
|
|
1263
|
+
map2.lazy = lazy_$1(false);
|
|
1264
|
+
map2.lazyIndexed = _toLazyIndexed(lazy_$1(true));
|
|
1265
|
+
map2.strict = map2;
|
|
1266
|
+
})(map || (map = {}));
|
|
1267
|
+
|
|
1268
|
+
function meanBy_(indexed) {
|
|
719
1269
|
return (array, fn) => {
|
|
720
1270
|
if (array.length === 0) {
|
|
721
1271
|
return Number.NaN;
|
|
@@ -745,29 +1295,48 @@ function mergeAll(items) {
|
|
|
745
1295
|
return out;
|
|
746
1296
|
}
|
|
747
1297
|
|
|
748
|
-
function
|
|
749
|
-
return (
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
retMin = min;
|
|
757
|
-
}
|
|
1298
|
+
function mergeDeep(...args) {
|
|
1299
|
+
return purry(mergeDeepImplementation, args);
|
|
1300
|
+
}
|
|
1301
|
+
function mergeDeepImplementation(destination, source) {
|
|
1302
|
+
const output = { ...destination, ...source };
|
|
1303
|
+
for (const key in source) {
|
|
1304
|
+
if (!(key in destination)) {
|
|
1305
|
+
continue;
|
|
758
1306
|
}
|
|
759
|
-
|
|
760
|
-
|
|
1307
|
+
const { [key]: destinationValue } = destination;
|
|
1308
|
+
if (!isRecord(destinationValue)) {
|
|
1309
|
+
continue;
|
|
1310
|
+
}
|
|
1311
|
+
const { [key]: sourceValue } = source;
|
|
1312
|
+
if (!isRecord(sourceValue)) {
|
|
1313
|
+
continue;
|
|
1314
|
+
}
|
|
1315
|
+
output[key] = mergeDeepImplementation(destinationValue, sourceValue);
|
|
1316
|
+
}
|
|
1317
|
+
return output;
|
|
761
1318
|
}
|
|
762
|
-
function
|
|
763
|
-
return
|
|
1319
|
+
function isRecord(object) {
|
|
1320
|
+
return typeof object === "object" && object !== null && Object.getPrototypeOf(object) === Object.prototype;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
function merge(...args) {
|
|
1324
|
+
return purry(merge_, args);
|
|
1325
|
+
}
|
|
1326
|
+
function merge_(data, source) {
|
|
1327
|
+
return { ...data, ...source };
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
function multiply(...args) {
|
|
1331
|
+
return purry(multiply_, args);
|
|
1332
|
+
}
|
|
1333
|
+
function multiply_(value, multiplicand) {
|
|
1334
|
+
return value * multiplicand;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
function noop() {
|
|
1338
|
+
return void 0;
|
|
764
1339
|
}
|
|
765
|
-
((minBy2) => {
|
|
766
|
-
function indexed(...args) {
|
|
767
|
-
return purry(minBy_(true), args);
|
|
768
|
-
}
|
|
769
|
-
minBy2.indexed = indexed;
|
|
770
|
-
})(minBy || (minBy = {}));
|
|
771
1340
|
|
|
772
1341
|
function quickSelect(data, index, compareFn) {
|
|
773
1342
|
return index < 0 || index >= data.length ? void 0 : quickSelectImplementation(
|
|
@@ -818,6 +1387,56 @@ function nthByImplementation(data, compareFn, index) {
|
|
|
818
1387
|
);
|
|
819
1388
|
}
|
|
820
1389
|
|
|
1390
|
+
function omitBy(...args) {
|
|
1391
|
+
return purry(omitBy_, args);
|
|
1392
|
+
}
|
|
1393
|
+
function omitBy_(object, fn) {
|
|
1394
|
+
if (object === void 0 || object === null) {
|
|
1395
|
+
return object;
|
|
1396
|
+
}
|
|
1397
|
+
const out = {};
|
|
1398
|
+
for (const key of keys.strict(object)) {
|
|
1399
|
+
const k = key;
|
|
1400
|
+
if (!fn(object[k], k)) {
|
|
1401
|
+
out[k] = object[k];
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
return out;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
function omit(...args) {
|
|
1408
|
+
return purry(omit_, args);
|
|
1409
|
+
}
|
|
1410
|
+
function omit_(data, propNames) {
|
|
1411
|
+
if (!hasAtLeast(propNames, 1)) {
|
|
1412
|
+
return { ...data };
|
|
1413
|
+
}
|
|
1414
|
+
if (!hasAtLeast(propNames, 2)) {
|
|
1415
|
+
const [propName] = propNames;
|
|
1416
|
+
const { [propName]: omitted, ...remaining } = data;
|
|
1417
|
+
return remaining;
|
|
1418
|
+
}
|
|
1419
|
+
if (!propNames.some((propName) => propName in data)) {
|
|
1420
|
+
return { ...data };
|
|
1421
|
+
}
|
|
1422
|
+
const asSet = new Set(propNames);
|
|
1423
|
+
return fromEntries(
|
|
1424
|
+
Object.entries(data).filter(([key]) => !asSet.has(key))
|
|
1425
|
+
);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
function once(fn) {
|
|
1429
|
+
let called = false;
|
|
1430
|
+
let ret;
|
|
1431
|
+
return () => {
|
|
1432
|
+
if (!called) {
|
|
1433
|
+
ret = fn();
|
|
1434
|
+
called = true;
|
|
1435
|
+
}
|
|
1436
|
+
return ret;
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
|
|
821
1440
|
function only(...args) {
|
|
822
1441
|
return purry(only_, args);
|
|
823
1442
|
}
|
|
@@ -845,15 +1464,195 @@ function partition_(indexed) {
|
|
|
845
1464
|
partition2.indexed = indexed;
|
|
846
1465
|
})(partition || (partition = {}));
|
|
847
1466
|
|
|
848
|
-
function
|
|
849
|
-
return purry(
|
|
1467
|
+
function pathOr(...args) {
|
|
1468
|
+
return purry(pathOr_, args);
|
|
850
1469
|
}
|
|
851
|
-
function
|
|
852
|
-
|
|
853
|
-
for (
|
|
854
|
-
|
|
1470
|
+
function pathOr_(data, path, defaultValue) {
|
|
1471
|
+
let current = data;
|
|
1472
|
+
for (const prop of path) {
|
|
1473
|
+
if (current === null || current === void 0) {
|
|
1474
|
+
break;
|
|
1475
|
+
}
|
|
1476
|
+
current = current[prop];
|
|
855
1477
|
}
|
|
856
|
-
return
|
|
1478
|
+
return current ?? defaultValue;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
function pickBy(...args) {
|
|
1482
|
+
return purry(pickBy_, args);
|
|
1483
|
+
}
|
|
1484
|
+
function pickBy_(data, fn) {
|
|
1485
|
+
if (data === null || data === void 0) {
|
|
1486
|
+
return {};
|
|
1487
|
+
}
|
|
1488
|
+
const out = {};
|
|
1489
|
+
for (const key of keys.strict(data)) {
|
|
1490
|
+
const k = key;
|
|
1491
|
+
if (fn(data[k], k)) {
|
|
1492
|
+
out[k] = data[k];
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
return out;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
function pick(...args) {
|
|
1499
|
+
return purry(pick_, args);
|
|
1500
|
+
}
|
|
1501
|
+
function pick_(object, names) {
|
|
1502
|
+
const out = {};
|
|
1503
|
+
for (const name of names) {
|
|
1504
|
+
if (name in object) {
|
|
1505
|
+
out[name] = object[name];
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
return out;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
function pipe(input, ...operations) {
|
|
1512
|
+
let output = input;
|
|
1513
|
+
const lazyOperations = operations.map((op) => "lazy" in op ? prepareLazyOperation(op) : void 0);
|
|
1514
|
+
let operationIndex = 0;
|
|
1515
|
+
while (operationIndex < operations.length) {
|
|
1516
|
+
const lazyOperation = lazyOperations[operationIndex];
|
|
1517
|
+
if (lazyOperation === void 0 || !isIterable(output)) {
|
|
1518
|
+
const operation = operations[operationIndex];
|
|
1519
|
+
output = operation(output);
|
|
1520
|
+
operationIndex += 1;
|
|
1521
|
+
continue;
|
|
1522
|
+
}
|
|
1523
|
+
const lazySequence = [];
|
|
1524
|
+
for (let index = operationIndex; index < operations.length; index++) {
|
|
1525
|
+
const lazyOp = lazyOperations[index];
|
|
1526
|
+
if (lazyOp === void 0) {
|
|
1527
|
+
break;
|
|
1528
|
+
}
|
|
1529
|
+
lazySequence.push(lazyOp);
|
|
1530
|
+
if (lazyOp.isSingle) {
|
|
1531
|
+
break;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
const accumulator = [];
|
|
1535
|
+
const iterator = output[Symbol.iterator]();
|
|
1536
|
+
while (true) {
|
|
1537
|
+
const result = iterator.next();
|
|
1538
|
+
if (result.done ?? false) {
|
|
1539
|
+
break;
|
|
1540
|
+
}
|
|
1541
|
+
const shouldExitEarly = processItem_(
|
|
1542
|
+
result.value,
|
|
1543
|
+
accumulator,
|
|
1544
|
+
lazySequence
|
|
1545
|
+
);
|
|
1546
|
+
if (shouldExitEarly) {
|
|
1547
|
+
break;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
const { isSingle } = lazySequence[lazySequence.length - 1];
|
|
1551
|
+
output = isSingle ? accumulator[0] : accumulator;
|
|
1552
|
+
operationIndex += lazySequence.length;
|
|
1553
|
+
}
|
|
1554
|
+
return output;
|
|
1555
|
+
}
|
|
1556
|
+
function processItem_(item, accumulator, lazySequence) {
|
|
1557
|
+
if (lazySequence.length === 0) {
|
|
1558
|
+
accumulator.push(item);
|
|
1559
|
+
return false;
|
|
1560
|
+
}
|
|
1561
|
+
let currentItem = item;
|
|
1562
|
+
let lazyResult = { done: false, hasNext: false };
|
|
1563
|
+
let isDone = false;
|
|
1564
|
+
for (const [operationsIndex, lazyFn] of lazySequence.entries()) {
|
|
1565
|
+
const { index, isIndexed, items } = lazyFn;
|
|
1566
|
+
items.push(currentItem);
|
|
1567
|
+
lazyResult = isIndexed ? lazyFn(currentItem, index, items) : lazyFn(currentItem);
|
|
1568
|
+
lazyFn.index += 1;
|
|
1569
|
+
if (lazyResult.hasNext) {
|
|
1570
|
+
if (lazyResult.hasMany ?? false) {
|
|
1571
|
+
for (const subItem of lazyResult.next) {
|
|
1572
|
+
const subResult = processItem_(
|
|
1573
|
+
subItem,
|
|
1574
|
+
accumulator,
|
|
1575
|
+
lazySequence.slice(operationsIndex + 1)
|
|
1576
|
+
);
|
|
1577
|
+
if (subResult) {
|
|
1578
|
+
return true;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
return false;
|
|
1582
|
+
}
|
|
1583
|
+
currentItem = lazyResult.next;
|
|
1584
|
+
}
|
|
1585
|
+
if (!lazyResult.hasNext) {
|
|
1586
|
+
break;
|
|
1587
|
+
}
|
|
1588
|
+
if (lazyResult.done) {
|
|
1589
|
+
isDone = true;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
if (lazyResult.hasNext) {
|
|
1593
|
+
accumulator.push(currentItem);
|
|
1594
|
+
}
|
|
1595
|
+
return isDone;
|
|
1596
|
+
}
|
|
1597
|
+
function prepareLazyOperation(op) {
|
|
1598
|
+
const { lazy, lazyArgs } = op;
|
|
1599
|
+
const fn = lazy(...lazyArgs ?? []);
|
|
1600
|
+
return Object.assign(fn, {
|
|
1601
|
+
index: 0,
|
|
1602
|
+
isIndexed: lazy.indexed,
|
|
1603
|
+
isSingle: lazy.single,
|
|
1604
|
+
items: []
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
function isIterable(something) {
|
|
1608
|
+
return typeof something === "string" || typeof something === "object" && something !== null && Symbol.iterator in something;
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
function piped(...operations) {
|
|
1612
|
+
return (value) => pipe(
|
|
1613
|
+
value,
|
|
1614
|
+
...operations
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
function prop(propName) {
|
|
1619
|
+
return ({ [propName]: value }) => value;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
function times(...args) {
|
|
1623
|
+
return purry(times_, args);
|
|
1624
|
+
}
|
|
1625
|
+
function times_(count, fn) {
|
|
1626
|
+
if (count < 0) {
|
|
1627
|
+
throw new RangeError("n must be a non-negative number");
|
|
1628
|
+
}
|
|
1629
|
+
const res = [];
|
|
1630
|
+
for (let i = 0; i < count; i++) {
|
|
1631
|
+
res.push(fn(i));
|
|
1632
|
+
}
|
|
1633
|
+
return res;
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
1637
|
+
function randomString(...args) {
|
|
1638
|
+
return purry(randomStringImplementation, args);
|
|
1639
|
+
}
|
|
1640
|
+
function randomStringImplementation(length) {
|
|
1641
|
+
return times(length, randomChar).join("");
|
|
1642
|
+
}
|
|
1643
|
+
function randomChar() {
|
|
1644
|
+
return ALPHABET[Math.floor(Math.random() * ALPHABET.length)];
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
function range(...args) {
|
|
1648
|
+
return purry(range_, args);
|
|
1649
|
+
}
|
|
1650
|
+
function range_(start, end) {
|
|
1651
|
+
const ret = [];
|
|
1652
|
+
for (let i = start; i < end; i++) {
|
|
1653
|
+
ret.push(i);
|
|
1654
|
+
}
|
|
1655
|
+
return ret;
|
|
857
1656
|
}
|
|
858
1657
|
|
|
859
1658
|
function rankBy(...args) {
|
|
@@ -887,30 +1686,6 @@ function reduce_(indexed) {
|
|
|
887
1686
|
reduce2.indexed = indexed;
|
|
888
1687
|
})(reduce || (reduce = {}));
|
|
889
1688
|
|
|
890
|
-
function reject(...args) {
|
|
891
|
-
return purry(reject_(false), args, reject.lazy);
|
|
892
|
-
}
|
|
893
|
-
function reject_(indexed) {
|
|
894
|
-
return (array, fn) => {
|
|
895
|
-
return reduceLazy(
|
|
896
|
-
array,
|
|
897
|
-
indexed ? reject.lazyIndexed(fn) : reject.lazy(fn),
|
|
898
|
-
indexed
|
|
899
|
-
);
|
|
900
|
-
};
|
|
901
|
-
}
|
|
902
|
-
function lazy_$1(indexed) {
|
|
903
|
-
return (fn) => (item, index, data) => (indexed ? fn(item, index, data) : fn(item)) ? { done: false, hasNext: false } : { done: false, hasNext: true, next: item };
|
|
904
|
-
}
|
|
905
|
-
((reject2) => {
|
|
906
|
-
function indexed(...args) {
|
|
907
|
-
return purry(reject_(true), args, reject2.lazyIndexed);
|
|
908
|
-
}
|
|
909
|
-
reject2.indexed = indexed;
|
|
910
|
-
reject2.lazy = lazy_$1(false);
|
|
911
|
-
reject2.lazyIndexed = toLazyIndexed(lazy_$1(true));
|
|
912
|
-
})(reject || (reject = {}));
|
|
913
|
-
|
|
914
1689
|
function reverse(...args) {
|
|
915
1690
|
return purry(reverse_, args);
|
|
916
1691
|
}
|
|
@@ -918,6 +1693,10 @@ function reverse_(array) {
|
|
|
918
1693
|
return array.slice().reverse();
|
|
919
1694
|
}
|
|
920
1695
|
|
|
1696
|
+
function round(...args) {
|
|
1697
|
+
return purry(_withPrecision(Math.round), args);
|
|
1698
|
+
}
|
|
1699
|
+
|
|
921
1700
|
function sample(...args) {
|
|
922
1701
|
return purry(sampleImplementation, args);
|
|
923
1702
|
}
|
|
@@ -946,6 +1725,40 @@ function sampleImplementation(data, sampleSize) {
|
|
|
946
1725
|
return data.filter((_, index) => !sampleIndices.has(index));
|
|
947
1726
|
}
|
|
948
1727
|
|
|
1728
|
+
function setPath(...args) {
|
|
1729
|
+
return purry(setPath_, args);
|
|
1730
|
+
}
|
|
1731
|
+
function setPath_(data, path, value) {
|
|
1732
|
+
const [current, ...rest] = path;
|
|
1733
|
+
if (current === void 0) {
|
|
1734
|
+
return value;
|
|
1735
|
+
}
|
|
1736
|
+
if (Array.isArray(data)) {
|
|
1737
|
+
return data.map((item, index) => index === current ? setPath_(item, rest, value) : item);
|
|
1738
|
+
}
|
|
1739
|
+
if (data === null || data === void 0) {
|
|
1740
|
+
throw new Error("Path doesn't exist in object!");
|
|
1741
|
+
}
|
|
1742
|
+
return {
|
|
1743
|
+
...data,
|
|
1744
|
+
[current]: setPath_(
|
|
1745
|
+
data[current],
|
|
1746
|
+
rest,
|
|
1747
|
+
value
|
|
1748
|
+
)
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
function set(...args) {
|
|
1753
|
+
return purry(set_, args);
|
|
1754
|
+
}
|
|
1755
|
+
function set_(obj, prop, value) {
|
|
1756
|
+
return {
|
|
1757
|
+
...obj,
|
|
1758
|
+
[prop]: value
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
|
|
949
1762
|
function shuffle(...args) {
|
|
950
1763
|
return purry(shuffle_, args);
|
|
951
1764
|
}
|
|
@@ -960,17 +1773,15 @@ function shuffle_(items) {
|
|
|
960
1773
|
return result;
|
|
961
1774
|
}
|
|
962
1775
|
|
|
963
|
-
function
|
|
964
|
-
return
|
|
1776
|
+
function sleep(timeout) {
|
|
1777
|
+
return new Promise((resolve) => {
|
|
1778
|
+
setTimeout(resolve, timeout);
|
|
1779
|
+
});
|
|
965
1780
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
return ret;
|
|
1781
|
+
|
|
1782
|
+
function slugify(str) {
|
|
1783
|
+
return str.normalize("NFD").replace(/[\u0300-\u036F]/g, "").toLowerCase().replace(/[^a-z0-9]/g, " ").trim().replace(/\s+/g, "-");
|
|
970
1784
|
}
|
|
971
|
-
((sort2) => {
|
|
972
|
-
sort2.strict = sort2;
|
|
973
|
-
})(sort || (sort = {}));
|
|
974
1785
|
|
|
975
1786
|
function sortBy(...args) {
|
|
976
1787
|
return purryOrderRules(_sortBy, args);
|
|
@@ -982,7 +1793,19 @@ function _sortBy(data, compareFn) {
|
|
|
982
1793
|
sortBy2.strict = sortBy2;
|
|
983
1794
|
})(sortBy || (sortBy = {}));
|
|
984
1795
|
|
|
985
|
-
function
|
|
1796
|
+
function sort(...args) {
|
|
1797
|
+
return purry(sort_, args);
|
|
1798
|
+
}
|
|
1799
|
+
function sort_(items, cmp) {
|
|
1800
|
+
const ret = items.slice();
|
|
1801
|
+
ret.sort(cmp);
|
|
1802
|
+
return ret;
|
|
1803
|
+
}
|
|
1804
|
+
((sort2) => {
|
|
1805
|
+
sort2.strict = sort2;
|
|
1806
|
+
})(sort || (sort = {}));
|
|
1807
|
+
|
|
1808
|
+
function _binarySearchCutoffIndex(array, predicate) {
|
|
986
1809
|
let lowIndex = 0;
|
|
987
1810
|
let highIndex = array.length;
|
|
988
1811
|
while (lowIndex < highIndex) {
|
|
@@ -997,37 +1820,57 @@ function binarySearchCutoffIndex(array, predicate) {
|
|
|
997
1820
|
return highIndex;
|
|
998
1821
|
}
|
|
999
1822
|
|
|
1000
|
-
function
|
|
1001
|
-
return purry(
|
|
1823
|
+
function sortedIndexBy(...args) {
|
|
1824
|
+
return purry(sortedIndexByImplementation, args);
|
|
1002
1825
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1826
|
+
((sortedIndexBy2) => {
|
|
1827
|
+
function indexed(...args) {
|
|
1828
|
+
return purry(sortedIndexByImplementation, args);
|
|
1829
|
+
}
|
|
1830
|
+
sortedIndexBy2.indexed = indexed;
|
|
1831
|
+
})(sortedIndexBy || (sortedIndexBy = {}));
|
|
1832
|
+
function sortedIndexByImplementation(array, item, valueFunction) {
|
|
1833
|
+
const value = valueFunction(item);
|
|
1834
|
+
return _binarySearchCutoffIndex(
|
|
1835
|
+
array,
|
|
1836
|
+
(pivot, index) => valueFunction(pivot, index) < value
|
|
1837
|
+
);
|
|
1005
1838
|
}
|
|
1006
1839
|
|
|
1007
1840
|
function sortedIndexWith(...args) {
|
|
1008
|
-
return purry(
|
|
1841
|
+
return purry(_binarySearchCutoffIndex, args);
|
|
1009
1842
|
}
|
|
1010
1843
|
((sortedIndexWith2) => {
|
|
1011
1844
|
function indexed(...args) {
|
|
1012
|
-
return purry(
|
|
1845
|
+
return purry(_binarySearchCutoffIndex, args);
|
|
1013
1846
|
}
|
|
1014
1847
|
sortedIndexWith2.indexed = indexed;
|
|
1015
1848
|
})(sortedIndexWith || (sortedIndexWith = {}));
|
|
1016
1849
|
|
|
1017
|
-
function
|
|
1018
|
-
return purry(
|
|
1850
|
+
function sortedIndex(...args) {
|
|
1851
|
+
return purry(sortedIndexImplementation, args);
|
|
1019
1852
|
}
|
|
1020
|
-
(
|
|
1853
|
+
function sortedIndexImplementation(array, item) {
|
|
1854
|
+
return _binarySearchCutoffIndex(array, (pivot) => pivot < item);
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
function sortedLastIndexBy(...args) {
|
|
1858
|
+
return purry(sortedLastIndexByImplementation, args);
|
|
1859
|
+
}
|
|
1860
|
+
((sortedLastIndexBy2) => {
|
|
1021
1861
|
function indexed(...args) {
|
|
1022
|
-
return purry(
|
|
1862
|
+
return purry(sortedLastIndexByImplementation, args);
|
|
1023
1863
|
}
|
|
1024
|
-
|
|
1025
|
-
})(
|
|
1026
|
-
function
|
|
1864
|
+
sortedLastIndexBy2.indexed = indexed;
|
|
1865
|
+
})(sortedLastIndexBy || (sortedLastIndexBy = {}));
|
|
1866
|
+
function sortedLastIndexByImplementation(array, item, valueFunction) {
|
|
1027
1867
|
const value = valueFunction(item);
|
|
1028
|
-
return
|
|
1868
|
+
return _binarySearchCutoffIndex(
|
|
1029
1869
|
array,
|
|
1030
|
-
|
|
1870
|
+
// The only difference between the regular implementation and the "last"
|
|
1871
|
+
// variation is that we consider the pivot with equality too, so that we
|
|
1872
|
+
// skip all equal values in addition to the lower ones.
|
|
1873
|
+
(pivot, index) => valueFunction(pivot, index) <= value
|
|
1031
1874
|
);
|
|
1032
1875
|
}
|
|
1033
1876
|
|
|
@@ -1035,7 +1878,7 @@ function sortedLastIndex(...args) {
|
|
|
1035
1878
|
return purry(sortedLastIndexImplementation, args);
|
|
1036
1879
|
}
|
|
1037
1880
|
function sortedLastIndexImplementation(array, item) {
|
|
1038
|
-
return
|
|
1881
|
+
return _binarySearchCutoffIndex(
|
|
1039
1882
|
array,
|
|
1040
1883
|
// The only difference between the regular implementation and the "last"
|
|
1041
1884
|
// variation is that we consider the pivot with equality too, so that we
|
|
@@ -1074,6 +1917,28 @@ function splitWhen_(array, fn) {
|
|
|
1074
1917
|
return [array.slice(), []];
|
|
1075
1918
|
}
|
|
1076
1919
|
|
|
1920
|
+
function stringToPath(path) {
|
|
1921
|
+
return stringToPath_(path);
|
|
1922
|
+
}
|
|
1923
|
+
function stringToPath_(path) {
|
|
1924
|
+
if (path.length === 0) {
|
|
1925
|
+
return [];
|
|
1926
|
+
}
|
|
1927
|
+
const match = /^\[(.+?)\](.*)$/u.exec(path) ?? /^\.?([^.[\]]+)(.*)$/u.exec(path);
|
|
1928
|
+
if (match !== null) {
|
|
1929
|
+
const [, key, rest] = match;
|
|
1930
|
+
return [key, ...stringToPath_(rest)];
|
|
1931
|
+
}
|
|
1932
|
+
return [path];
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
function subtract(...args) {
|
|
1936
|
+
return purry(subtract_, args);
|
|
1937
|
+
}
|
|
1938
|
+
function subtract_(value, subtrahend) {
|
|
1939
|
+
return value - subtrahend;
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1077
1942
|
function sumBy_(indexed) {
|
|
1078
1943
|
return (array, fn) => {
|
|
1079
1944
|
let sum = 0;
|
|
@@ -1122,25 +1987,17 @@ function swapString_(item, index1, index2) {
|
|
|
1122
1987
|
return result.join("");
|
|
1123
1988
|
}
|
|
1124
1989
|
|
|
1125
|
-
function
|
|
1126
|
-
return purry(
|
|
1990
|
+
function swapProps(...args) {
|
|
1991
|
+
return purry(swapProps_, args);
|
|
1127
1992
|
}
|
|
1128
|
-
function
|
|
1129
|
-
|
|
1993
|
+
function swapProps_(obj, key1, key2) {
|
|
1994
|
+
const { [key1]: value1, [key2]: value2 } = obj;
|
|
1995
|
+
return {
|
|
1996
|
+
...obj,
|
|
1997
|
+
[key1]: value2,
|
|
1998
|
+
[key2]: value1
|
|
1999
|
+
};
|
|
1130
2000
|
}
|
|
1131
|
-
((take2) => {
|
|
1132
|
-
function lazy(n) {
|
|
1133
|
-
if (n <= 0) {
|
|
1134
|
-
return () => ({ done: true, hasNext: false });
|
|
1135
|
-
}
|
|
1136
|
-
let remaining = n;
|
|
1137
|
-
return (value) => {
|
|
1138
|
-
remaining -= 1;
|
|
1139
|
-
return { done: remaining <= 0, hasNext: true, next: value };
|
|
1140
|
-
};
|
|
1141
|
-
}
|
|
1142
|
-
take2.lazy = lazy;
|
|
1143
|
-
})(take || (take = {}));
|
|
1144
2001
|
|
|
1145
2002
|
function takeFirstBy(...args) {
|
|
1146
2003
|
return purryOrderRulesWithArgument(takeFirstByImplementation, args);
|
|
@@ -1175,83 +2032,80 @@ function takeWhile_(array, fn) {
|
|
|
1175
2032
|
return ret;
|
|
1176
2033
|
}
|
|
1177
2034
|
|
|
1178
|
-
function
|
|
1179
|
-
return purry(
|
|
2035
|
+
function take(...args) {
|
|
2036
|
+
return purry(take_, args, take.lazy);
|
|
1180
2037
|
}
|
|
1181
|
-
function
|
|
1182
|
-
return
|
|
2038
|
+
function take_(array, n) {
|
|
2039
|
+
return _reduceLazy(array, take.lazy(n));
|
|
1183
2040
|
}
|
|
1184
|
-
((
|
|
1185
|
-
function lazy() {
|
|
1186
|
-
|
|
2041
|
+
((take2) => {
|
|
2042
|
+
function lazy(n) {
|
|
2043
|
+
if (n <= 0) {
|
|
2044
|
+
return () => ({ done: true, hasNext: false });
|
|
2045
|
+
}
|
|
2046
|
+
let remaining = n;
|
|
1187
2047
|
return (value) => {
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
}
|
|
1191
|
-
set.add(value);
|
|
1192
|
-
return { done: false, hasNext: true, next: value };
|
|
2048
|
+
remaining -= 1;
|
|
2049
|
+
return { done: remaining <= 0, hasNext: true, next: value };
|
|
1193
2050
|
};
|
|
1194
2051
|
}
|
|
1195
|
-
|
|
1196
|
-
})(
|
|
2052
|
+
take2.lazy = lazy;
|
|
2053
|
+
})(take || (take = {}));
|
|
1197
2054
|
|
|
1198
|
-
function
|
|
1199
|
-
return purry(
|
|
2055
|
+
function uniqueBy(...args) {
|
|
2056
|
+
return purry(uniqueByImplementation, args, lazyUniqueBy);
|
|
1200
2057
|
}
|
|
1201
|
-
function
|
|
1202
|
-
return
|
|
2058
|
+
function uniqueByImplementation(data, keyFunction) {
|
|
2059
|
+
return _reduceLazy(data, lazyUniqueBy(keyFunction));
|
|
1203
2060
|
}
|
|
1204
|
-
function
|
|
2061
|
+
function lazyUniqueBy(keyFunction) {
|
|
1205
2062
|
const set = /* @__PURE__ */ new Set();
|
|
1206
2063
|
return (value) => {
|
|
1207
|
-
const
|
|
1208
|
-
if (set.has(
|
|
2064
|
+
const key = keyFunction(value);
|
|
2065
|
+
if (set.has(key)) {
|
|
1209
2066
|
return { done: false, hasNext: false };
|
|
1210
2067
|
}
|
|
1211
|
-
set.add(
|
|
2068
|
+
set.add(key);
|
|
1212
2069
|
return { done: false, hasNext: true, next: value };
|
|
1213
2070
|
};
|
|
1214
2071
|
}
|
|
1215
2072
|
|
|
1216
|
-
function
|
|
1217
|
-
return purry(
|
|
2073
|
+
function uniqueWith(...args) {
|
|
2074
|
+
return purry(uniqueWithImplementation, args, uniqueWith.lazy);
|
|
1218
2075
|
}
|
|
1219
|
-
function
|
|
1220
|
-
const lazy =
|
|
1221
|
-
return
|
|
2076
|
+
function uniqueWithImplementation(array, isEquals) {
|
|
2077
|
+
const lazy = uniqueWith.lazy(isEquals);
|
|
2078
|
+
return _reduceLazy(array, lazy, true);
|
|
1222
2079
|
}
|
|
1223
2080
|
function lazy_(isEquals) {
|
|
1224
2081
|
return (value, index, array) => array !== void 0 && array.findIndex((otherValue) => isEquals(value, otherValue)) === index ? { done: false, hasNext: true, next: value } : { done: false, hasNext: false };
|
|
1225
2082
|
}
|
|
1226
|
-
((
|
|
1227
|
-
|
|
1228
|
-
})(
|
|
2083
|
+
((uniqueWith2) => {
|
|
2084
|
+
uniqueWith2.lazy = _toLazyIndexed(lazy_);
|
|
2085
|
+
})(uniqueWith || (uniqueWith = {}));
|
|
1229
2086
|
|
|
1230
|
-
function
|
|
1231
|
-
return purry(
|
|
1232
|
-
}
|
|
1233
|
-
function zip_(first, second) {
|
|
1234
|
-
const resultLength = first.length > second.length ? second.length : first.length;
|
|
1235
|
-
const result = [];
|
|
1236
|
-
for (let i = 0; i < resultLength; i++) {
|
|
1237
|
-
result.push([first[i], second[i]]);
|
|
1238
|
-
}
|
|
1239
|
-
return result;
|
|
2087
|
+
function unique(...args) {
|
|
2088
|
+
return purry(uniqueImplementation, args, unique.lazy);
|
|
1240
2089
|
}
|
|
1241
|
-
(
|
|
1242
|
-
|
|
1243
|
-
})(zip || (zip = {}));
|
|
1244
|
-
|
|
1245
|
-
function zipObj(...args) {
|
|
1246
|
-
return purry(zipObj_, args);
|
|
2090
|
+
function uniqueImplementation(array) {
|
|
2091
|
+
return _reduceLazy(array, unique.lazy());
|
|
1247
2092
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
2093
|
+
((unique2) => {
|
|
2094
|
+
function lazy() {
|
|
2095
|
+
const set = /* @__PURE__ */ new Set();
|
|
2096
|
+
return (value) => {
|
|
2097
|
+
if (set.has(value)) {
|
|
2098
|
+
return { done: false, hasNext: false };
|
|
2099
|
+
}
|
|
2100
|
+
set.add(value);
|
|
2101
|
+
return { done: false, hasNext: true, next: value };
|
|
2102
|
+
};
|
|
1253
2103
|
}
|
|
1254
|
-
|
|
2104
|
+
unique2.lazy = lazy;
|
|
2105
|
+
})(unique || (unique = {}));
|
|
2106
|
+
|
|
2107
|
+
function values(source) {
|
|
2108
|
+
return Object.values(source);
|
|
1255
2109
|
}
|
|
1256
2110
|
|
|
1257
2111
|
function zipWith(arg0, arg1, arg2) {
|
|
@@ -1272,960 +2126,21 @@ function zipWith_(first, second, fn) {
|
|
|
1272
2126
|
return result;
|
|
1273
2127
|
}
|
|
1274
2128
|
|
|
1275
|
-
function
|
|
1276
|
-
|
|
1277
|
-
return isArg(args[0]) ? (data) => implementation(data, ...callArgs) : implementation(...callArgs);
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
function conditional(...args) {
|
|
1281
|
-
return purryOn(isCase, conditionalImplementation, args);
|
|
1282
|
-
}
|
|
1283
|
-
function conditionalImplementation(data, ...cases) {
|
|
1284
|
-
for (const [when, then] of cases) {
|
|
1285
|
-
if (when(data)) {
|
|
1286
|
-
return then(data);
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
throw new Error("conditional: data failed for all cases");
|
|
1290
|
-
}
|
|
1291
|
-
function isCase(maybeCase) {
|
|
1292
|
-
if (!Array.isArray(maybeCase)) {
|
|
1293
|
-
return false;
|
|
1294
|
-
}
|
|
1295
|
-
const [when, then, ...rest] = maybeCase;
|
|
1296
|
-
return typeof when === "function" && when.length <= 1 && typeof then === "function" && then.length <= 1 && rest.length === 0;
|
|
1297
|
-
}
|
|
1298
|
-
const trivialDefaultCase = () => void 0;
|
|
1299
|
-
((conditional2) => {
|
|
1300
|
-
function defaultCase(then = trivialDefaultCase) {
|
|
1301
|
-
return [() => true, then];
|
|
1302
|
-
}
|
|
1303
|
-
conditional2.defaultCase = defaultCase;
|
|
1304
|
-
})(conditional || (conditional = {}));
|
|
1305
|
-
|
|
1306
|
-
function pipe(input, ...operations) {
|
|
1307
|
-
let output = input;
|
|
1308
|
-
const lazyOperations = operations.map((op) => "lazy" in op ? prepareLazyOperation(op) : void 0);
|
|
1309
|
-
let operationIndex = 0;
|
|
1310
|
-
while (operationIndex < operations.length) {
|
|
1311
|
-
const lazyOperation = lazyOperations[operationIndex];
|
|
1312
|
-
if (lazyOperation === void 0 || !isIterable(output)) {
|
|
1313
|
-
const operation = operations[operationIndex];
|
|
1314
|
-
output = operation(output);
|
|
1315
|
-
operationIndex += 1;
|
|
1316
|
-
continue;
|
|
1317
|
-
}
|
|
1318
|
-
const lazySequence = [];
|
|
1319
|
-
for (let index = operationIndex; index < operations.length; index++) {
|
|
1320
|
-
const lazyOp = lazyOperations[index];
|
|
1321
|
-
if (lazyOp === void 0) {
|
|
1322
|
-
break;
|
|
1323
|
-
}
|
|
1324
|
-
lazySequence.push(lazyOp);
|
|
1325
|
-
if (lazyOp.isSingle) {
|
|
1326
|
-
break;
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
const accumulator = [];
|
|
1330
|
-
const iterator = output[Symbol.iterator]();
|
|
1331
|
-
while (true) {
|
|
1332
|
-
const result = iterator.next();
|
|
1333
|
-
if (result.done ?? false) {
|
|
1334
|
-
break;
|
|
1335
|
-
}
|
|
1336
|
-
const shouldExitEarly = processItem_(
|
|
1337
|
-
result.value,
|
|
1338
|
-
accumulator,
|
|
1339
|
-
lazySequence
|
|
1340
|
-
);
|
|
1341
|
-
if (shouldExitEarly) {
|
|
1342
|
-
break;
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
const { isSingle } = lazySequence[lazySequence.length - 1];
|
|
1346
|
-
output = isSingle ? accumulator[0] : accumulator;
|
|
1347
|
-
operationIndex += lazySequence.length;
|
|
1348
|
-
}
|
|
1349
|
-
return output;
|
|
2129
|
+
function zip(...args) {
|
|
2130
|
+
return purry(zip_, args);
|
|
1350
2131
|
}
|
|
1351
|
-
function
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
let currentItem = item;
|
|
1357
|
-
let lazyResult = { done: false, hasNext: false };
|
|
1358
|
-
let isDone = false;
|
|
1359
|
-
for (const [operationsIndex, lazyFn] of lazySequence.entries()) {
|
|
1360
|
-
const { index, isIndexed, items } = lazyFn;
|
|
1361
|
-
items.push(currentItem);
|
|
1362
|
-
lazyResult = isIndexed ? lazyFn(currentItem, index, items) : lazyFn(currentItem);
|
|
1363
|
-
lazyFn.index += 1;
|
|
1364
|
-
if (lazyResult.hasNext) {
|
|
1365
|
-
if (lazyResult.hasMany ?? false) {
|
|
1366
|
-
for (const subItem of lazyResult.next) {
|
|
1367
|
-
const subResult = processItem_(
|
|
1368
|
-
subItem,
|
|
1369
|
-
accumulator,
|
|
1370
|
-
lazySequence.slice(operationsIndex + 1)
|
|
1371
|
-
);
|
|
1372
|
-
if (subResult) {
|
|
1373
|
-
return true;
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
return false;
|
|
1377
|
-
}
|
|
1378
|
-
currentItem = lazyResult.next;
|
|
1379
|
-
}
|
|
1380
|
-
if (!lazyResult.hasNext) {
|
|
1381
|
-
break;
|
|
1382
|
-
}
|
|
1383
|
-
if (lazyResult.done) {
|
|
1384
|
-
isDone = true;
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
if (lazyResult.hasNext) {
|
|
1388
|
-
accumulator.push(currentItem);
|
|
2132
|
+
function zip_(first, second) {
|
|
2133
|
+
const resultLength = first.length > second.length ? second.length : first.length;
|
|
2134
|
+
const result = [];
|
|
2135
|
+
for (let i = 0; i < resultLength; i++) {
|
|
2136
|
+
result.push([first[i], second[i]]);
|
|
1389
2137
|
}
|
|
1390
|
-
return
|
|
1391
|
-
}
|
|
1392
|
-
function prepareLazyOperation(op) {
|
|
1393
|
-
const { lazy, lazyArgs } = op;
|
|
1394
|
-
const fn = lazy(...lazyArgs ?? []);
|
|
1395
|
-
return Object.assign(fn, {
|
|
1396
|
-
index: 0,
|
|
1397
|
-
isIndexed: lazy.indexed,
|
|
1398
|
-
isSingle: lazy.single,
|
|
1399
|
-
items: []
|
|
1400
|
-
});
|
|
1401
|
-
}
|
|
1402
|
-
function isIterable(something) {
|
|
1403
|
-
return typeof something === "string" || typeof something === "object" && something !== null && Symbol.iterator in something;
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
function createPipe(...operations) {
|
|
1407
|
-
return (value) => pipe(
|
|
1408
|
-
value,
|
|
1409
|
-
...operations
|
|
1410
|
-
);
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
function identity(value) {
|
|
1414
|
-
return value;
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
function noop() {
|
|
1418
|
-
return void 0;
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
function once(fn) {
|
|
1422
|
-
let called = false;
|
|
1423
|
-
let ret;
|
|
1424
|
-
return () => {
|
|
1425
|
-
if (!called) {
|
|
1426
|
-
ret = fn();
|
|
1427
|
-
called = true;
|
|
1428
|
-
}
|
|
1429
|
-
return ret;
|
|
1430
|
-
};
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
function debounce(func, {
|
|
1434
|
-
maxWaitMs,
|
|
1435
|
-
timing = "trailing",
|
|
1436
|
-
waitMs
|
|
1437
|
-
}) {
|
|
1438
|
-
if (maxWaitMs !== void 0 && waitMs !== void 0 && maxWaitMs < waitMs) {
|
|
1439
|
-
throw new Error(
|
|
1440
|
-
`debounce: maxWaitMs (${maxWaitMs}) cannot be less than waitMs (${waitMs})`
|
|
1441
|
-
);
|
|
1442
|
-
}
|
|
1443
|
-
let coolDownTimeoutId;
|
|
1444
|
-
let maxWaitTimeoutId;
|
|
1445
|
-
let latestCallArgs;
|
|
1446
|
-
let result;
|
|
1447
|
-
function handleDebouncedCall(args) {
|
|
1448
|
-
latestCallArgs = args;
|
|
1449
|
-
if (maxWaitMs !== void 0 && maxWaitTimeoutId === void 0) {
|
|
1450
|
-
maxWaitTimeoutId = setTimeout(handleInvoke, maxWaitMs);
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
function handleInvoke() {
|
|
1454
|
-
if (latestCallArgs === void 0) {
|
|
1455
|
-
return;
|
|
1456
|
-
}
|
|
1457
|
-
if (maxWaitTimeoutId !== void 0) {
|
|
1458
|
-
const timeoutId = maxWaitTimeoutId;
|
|
1459
|
-
maxWaitTimeoutId = void 0;
|
|
1460
|
-
clearTimeout(timeoutId);
|
|
1461
|
-
}
|
|
1462
|
-
const args = latestCallArgs;
|
|
1463
|
-
latestCallArgs = void 0;
|
|
1464
|
-
result = func(...args);
|
|
1465
|
-
}
|
|
1466
|
-
function handleCoolDownEnd() {
|
|
1467
|
-
if (coolDownTimeoutId === void 0) {
|
|
1468
|
-
return;
|
|
1469
|
-
}
|
|
1470
|
-
const timeoutId = coolDownTimeoutId;
|
|
1471
|
-
coolDownTimeoutId = void 0;
|
|
1472
|
-
clearTimeout(timeoutId);
|
|
1473
|
-
if (latestCallArgs !== void 0) {
|
|
1474
|
-
handleInvoke();
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
return {
|
|
1478
|
-
get cachedValue() {
|
|
1479
|
-
return result;
|
|
1480
|
-
},
|
|
1481
|
-
call: (...args) => {
|
|
1482
|
-
if (coolDownTimeoutId === void 0) {
|
|
1483
|
-
if (timing === "trailing") {
|
|
1484
|
-
handleDebouncedCall(args);
|
|
1485
|
-
} else {
|
|
1486
|
-
result = func(...args);
|
|
1487
|
-
}
|
|
1488
|
-
} else {
|
|
1489
|
-
if (timing !== "leading") {
|
|
1490
|
-
handleDebouncedCall(args);
|
|
1491
|
-
}
|
|
1492
|
-
const timeoutId = coolDownTimeoutId;
|
|
1493
|
-
coolDownTimeoutId = void 0;
|
|
1494
|
-
clearTimeout(timeoutId);
|
|
1495
|
-
}
|
|
1496
|
-
coolDownTimeoutId = setTimeout(
|
|
1497
|
-
handleCoolDownEnd,
|
|
1498
|
-
// If waitMs is not defined but maxWaitMs *is* it means the user is only
|
|
1499
|
-
// interested in the leaky-bucket nature of the debouncer which is
|
|
1500
|
-
// achieved by setting waitMs === maxWaitMs. If both are not defined we
|
|
1501
|
-
// default to 0 which would wait until the end of the execution frame.
|
|
1502
|
-
waitMs ?? maxWaitMs ?? 0
|
|
1503
|
-
);
|
|
1504
|
-
return result;
|
|
1505
|
-
},
|
|
1506
|
-
cancel: () => {
|
|
1507
|
-
if (coolDownTimeoutId !== void 0) {
|
|
1508
|
-
const timeoutId = coolDownTimeoutId;
|
|
1509
|
-
coolDownTimeoutId = void 0;
|
|
1510
|
-
clearTimeout(timeoutId);
|
|
1511
|
-
}
|
|
1512
|
-
if (maxWaitTimeoutId !== void 0) {
|
|
1513
|
-
const timeoutId = maxWaitTimeoutId;
|
|
1514
|
-
maxWaitTimeoutId = void 0;
|
|
1515
|
-
clearTimeout(timeoutId);
|
|
1516
|
-
}
|
|
1517
|
-
latestCallArgs = void 0;
|
|
1518
|
-
},
|
|
1519
|
-
flush: () => {
|
|
1520
|
-
handleCoolDownEnd();
|
|
1521
|
-
return result;
|
|
1522
|
-
},
|
|
1523
|
-
get isPending() {
|
|
1524
|
-
return coolDownTimeoutId !== void 0;
|
|
1525
|
-
}
|
|
1526
|
-
};
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
function sleep(timeout) {
|
|
1530
|
-
return new Promise((resolve) => {
|
|
1531
|
-
setTimeout(resolve, timeout);
|
|
1532
|
-
});
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
function times(...args) {
|
|
1536
|
-
return purry(times_, args);
|
|
1537
|
-
}
|
|
1538
|
-
function times_(count, fn) {
|
|
1539
|
-
if (count < 0) {
|
|
1540
|
-
throw new RangeError("n must be a non-negative number");
|
|
1541
|
-
}
|
|
1542
|
-
const res = [];
|
|
1543
|
-
for (let i = 0; i < count; i++) {
|
|
1544
|
-
res.push(fn(i));
|
|
1545
|
-
}
|
|
1546
|
-
return res;
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
function isDeepEqual(...args) {
|
|
1550
|
-
return purry(isDeepEqualImplementation, args);
|
|
1551
|
-
}
|
|
1552
|
-
function isDeepEqualImplementation(data, other) {
|
|
1553
|
-
if (data === other) {
|
|
1554
|
-
return true;
|
|
1555
|
-
}
|
|
1556
|
-
if (typeof data === "number" && typeof other === "number") {
|
|
1557
|
-
return data !== data && other !== other;
|
|
1558
|
-
}
|
|
1559
|
-
if (typeof data !== "object" || typeof other !== "object") {
|
|
1560
|
-
return false;
|
|
1561
|
-
}
|
|
1562
|
-
if (data === null || other === null) {
|
|
1563
|
-
return false;
|
|
1564
|
-
}
|
|
1565
|
-
if (Object.getPrototypeOf(data) !== Object.getPrototypeOf(other)) {
|
|
1566
|
-
return false;
|
|
1567
|
-
}
|
|
1568
|
-
if (Array.isArray(data)) {
|
|
1569
|
-
if (data.length !== other.length) {
|
|
1570
|
-
return false;
|
|
1571
|
-
}
|
|
1572
|
-
for (let i = 0; i < data.length; i++) {
|
|
1573
|
-
if (!isDeepEqualImplementation(
|
|
1574
|
-
data[i],
|
|
1575
|
-
other[i]
|
|
1576
|
-
)) {
|
|
1577
|
-
return false;
|
|
1578
|
-
}
|
|
1579
|
-
}
|
|
1580
|
-
return true;
|
|
1581
|
-
}
|
|
1582
|
-
if (data instanceof Date) {
|
|
1583
|
-
return data.getTime() === other.getTime();
|
|
1584
|
-
}
|
|
1585
|
-
if (data instanceof RegExp) {
|
|
1586
|
-
return data.toString() === other.toString();
|
|
1587
|
-
}
|
|
1588
|
-
const keys = Object.keys(data);
|
|
1589
|
-
if (keys.length !== Object.keys(other).length) {
|
|
1590
|
-
return false;
|
|
1591
|
-
}
|
|
1592
|
-
for (const key of keys) {
|
|
1593
|
-
if (!Object.prototype.hasOwnProperty.call(other, key)) {
|
|
1594
|
-
return false;
|
|
1595
|
-
}
|
|
1596
|
-
if (!isDeepEqualImplementation(data[key], other[key])) {
|
|
1597
|
-
return false;
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
return true;
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
function hasSubObject(...args) {
|
|
1604
|
-
return purry(_hasSubObject, args);
|
|
1605
|
-
}
|
|
1606
|
-
function _hasSubObject(data, subObject) {
|
|
1607
|
-
for (const key of Object.keys(subObject)) {
|
|
1608
|
-
if (!Object.prototype.hasOwnProperty.call(data, key)) {
|
|
1609
|
-
return false;
|
|
1610
|
-
}
|
|
1611
|
-
if (!isDeepEqual(subObject[key], data[key])) {
|
|
1612
|
-
return false;
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
return true;
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
function isArray(data) {
|
|
1619
|
-
return Array.isArray(data);
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
function isBoolean(data) {
|
|
1623
|
-
return typeof data === "boolean";
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
function isDate(data) {
|
|
1627
|
-
return data instanceof Date;
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
function isDefined(data) {
|
|
1631
|
-
return data !== void 0 && data !== null;
|
|
1632
|
-
}
|
|
1633
|
-
((isDefined2) => {
|
|
1634
|
-
function strict(data) {
|
|
1635
|
-
return data !== void 0;
|
|
1636
|
-
}
|
|
1637
|
-
isDefined2.strict = strict;
|
|
1638
|
-
})(isDefined || (isDefined = {}));
|
|
1639
|
-
|
|
1640
|
-
function isObject(data) {
|
|
1641
|
-
if (typeof data !== "object" || data === null) {
|
|
1642
|
-
return false;
|
|
1643
|
-
}
|
|
1644
|
-
const proto = Object.getPrototypeOf(data);
|
|
1645
|
-
return proto === null || proto === Object.prototype;
|
|
1646
|
-
}
|
|
1647
|
-
|
|
1648
|
-
function isString(data) {
|
|
1649
|
-
return typeof data === "string";
|
|
1650
|
-
}
|
|
1651
|
-
|
|
1652
|
-
function isEmpty(data) {
|
|
1653
|
-
if (data === void 0) {
|
|
1654
|
-
return true;
|
|
1655
|
-
}
|
|
1656
|
-
if (isArray(data) || isString(data)) {
|
|
1657
|
-
return data.length === 0;
|
|
1658
|
-
}
|
|
1659
|
-
if (isObject(data)) {
|
|
1660
|
-
return Object.keys(data).length === 0;
|
|
1661
|
-
}
|
|
1662
|
-
return false;
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
|
-
function isError(data) {
|
|
1666
|
-
return data instanceof Error;
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
function isFunction(data) {
|
|
1670
|
-
return typeof data === "function";
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
function isIncludedIn(dataOrContainer, container) {
|
|
1674
|
-
if (container === void 0) {
|
|
1675
|
-
const asSet = new Set(dataOrContainer);
|
|
1676
|
-
return (data) => asSet.has(data);
|
|
1677
|
-
}
|
|
1678
|
-
return container.includes(dataOrContainer);
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
function isNil(data) {
|
|
1682
|
-
return data === null || data === void 0;
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
function isNonNull(data) {
|
|
1686
|
-
return data !== null;
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
function isNot(predicate) {
|
|
1690
|
-
return (data) => !predicate(data);
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
function isNumber(data) {
|
|
1694
|
-
return typeof data === "number" && !Number.isNaN(data);
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
function isPromise(data) {
|
|
1698
|
-
return data instanceof Promise;
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
function isSymbol(data) {
|
|
1702
|
-
return typeof data === "symbol";
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
function isTruthy(data) {
|
|
1706
|
-
return !!data;
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
function add(...args) {
|
|
1710
|
-
return purry(add_, args);
|
|
1711
|
-
}
|
|
1712
|
-
function add_(value, addend) {
|
|
1713
|
-
return value + addend;
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
const MAX_PRECISION = 15;
|
|
1717
|
-
function withPrecision(roundingFn) {
|
|
1718
|
-
return (value, precision) => {
|
|
1719
|
-
if (precision === 0) {
|
|
1720
|
-
return roundingFn(value);
|
|
1721
|
-
}
|
|
1722
|
-
if (!Number.isInteger(precision)) {
|
|
1723
|
-
throw new TypeError(`precision must be an integer: ${precision}`);
|
|
1724
|
-
}
|
|
1725
|
-
if (precision > MAX_PRECISION || precision < -MAX_PRECISION) {
|
|
1726
|
-
throw new RangeError(`precision must be between ${-MAX_PRECISION} and ${MAX_PRECISION}`);
|
|
1727
|
-
}
|
|
1728
|
-
if (Number.isNaN(value) || !Number.isFinite(value)) {
|
|
1729
|
-
return roundingFn(value);
|
|
1730
|
-
}
|
|
1731
|
-
const multiplier = 10 ** precision;
|
|
1732
|
-
return roundingFn(value * multiplier) / multiplier;
|
|
1733
|
-
};
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
function ceil(...args) {
|
|
1737
|
-
return purry(withPrecision(Math.ceil), args);
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
function clamp(...args) {
|
|
1741
|
-
return purry(clamp_, args);
|
|
1742
|
-
}
|
|
1743
|
-
function clamp_(value, { max, min }) {
|
|
1744
|
-
if (min !== void 0 && value < min) {
|
|
1745
|
-
return min;
|
|
1746
|
-
}
|
|
1747
|
-
if (max !== void 0 && value > max) {
|
|
1748
|
-
return max;
|
|
1749
|
-
}
|
|
1750
|
-
return value;
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
function divide(...args) {
|
|
1754
|
-
return purry(divide_, args);
|
|
1755
|
-
}
|
|
1756
|
-
function divide_(value, divisor) {
|
|
1757
|
-
return value / divisor;
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
function floor(...args) {
|
|
1761
|
-
return purry(withPrecision(Math.floor), args);
|
|
1762
|
-
}
|
|
1763
|
-
|
|
1764
|
-
function multiply(...args) {
|
|
1765
|
-
return purry(multiply_, args);
|
|
1766
|
-
}
|
|
1767
|
-
function multiply_(value, multiplicand) {
|
|
1768
|
-
return value * multiplicand;
|
|
1769
|
-
}
|
|
1770
|
-
|
|
1771
|
-
function round(...args) {
|
|
1772
|
-
return purry(withPrecision(Math.round), args);
|
|
1773
|
-
}
|
|
1774
|
-
|
|
1775
|
-
function subtract(...args) {
|
|
1776
|
-
return purry(subtract_, args);
|
|
1777
|
-
}
|
|
1778
|
-
function subtract_(value, subtrahend) {
|
|
1779
|
-
return value - subtrahend;
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
function addProp(...args) {
|
|
1783
|
-
return purry(addProp_, args);
|
|
1784
|
-
}
|
|
1785
|
-
function addProp_(obj, prop, value) {
|
|
1786
|
-
return {
|
|
1787
|
-
...obj,
|
|
1788
|
-
[prop]: value
|
|
1789
|
-
};
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
function type(val) {
|
|
1793
|
-
if (val === null) {
|
|
1794
|
-
return "Null";
|
|
1795
|
-
}
|
|
1796
|
-
if (val === void 0) {
|
|
1797
|
-
return "Undefined";
|
|
1798
|
-
}
|
|
1799
|
-
return Object.prototype.toString.call(val).slice(8, -1);
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
|
-
function cloneRegExp_(pattern) {
|
|
1803
|
-
return new RegExp(
|
|
1804
|
-
pattern.source,
|
|
1805
|
-
(pattern.global ? "g" : "") + (pattern.ignoreCase ? "i" : "") + (pattern.multiline ? "m" : "") + (pattern.sticky ? "y" : "") + (pattern.unicode ? "u" : "")
|
|
1806
|
-
);
|
|
1807
|
-
}
|
|
1808
|
-
function clone_(value, refFrom, refTo, deep) {
|
|
1809
|
-
function copy(copiedValue) {
|
|
1810
|
-
const len = refFrom.length;
|
|
1811
|
-
let idx = 0;
|
|
1812
|
-
while (idx < len) {
|
|
1813
|
-
if (value === refFrom[idx]) {
|
|
1814
|
-
return refTo[idx];
|
|
1815
|
-
}
|
|
1816
|
-
idx += 1;
|
|
1817
|
-
}
|
|
1818
|
-
refFrom[idx + 1] = value;
|
|
1819
|
-
refTo[idx + 1] = copiedValue;
|
|
1820
|
-
for (const key in value) {
|
|
1821
|
-
copiedValue[key] = deep ? clone_(value[key], refFrom, refTo, true) : value[key];
|
|
1822
|
-
}
|
|
1823
|
-
return copiedValue;
|
|
1824
|
-
}
|
|
1825
|
-
switch (type(value)) {
|
|
1826
|
-
case "Object":
|
|
1827
|
-
return copy({});
|
|
1828
|
-
case "Array":
|
|
1829
|
-
return copy([]);
|
|
1830
|
-
case "Date":
|
|
1831
|
-
return new Date(value.valueOf());
|
|
1832
|
-
case "RegExp":
|
|
1833
|
-
return cloneRegExp_(value);
|
|
1834
|
-
default:
|
|
1835
|
-
return value;
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
function clone(value) {
|
|
1839
|
-
return value != null && typeof value.clone === "function" ? value.clone() : clone_(value, [], [], true);
|
|
1840
|
-
}
|
|
1841
|
-
|
|
1842
|
-
function forEachObj(...args) {
|
|
1843
|
-
return purry(forEachObj_(false), args);
|
|
1844
|
-
}
|
|
1845
|
-
function forEachObj_(indexed) {
|
|
1846
|
-
return (data, fn) => {
|
|
1847
|
-
for (const key in data) {
|
|
1848
|
-
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
1849
|
-
const { [key]: val } = data;
|
|
1850
|
-
if (indexed) {
|
|
1851
|
-
fn(val, key, data);
|
|
1852
|
-
} else {
|
|
1853
|
-
fn(val);
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
return data;
|
|
1858
|
-
};
|
|
1859
|
-
}
|
|
1860
|
-
((forEachObj2) => {
|
|
1861
|
-
function indexed(...args) {
|
|
1862
|
-
return purry(forEachObj_(true), args);
|
|
1863
|
-
}
|
|
1864
|
-
forEachObj2.indexed = indexed;
|
|
1865
|
-
})(forEachObj || (forEachObj = {}));
|
|
1866
|
-
|
|
1867
|
-
function fromKeys(...args) {
|
|
1868
|
-
return purry(fromKeysImplementation, args);
|
|
1869
|
-
}
|
|
1870
|
-
function fromKeysImplementation(data, mapper) {
|
|
1871
|
-
const result = {};
|
|
1872
|
-
for (const key of data) {
|
|
1873
|
-
result[key] = mapper(key);
|
|
1874
|
-
}
|
|
1875
|
-
return result;
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
function fromPairs(...args) {
|
|
1879
|
-
return purry(fromPairsImplementation, args);
|
|
1880
|
-
}
|
|
1881
|
-
function fromPairsImplementation(entries) {
|
|
1882
|
-
const out = {};
|
|
1883
|
-
for (const [key, value] of entries) {
|
|
1884
|
-
out[key] = value;
|
|
1885
|
-
}
|
|
1886
|
-
return out;
|
|
1887
|
-
}
|
|
1888
|
-
((fromPairs2) => {
|
|
1889
|
-
fromPairs2.strict = fromPairs2;
|
|
1890
|
-
})(fromPairs || (fromPairs = {}));
|
|
1891
|
-
|
|
1892
|
-
function invert(...args) {
|
|
1893
|
-
return purry(invert_, args);
|
|
1894
|
-
}
|
|
1895
|
-
function invert_(object) {
|
|
1896
|
-
const result = {};
|
|
1897
|
-
for (const key in object) {
|
|
1898
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
1899
|
-
result[object[key]] = key;
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
return result;
|
|
1903
|
-
}
|
|
1904
|
-
|
|
1905
|
-
function keys(...args) {
|
|
1906
|
-
return purry(Object.keys, args);
|
|
1907
|
-
}
|
|
1908
|
-
((keys2) => {
|
|
1909
|
-
keys2.strict = keys2;
|
|
1910
|
-
})(keys || (keys = {}));
|
|
1911
|
-
|
|
1912
|
-
function toPairs(...args) {
|
|
1913
|
-
return purry(Object.entries, args);
|
|
1914
|
-
}
|
|
1915
|
-
((toPairs2) => {
|
|
1916
|
-
toPairs2.strict = toPairs2;
|
|
1917
|
-
})(toPairs || (toPairs = {}));
|
|
1918
|
-
|
|
1919
|
-
function mapKeys(...args) {
|
|
1920
|
-
return purry(mapKeys_, args);
|
|
1921
|
-
}
|
|
1922
|
-
function mapKeys_(data, fn) {
|
|
1923
|
-
const out = {};
|
|
1924
|
-
for (const [key, value] of toPairs.strict(data)) {
|
|
1925
|
-
out[fn(key, value)] = value;
|
|
1926
|
-
}
|
|
1927
|
-
return out;
|
|
1928
|
-
}
|
|
1929
|
-
|
|
1930
|
-
function mapValues(...args) {
|
|
1931
|
-
return purry(mapValues_, args);
|
|
1932
|
-
}
|
|
1933
|
-
function mapValues_(data, fn) {
|
|
1934
|
-
const out = {};
|
|
1935
|
-
for (const [key, value] of toPairs.strict(data)) {
|
|
1936
|
-
out[key] = fn(value, key);
|
|
1937
|
-
}
|
|
1938
|
-
return out;
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
function merge(...args) {
|
|
1942
|
-
return purry(merge_, args);
|
|
1943
|
-
}
|
|
1944
|
-
function merge_(data, source) {
|
|
1945
|
-
return { ...data, ...source };
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
function mergeDeep(...args) {
|
|
1949
|
-
return purry(mergeDeepImplementation, args);
|
|
1950
|
-
}
|
|
1951
|
-
function mergeDeepImplementation(destination, source) {
|
|
1952
|
-
const output = { ...destination, ...source };
|
|
1953
|
-
for (const key in source) {
|
|
1954
|
-
if (!(key in destination)) {
|
|
1955
|
-
continue;
|
|
1956
|
-
}
|
|
1957
|
-
const { [key]: destinationValue } = destination;
|
|
1958
|
-
if (!isRecord(destinationValue)) {
|
|
1959
|
-
continue;
|
|
1960
|
-
}
|
|
1961
|
-
const { [key]: sourceValue } = source;
|
|
1962
|
-
if (!isRecord(sourceValue)) {
|
|
1963
|
-
continue;
|
|
1964
|
-
}
|
|
1965
|
-
output[key] = mergeDeepImplementation(destinationValue, sourceValue);
|
|
1966
|
-
}
|
|
1967
|
-
return output;
|
|
1968
|
-
}
|
|
1969
|
-
function isRecord(object) {
|
|
1970
|
-
return typeof object === "object" && object !== null && Object.getPrototypeOf(object) === Object.prototype;
|
|
1971
|
-
}
|
|
1972
|
-
|
|
1973
|
-
function omit(...args) {
|
|
1974
|
-
return purry(omit_, args);
|
|
1975
|
-
}
|
|
1976
|
-
function omit_(data, propNames) {
|
|
1977
|
-
if (!hasAtLeast(propNames, 1)) {
|
|
1978
|
-
return { ...data };
|
|
1979
|
-
}
|
|
1980
|
-
if (!hasAtLeast(propNames, 2)) {
|
|
1981
|
-
const [propName] = propNames;
|
|
1982
|
-
const { [propName]: omitted, ...remaining } = data;
|
|
1983
|
-
return remaining;
|
|
1984
|
-
}
|
|
1985
|
-
if (!propNames.some((propName) => propName in data)) {
|
|
1986
|
-
return { ...data };
|
|
1987
|
-
}
|
|
1988
|
-
const asSet = new Set(propNames);
|
|
1989
|
-
return fromPairs(
|
|
1990
|
-
Object.entries(data).filter(([key]) => !asSet.has(key))
|
|
1991
|
-
);
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
function omitBy(...args) {
|
|
1995
|
-
return purry(omitBy_, args);
|
|
1996
|
-
}
|
|
1997
|
-
function omitBy_(object, fn) {
|
|
1998
|
-
if (object === void 0 || object === null) {
|
|
1999
|
-
return object;
|
|
2000
|
-
}
|
|
2001
|
-
const out = {};
|
|
2002
|
-
for (const key of keys.strict(object)) {
|
|
2003
|
-
const k = key;
|
|
2004
|
-
if (!fn(object[k], k)) {
|
|
2005
|
-
out[k] = object[k];
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
return out;
|
|
2009
|
-
}
|
|
2010
|
-
|
|
2011
|
-
function pathOr(...args) {
|
|
2012
|
-
return purry(pathOr_, args);
|
|
2013
|
-
}
|
|
2014
|
-
function pathOr_(data, path, defaultValue) {
|
|
2015
|
-
let current = data;
|
|
2016
|
-
for (const prop of path) {
|
|
2017
|
-
if (current === null || current === void 0) {
|
|
2018
|
-
break;
|
|
2019
|
-
}
|
|
2020
|
-
current = current[prop];
|
|
2021
|
-
}
|
|
2022
|
-
return current ?? defaultValue;
|
|
2023
|
-
}
|
|
2024
|
-
|
|
2025
|
-
function pick(...args) {
|
|
2026
|
-
return purry(pick_, args);
|
|
2027
|
-
}
|
|
2028
|
-
function pick_(object, names) {
|
|
2029
|
-
const out = {};
|
|
2030
|
-
for (const name of names) {
|
|
2031
|
-
if (name in object) {
|
|
2032
|
-
out[name] = object[name];
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
return out;
|
|
2036
|
-
}
|
|
2037
|
-
|
|
2038
|
-
function pickBy(...args) {
|
|
2039
|
-
return purry(pickBy_, args);
|
|
2040
|
-
}
|
|
2041
|
-
function pickBy_(data, fn) {
|
|
2042
|
-
if (data === null || data === void 0) {
|
|
2043
|
-
return {};
|
|
2044
|
-
}
|
|
2045
|
-
const out = {};
|
|
2046
|
-
for (const key of keys.strict(data)) {
|
|
2047
|
-
const k = key;
|
|
2048
|
-
if (fn(data[k], k)) {
|
|
2049
|
-
out[k] = data[k];
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
return out;
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
function prop(propName) {
|
|
2056
|
-
return ({ [propName]: value }) => value;
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
function set(...args) {
|
|
2060
|
-
return purry(set_, args);
|
|
2061
|
-
}
|
|
2062
|
-
function set_(obj, prop, value) {
|
|
2063
|
-
return {
|
|
2064
|
-
...obj,
|
|
2065
|
-
[prop]: value
|
|
2066
|
-
};
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
function setPath(...args) {
|
|
2070
|
-
return purry(setPath_, args);
|
|
2071
|
-
}
|
|
2072
|
-
function setPath_(data, path, value) {
|
|
2073
|
-
const [current, ...rest] = path;
|
|
2074
|
-
if (current === void 0) {
|
|
2075
|
-
return value;
|
|
2076
|
-
}
|
|
2077
|
-
if (Array.isArray(data)) {
|
|
2078
|
-
return data.map((item, index) => index === current ? setPath_(item, rest, value) : item);
|
|
2079
|
-
}
|
|
2080
|
-
if (data === null || data === void 0) {
|
|
2081
|
-
throw new Error("Path doesn't exist in object!");
|
|
2082
|
-
}
|
|
2083
|
-
return {
|
|
2084
|
-
...data,
|
|
2085
|
-
[current]: setPath_(
|
|
2086
|
-
data[current],
|
|
2087
|
-
rest,
|
|
2088
|
-
value
|
|
2089
|
-
)
|
|
2090
|
-
};
|
|
2091
|
-
}
|
|
2092
|
-
|
|
2093
|
-
function swapProps(...args) {
|
|
2094
|
-
return purry(swapProps_, args);
|
|
2095
|
-
}
|
|
2096
|
-
function swapProps_(obj, key1, key2) {
|
|
2097
|
-
const { [key1]: value1, [key2]: value2 } = obj;
|
|
2098
|
-
return {
|
|
2099
|
-
...obj,
|
|
2100
|
-
[key1]: value2,
|
|
2101
|
-
[key2]: value1
|
|
2102
|
-
};
|
|
2103
|
-
}
|
|
2104
|
-
|
|
2105
|
-
function values(source) {
|
|
2106
|
-
return Object.values(source);
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
const RE_NUMBER_CHAR = /\d/;
|
|
2110
|
-
const STR_SPLITTERS = ["-", "_", "/", "."];
|
|
2111
|
-
function isUppercase(char = "") {
|
|
2112
|
-
if (RE_NUMBER_CHAR.test(char)) {
|
|
2113
|
-
return void 0;
|
|
2114
|
-
}
|
|
2115
|
-
return char !== char.toLowerCase();
|
|
2116
|
-
}
|
|
2117
|
-
function splitByCase(str, separators) {
|
|
2118
|
-
const splitters = separators ?? STR_SPLITTERS;
|
|
2119
|
-
const parts = [];
|
|
2120
|
-
if (!str || !isString(str)) {
|
|
2121
|
-
return parts;
|
|
2122
|
-
}
|
|
2123
|
-
let buff = "";
|
|
2124
|
-
let previousUpper;
|
|
2125
|
-
let previousSplitter;
|
|
2126
|
-
for (const char of str) {
|
|
2127
|
-
const isSplitter = splitters.includes(char);
|
|
2128
|
-
if (isSplitter === true) {
|
|
2129
|
-
parts.push(buff);
|
|
2130
|
-
buff = "";
|
|
2131
|
-
previousUpper = void 0;
|
|
2132
|
-
continue;
|
|
2133
|
-
}
|
|
2134
|
-
const isUpper = isUppercase(char);
|
|
2135
|
-
if (previousSplitter === false) {
|
|
2136
|
-
if (previousUpper === false && isUpper === true) {
|
|
2137
|
-
parts.push(buff);
|
|
2138
|
-
buff = char;
|
|
2139
|
-
previousUpper = isUpper;
|
|
2140
|
-
continue;
|
|
2141
|
-
}
|
|
2142
|
-
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
2143
|
-
const lastChar = buff.at(-1);
|
|
2144
|
-
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
2145
|
-
buff = lastChar + char;
|
|
2146
|
-
previousUpper = isUpper;
|
|
2147
|
-
continue;
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
buff += char;
|
|
2151
|
-
previousUpper = isUpper;
|
|
2152
|
-
previousSplitter = isSplitter;
|
|
2153
|
-
}
|
|
2154
|
-
parts.push(buff);
|
|
2155
|
-
return parts;
|
|
2156
|
-
}
|
|
2157
|
-
function toUpperFirst(str) {
|
|
2158
|
-
return str ? str[0]?.toUpperCase() + str.slice(1) : "";
|
|
2159
|
-
}
|
|
2160
|
-
function toLowerFirst(str) {
|
|
2161
|
-
return str ? str[0]?.toLowerCase() + str.slice(1) : "";
|
|
2162
|
-
}
|
|
2163
|
-
function toPascalCase(str, opts) {
|
|
2164
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => toUpperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
2165
|
-
}
|
|
2166
|
-
function toCamelCase(str, opts) {
|
|
2167
|
-
return toLowerFirst(toPascalCase(str || "", opts));
|
|
2168
|
-
}
|
|
2169
|
-
function toKebabCase(str, joiner) {
|
|
2170
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
2171
|
-
}
|
|
2172
|
-
function toSnakeCase(str) {
|
|
2173
|
-
return toKebabCase(str || "", "_");
|
|
2174
|
-
}
|
|
2175
|
-
function toFlatCase(str) {
|
|
2176
|
-
return toKebabCase(str || "", "");
|
|
2177
|
-
}
|
|
2178
|
-
function toTrainCase(str, opts) {
|
|
2179
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => toUpperFirst(opts?.normalize ? p.toLowerCase() : p)).join("-");
|
|
2180
|
-
}
|
|
2181
|
-
const titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
|
|
2182
|
-
function toTitleCase(str, opts) {
|
|
2183
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => titleCaseExceptions.test(p) ? p.toLowerCase() : toUpperFirst(opts?.normalize ? p.toLowerCase() : p)).join(" ");
|
|
2184
|
-
}
|
|
2185
|
-
|
|
2186
|
-
function humanReadableFileSize(bytes, base = 1e3) {
|
|
2187
|
-
if (bytes < base) {
|
|
2188
|
-
return `${bytes} B`;
|
|
2189
|
-
}
|
|
2190
|
-
const prefix = base === 1024 ? ["Ki", "Mi", "Gi"] : ["k", "M", "G"];
|
|
2191
|
-
let unit = -1;
|
|
2192
|
-
while (Math.abs(bytes) >= base && unit < prefix.length - 1) {
|
|
2193
|
-
bytes /= base;
|
|
2194
|
-
++unit;
|
|
2195
|
-
}
|
|
2196
|
-
return `${bytes.toFixed(1)} ${prefix[unit]}B`;
|
|
2197
|
-
}
|
|
2198
|
-
|
|
2199
|
-
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
2200
|
-
function randomString(...args) {
|
|
2201
|
-
return purry(randomStringImplementation, args);
|
|
2202
|
-
}
|
|
2203
|
-
function randomStringImplementation(length) {
|
|
2204
|
-
return times(length, randomChar).join("");
|
|
2205
|
-
}
|
|
2206
|
-
function randomChar() {
|
|
2207
|
-
return ALPHABET[Math.floor(Math.random() * ALPHABET.length)];
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
function slugify(str) {
|
|
2211
|
-
return str.normalize("NFD").replace(/[\u0300-\u036F]/g, "").toLowerCase().replace(/[^a-z0-9]/g, " ").trim().replace(/\s+/g, "-");
|
|
2212
|
-
}
|
|
2213
|
-
|
|
2214
|
-
function stringToPath(path) {
|
|
2215
|
-
return stringToPath_(path);
|
|
2216
|
-
}
|
|
2217
|
-
function stringToPath_(path) {
|
|
2218
|
-
if (path.length === 0) {
|
|
2219
|
-
return [];
|
|
2220
|
-
}
|
|
2221
|
-
const match = /^\[(.+?)\](.*)$/u.exec(path) ?? /^\.?([^.[\]]+)(.*)$/u.exec(path);
|
|
2222
|
-
if (match !== null) {
|
|
2223
|
-
const [, key, rest] = match;
|
|
2224
|
-
return [key, ...stringToPath_(rest)];
|
|
2225
|
-
}
|
|
2226
|
-
return [path];
|
|
2138
|
+
return result;
|
|
2227
2139
|
}
|
|
2140
|
+
((zip2) => {
|
|
2141
|
+
zip2.strict = zip2;
|
|
2142
|
+
})(zip || (zip = {}));
|
|
2228
2143
|
|
|
2229
2144
|
const isBrowser = typeof window !== "undefined";
|
|
2230
2145
|
|
|
2231
|
-
export { KEY_CODES, add, addProp, allPass, anyPass, ceil, chunk, clamp, clone, concat, conditional,
|
|
2146
|
+
export { KEY_CODES, add, addProp, allPass, anyPass, ceil, chunk, clamp, clone, concat, conditional, debounce, differenceWith, divide, drop, dropFirstBy, dropLast, dropLastWhile, dropWhile, entries, filter, find, findIndex, findLast, findLastIndex, first, firstBy, flatMap, flatten, flattenDeep, floor, forEach, forEachObj, fromEntries, fromKeys, groupBy, hasAtLeast, hasSubObject, humanReadableFileSize, identity, indexBy, intersectionWith, invert, isArray, isBoolean, isBrowser, isDate, isDeepEqual, isDefined, isEmpty, isError, isFunction, isIncludedIn, isNonNull, isNot, isNullish, isNumber, isObject, isPromise, isString, isSymbol, isTruthy, isUppercase, join, keys, last, length, map, mapKeys, mapToObj, mapValues, meanBy, merge, mergeAll, mergeDeep, multiply, noop, nthBy, omit, omitBy, once, only, partition, pathOr, pick, pickBy, pipe, piped, prop, purry, randomString, range, rankBy, reduce, reverse, round, sample, set, setPath, setPath_, shuffle, sleep, slugify, sort, sortBy, sortedIndex, sortedIndexBy, sortedIndexWith, sortedLastIndex, sortedLastIndexBy, splice, splitAt, splitByCase, splitWhen, stringToPath, subtract, sumBy, swapIndices, swapProps, take, takeFirstBy, takeWhile, times, toCamelCase, toFlatCase, toKebabCase, toLowerFirst, toPascalCase, toSnakeCase, toTitleCase, toTrainCase, toUpperFirst, unique, uniqueBy, uniqueWith, values, zip, zipWith };
|