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