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