@vinicunca/perkakas 0.1.0 → 0.2.1
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 +1061 -621
- package/dist/index.d.cts +912 -115
- package/dist/index.d.ts +912 -115
- package/dist/index.js +1039 -621
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -22,21 +22,28 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
KEY_CODES: () => KEY_CODES,
|
|
24
24
|
_setPath: () => _setPath,
|
|
25
|
+
add: () => add,
|
|
25
26
|
addProp: () => addProp,
|
|
26
27
|
allPass: () => allPass,
|
|
27
28
|
anyPass: () => anyPass,
|
|
29
|
+
ceil: () => ceil,
|
|
28
30
|
chunk: () => chunk,
|
|
29
31
|
clamp: () => clamp,
|
|
30
32
|
clone: () => clone,
|
|
31
33
|
compact: () => compact,
|
|
32
34
|
concat: () => concat,
|
|
35
|
+
conditional: () => conditional,
|
|
33
36
|
countBy: () => countBy,
|
|
34
37
|
createPipe: () => createPipe,
|
|
35
38
|
debounce: () => debounce,
|
|
36
39
|
difference: () => difference,
|
|
37
40
|
differenceWith: () => differenceWith,
|
|
41
|
+
divide: () => divide,
|
|
38
42
|
drop: () => drop,
|
|
43
|
+
dropFirstBy: () => dropFirstBy,
|
|
39
44
|
dropLast: () => dropLast,
|
|
45
|
+
dropLastWhile: () => dropLastWhile,
|
|
46
|
+
dropWhile: () => dropWhile,
|
|
40
47
|
equals: () => equals,
|
|
41
48
|
filter: () => filter,
|
|
42
49
|
find: () => find,
|
|
@@ -44,14 +51,17 @@ __export(src_exports, {
|
|
|
44
51
|
findLast: () => findLast,
|
|
45
52
|
findLastIndex: () => findLastIndex,
|
|
46
53
|
first: () => first,
|
|
54
|
+
firstBy: () => firstBy,
|
|
47
55
|
flatMap: () => flatMap,
|
|
48
56
|
flatMapToObj: () => flatMapToObj,
|
|
49
57
|
flatten: () => flatten,
|
|
50
58
|
flattenDeep: () => flattenDeep,
|
|
59
|
+
floor: () => floor,
|
|
51
60
|
forEach: () => forEach,
|
|
52
61
|
forEachObj: () => forEachObj,
|
|
53
62
|
fromPairs: () => fromPairs,
|
|
54
63
|
groupBy: () => groupBy,
|
|
64
|
+
hasAtLeast: () => hasAtLeast,
|
|
55
65
|
humanReadableFileSize: () => humanReadableFileSize,
|
|
56
66
|
identity: () => identity,
|
|
57
67
|
indexBy: () => indexBy,
|
|
@@ -73,6 +83,7 @@ __export(src_exports, {
|
|
|
73
83
|
isObject: () => isObject,
|
|
74
84
|
isPromise: () => isPromise,
|
|
75
85
|
isString: () => isString,
|
|
86
|
+
isSymbol: () => isSymbol,
|
|
76
87
|
isTruthy: () => isTruthy,
|
|
77
88
|
isUppercase: () => isUppercase,
|
|
78
89
|
join: () => join,
|
|
@@ -89,11 +100,14 @@ __export(src_exports, {
|
|
|
89
100
|
mergeAll: () => mergeAll,
|
|
90
101
|
mergeDeep: () => mergeDeep,
|
|
91
102
|
minBy: () => minBy,
|
|
103
|
+
multiply: () => multiply,
|
|
92
104
|
noop: () => noop,
|
|
105
|
+
nthBy: () => nthBy,
|
|
93
106
|
omit: () => omit,
|
|
94
107
|
omitBy: () => omitBy,
|
|
95
108
|
once: () => once,
|
|
96
|
-
|
|
109
|
+
only: () => only,
|
|
110
|
+
partition: () => partition2,
|
|
97
111
|
pathOr: () => pathOr,
|
|
98
112
|
pick: () => pick,
|
|
99
113
|
pickBy: () => pickBy,
|
|
@@ -102,9 +116,11 @@ __export(src_exports, {
|
|
|
102
116
|
purry: () => purry,
|
|
103
117
|
randomString: () => randomString,
|
|
104
118
|
range: () => range,
|
|
119
|
+
rankBy: () => rankBy,
|
|
105
120
|
reduce: () => reduce,
|
|
106
121
|
reject: () => reject,
|
|
107
122
|
reverse: () => reverse,
|
|
123
|
+
round: () => round,
|
|
108
124
|
sample: () => sample,
|
|
109
125
|
set: () => set,
|
|
110
126
|
setPath: () => setPath,
|
|
@@ -113,21 +129,27 @@ __export(src_exports, {
|
|
|
113
129
|
slugify: () => slugify,
|
|
114
130
|
sort: () => sort,
|
|
115
131
|
sortBy: () => sortBy,
|
|
132
|
+
splice: () => splice,
|
|
116
133
|
splitAt: () => splitAt,
|
|
117
134
|
splitByCase: () => splitByCase,
|
|
118
135
|
splitWhen: () => splitWhen,
|
|
119
136
|
stringToPath: () => stringToPath,
|
|
137
|
+
subtract: () => subtract,
|
|
120
138
|
sumBy: () => sumBy,
|
|
121
139
|
swapIndices: () => swapIndices,
|
|
122
140
|
swapProps: () => swapProps,
|
|
123
141
|
take: () => take,
|
|
142
|
+
takeFirstBy: () => takeFirstBy,
|
|
124
143
|
takeWhile: () => takeWhile,
|
|
144
|
+
titleCase: () => titleCase,
|
|
125
145
|
toCamelCase: () => toCamelCase,
|
|
146
|
+
toFlatCase: () => toFlatCase,
|
|
126
147
|
toKebabCase: () => toKebabCase,
|
|
127
148
|
toLowerFirst: () => toLowerFirst,
|
|
128
149
|
toPairs: () => toPairs,
|
|
129
150
|
toPascalCase: () => toPascalCase,
|
|
130
151
|
toSnakeCase: () => toSnakeCase,
|
|
152
|
+
toTrainCase: () => toTrainCase,
|
|
131
153
|
toUpperFirst: () => toUpperFirst,
|
|
132
154
|
type: () => type,
|
|
133
155
|
uniq: () => uniq,
|
|
@@ -164,232 +186,6 @@ var KEY_CODES = {
|
|
|
164
186
|
TAB: "Tab"
|
|
165
187
|
};
|
|
166
188
|
|
|
167
|
-
// src/function/pipe.ts
|
|
168
|
-
function pipe(value, ...operations) {
|
|
169
|
-
let ret = value;
|
|
170
|
-
const lazyOps = operations.map((op) => {
|
|
171
|
-
const { lazy, lazyArgs } = op;
|
|
172
|
-
if (lazy) {
|
|
173
|
-
const fn = lazy(...lazyArgs || []);
|
|
174
|
-
fn.indexed = lazy.indexed;
|
|
175
|
-
fn.single = lazy.single;
|
|
176
|
-
fn.index = 0;
|
|
177
|
-
fn.items = [];
|
|
178
|
-
return fn;
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
181
|
-
});
|
|
182
|
-
let opIdx = 0;
|
|
183
|
-
while (opIdx < operations.length) {
|
|
184
|
-
const op = operations[opIdx];
|
|
185
|
-
const lazyOp = lazyOps[opIdx];
|
|
186
|
-
if (!lazyOp) {
|
|
187
|
-
ret = op(ret);
|
|
188
|
-
opIdx++;
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
const lazySeq = [];
|
|
192
|
-
for (let j = opIdx; j < operations.length; j++) {
|
|
193
|
-
if (lazyOps[j]) {
|
|
194
|
-
lazySeq.push(lazyOps[j]);
|
|
195
|
-
if (lazyOps[j].single) {
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
} else {
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
const acc = [];
|
|
203
|
-
for (const item of ret) {
|
|
204
|
-
if (_processItem({ acc, item, lazySeq })) {
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
const lastLazySeq = lazySeq[lazySeq.length - 1];
|
|
209
|
-
if (lastLazySeq.single) {
|
|
210
|
-
ret = acc[0];
|
|
211
|
-
} else {
|
|
212
|
-
ret = acc;
|
|
213
|
-
}
|
|
214
|
-
opIdx += lazySeq.length;
|
|
215
|
-
}
|
|
216
|
-
return ret;
|
|
217
|
-
}
|
|
218
|
-
function _processItem({
|
|
219
|
-
acc,
|
|
220
|
-
item,
|
|
221
|
-
lazySeq
|
|
222
|
-
}) {
|
|
223
|
-
if (lazySeq.length === 0) {
|
|
224
|
-
acc.push(item);
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
let lazyResult = { done: false, hasNext: false };
|
|
228
|
-
let isDone = false;
|
|
229
|
-
for (let i = 0; i < lazySeq.length; i++) {
|
|
230
|
-
const lazyFn = lazySeq[i];
|
|
231
|
-
const indexed = lazyFn.indexed;
|
|
232
|
-
const index = lazyFn.index;
|
|
233
|
-
const items = lazyFn.items;
|
|
234
|
-
items.push(item);
|
|
235
|
-
lazyResult = indexed ? lazyFn(item, index, items) : lazyFn(item);
|
|
236
|
-
lazyFn.index++;
|
|
237
|
-
if (lazyResult.hasNext) {
|
|
238
|
-
if (lazyResult.hasMany) {
|
|
239
|
-
const nextValues = lazyResult.next;
|
|
240
|
-
for (const subItem of nextValues) {
|
|
241
|
-
const subResult = _processItem({
|
|
242
|
-
acc,
|
|
243
|
-
item: subItem,
|
|
244
|
-
lazySeq: lazySeq.slice(i + 1)
|
|
245
|
-
});
|
|
246
|
-
if (subResult) {
|
|
247
|
-
return true;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return false;
|
|
251
|
-
} else {
|
|
252
|
-
item = lazyResult.next;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (!lazyResult.hasNext) {
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
if (lazyResult.done) {
|
|
259
|
-
isDone = true;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (lazyResult.hasNext) {
|
|
263
|
-
acc.push(item);
|
|
264
|
-
}
|
|
265
|
-
return !!isDone;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// src/function/create-pipe.ts
|
|
269
|
-
function createPipe(...operations) {
|
|
270
|
-
return (value) => pipe(value, ...operations);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// src/function/identity.ts
|
|
274
|
-
function identity(value) {
|
|
275
|
-
return value;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// src/function/noop.ts
|
|
279
|
-
function noop() {
|
|
280
|
-
return void 0;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// src/function/once.ts
|
|
284
|
-
function once(fn) {
|
|
285
|
-
let called = false;
|
|
286
|
-
let ret;
|
|
287
|
-
return () => {
|
|
288
|
-
if (!called) {
|
|
289
|
-
ret = fn();
|
|
290
|
-
called = true;
|
|
291
|
-
}
|
|
292
|
-
return ret;
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/function/debounce.ts
|
|
297
|
-
function debounce(func, {
|
|
298
|
-
maxWaitMs,
|
|
299
|
-
timing = "trailing",
|
|
300
|
-
waitMs
|
|
301
|
-
}) {
|
|
302
|
-
if (maxWaitMs !== void 0 && waitMs !== void 0 && maxWaitMs < waitMs) {
|
|
303
|
-
throw new Error(
|
|
304
|
-
`debounce: maxWaitMs (${maxWaitMs}) cannot be less than waitMs (${waitMs})`
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
let coolDownTimeoutId;
|
|
308
|
-
let maxWaitTimeoutId;
|
|
309
|
-
let latestCallArgs;
|
|
310
|
-
let result;
|
|
311
|
-
function handleDebouncedCall(args) {
|
|
312
|
-
latestCallArgs = args;
|
|
313
|
-
if (maxWaitMs !== void 0 && maxWaitTimeoutId === void 0) {
|
|
314
|
-
maxWaitTimeoutId = setTimeout(handleInvoke, maxWaitMs);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
function handleInvoke() {
|
|
318
|
-
if (latestCallArgs === void 0) {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
if (maxWaitTimeoutId !== void 0) {
|
|
322
|
-
const timeoutId = maxWaitTimeoutId;
|
|
323
|
-
maxWaitTimeoutId = void 0;
|
|
324
|
-
clearTimeout(timeoutId);
|
|
325
|
-
}
|
|
326
|
-
const args = latestCallArgs;
|
|
327
|
-
latestCallArgs = void 0;
|
|
328
|
-
result = func(...args);
|
|
329
|
-
}
|
|
330
|
-
function handleCoolDownEnd() {
|
|
331
|
-
if (coolDownTimeoutId === void 0) {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
const timeoutId = coolDownTimeoutId;
|
|
335
|
-
coolDownTimeoutId = void 0;
|
|
336
|
-
clearTimeout(timeoutId);
|
|
337
|
-
if (latestCallArgs !== void 0) {
|
|
338
|
-
handleInvoke();
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
get cachedValue() {
|
|
343
|
-
return result;
|
|
344
|
-
},
|
|
345
|
-
call: (...args) => {
|
|
346
|
-
if (coolDownTimeoutId === void 0) {
|
|
347
|
-
if (timing === "trailing") {
|
|
348
|
-
handleDebouncedCall(args);
|
|
349
|
-
} else {
|
|
350
|
-
result = func(...args);
|
|
351
|
-
}
|
|
352
|
-
} else {
|
|
353
|
-
if (timing !== "leading") {
|
|
354
|
-
handleDebouncedCall(args);
|
|
355
|
-
}
|
|
356
|
-
const timeoutId = coolDownTimeoutId;
|
|
357
|
-
coolDownTimeoutId = void 0;
|
|
358
|
-
clearTimeout(timeoutId);
|
|
359
|
-
}
|
|
360
|
-
coolDownTimeoutId = setTimeout(
|
|
361
|
-
handleCoolDownEnd,
|
|
362
|
-
// If waitMs is not defined but maxWaitMs *is* it means the user is only
|
|
363
|
-
// interested in the leaky-bucket nature of the debouncer which is
|
|
364
|
-
// achieved by setting waitMs === maxWaitMs. If both are not defined we
|
|
365
|
-
// default to 0 which would wait until the end of the execution frame.
|
|
366
|
-
waitMs ?? maxWaitMs ?? 0
|
|
367
|
-
);
|
|
368
|
-
return result;
|
|
369
|
-
},
|
|
370
|
-
cancel: () => {
|
|
371
|
-
if (coolDownTimeoutId !== void 0) {
|
|
372
|
-
const timeoutId = coolDownTimeoutId;
|
|
373
|
-
coolDownTimeoutId = void 0;
|
|
374
|
-
clearTimeout(timeoutId);
|
|
375
|
-
}
|
|
376
|
-
if (maxWaitTimeoutId !== void 0) {
|
|
377
|
-
const timeoutId = maxWaitTimeoutId;
|
|
378
|
-
maxWaitTimeoutId = void 0;
|
|
379
|
-
clearTimeout(timeoutId);
|
|
380
|
-
}
|
|
381
|
-
latestCallArgs = void 0;
|
|
382
|
-
},
|
|
383
|
-
flush: () => {
|
|
384
|
-
handleCoolDownEnd();
|
|
385
|
-
return result;
|
|
386
|
-
},
|
|
387
|
-
get isPending() {
|
|
388
|
-
return coolDownTimeoutId !== void 0;
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
189
|
// src/function/purry.ts
|
|
394
190
|
function purry(fn, args, lazy) {
|
|
395
191
|
const diff = fn.length - args.length;
|
|
@@ -408,13 +204,6 @@ function purry(fn, args, lazy) {
|
|
|
408
204
|
throw new Error("Wrong number of arguments");
|
|
409
205
|
}
|
|
410
206
|
|
|
411
|
-
// src/function/sleep.ts
|
|
412
|
-
function sleep(timeout) {
|
|
413
|
-
return new Promise((resolve) => {
|
|
414
|
-
setTimeout(resolve, timeout);
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
|
|
418
207
|
// src/array/all-pass.ts
|
|
419
208
|
function allPass(...args) {
|
|
420
209
|
return purry(_allPass, args);
|
|
@@ -445,148 +234,56 @@ function _chunk(array, size) {
|
|
|
445
234
|
return ret;
|
|
446
235
|
}
|
|
447
236
|
|
|
448
|
-
// src/guard/is-
|
|
449
|
-
function
|
|
450
|
-
return
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// src/guard/is-boolean.ts
|
|
454
|
-
function isBoolean(data) {
|
|
455
|
-
return typeof data === "boolean";
|
|
237
|
+
// src/guard/is-truthy.ts
|
|
238
|
+
function isTruthy(data) {
|
|
239
|
+
return !!data;
|
|
456
240
|
}
|
|
457
241
|
|
|
458
|
-
// src/
|
|
459
|
-
function
|
|
460
|
-
return
|
|
242
|
+
// src/array/compact.ts
|
|
243
|
+
function compact(items) {
|
|
244
|
+
return items.filter(isTruthy);
|
|
461
245
|
}
|
|
462
246
|
|
|
463
|
-
// src/
|
|
464
|
-
function
|
|
465
|
-
return
|
|
247
|
+
// src/array/concat.ts
|
|
248
|
+
function concat(...args) {
|
|
249
|
+
return purry(_concat, args);
|
|
466
250
|
}
|
|
467
|
-
(
|
|
468
|
-
|
|
469
|
-
return data !== void 0;
|
|
470
|
-
}
|
|
471
|
-
isDefined2.strict = strict;
|
|
472
|
-
})(isDefined || (isDefined = {}));
|
|
473
|
-
|
|
474
|
-
// src/base.ts
|
|
475
|
-
function toString(value) {
|
|
476
|
-
return Object.prototype.toString.call(value);
|
|
251
|
+
function _concat(arr1, arr2) {
|
|
252
|
+
return arr1.concat(arr2);
|
|
477
253
|
}
|
|
478
254
|
|
|
479
|
-
// src/
|
|
480
|
-
function
|
|
481
|
-
return
|
|
255
|
+
// src/array/count-by.ts
|
|
256
|
+
function _countBy(indexed) {
|
|
257
|
+
return (array, fn) => {
|
|
258
|
+
return array.reduce((ret, item, index) => {
|
|
259
|
+
const value = indexed ? fn(item, index, array) : fn(item);
|
|
260
|
+
return ret + (value ? 1 : 0);
|
|
261
|
+
}, 0);
|
|
262
|
+
};
|
|
482
263
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
function isString(data) {
|
|
486
|
-
return typeof data === "string";
|
|
264
|
+
function countBy(...args) {
|
|
265
|
+
return purry(_countBy(false), args);
|
|
487
266
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
if (isArray(data) || isString(data)) {
|
|
492
|
-
return data.length === 0;
|
|
267
|
+
((countBy2) => {
|
|
268
|
+
function indexed(...args) {
|
|
269
|
+
return purry(_countBy(true), args);
|
|
493
270
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
271
|
+
countBy2.indexed = indexed;
|
|
272
|
+
})(countBy || (countBy = {}));
|
|
273
|
+
|
|
274
|
+
// src/utils/reduce-lazy.ts
|
|
275
|
+
function reduceLazy(array, lazy, indexed) {
|
|
276
|
+
const newArray = [];
|
|
277
|
+
for (let index = 0; index < array.length; index++) {
|
|
278
|
+
const item = array[index];
|
|
279
|
+
const result = indexed ? lazy(item, index, array) : lazy(item);
|
|
280
|
+
if (result.hasMany === true) {
|
|
281
|
+
newArray.push(...result.next);
|
|
282
|
+
} else if (result.hasNext) {
|
|
283
|
+
newArray.push(result.next);
|
|
497
284
|
}
|
|
498
|
-
return !(data instanceof RegExp);
|
|
499
285
|
}
|
|
500
|
-
return
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// src/guard/is-error.ts
|
|
504
|
-
function isError(data) {
|
|
505
|
-
return data instanceof Error;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// src/guard/is-function.ts
|
|
509
|
-
function isFunction(data) {
|
|
510
|
-
return typeof data === "function";
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// src/guard/is-nil.ts
|
|
514
|
-
function isNil(data) {
|
|
515
|
-
return data == null;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// src/guard/is-non-null.ts
|
|
519
|
-
function isNonNull(data) {
|
|
520
|
-
return data !== null;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// src/guard/is-not.ts
|
|
524
|
-
function isNot(predicate) {
|
|
525
|
-
return (data) => {
|
|
526
|
-
return !predicate(data);
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// src/guard/is-number.ts
|
|
531
|
-
function isNumber(data) {
|
|
532
|
-
return typeof data === "number" && !Number.isNaN(data);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
// src/guard/is-promise.ts
|
|
536
|
-
function isPromise(data) {
|
|
537
|
-
return data instanceof Promise;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
// src/guard/is-truthy.ts
|
|
541
|
-
function isTruthy(data) {
|
|
542
|
-
return !!data;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// src/array/compact.ts
|
|
546
|
-
function compact(items) {
|
|
547
|
-
return items.filter(isTruthy);
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// src/array/concat.ts
|
|
551
|
-
function concat(...args) {
|
|
552
|
-
return purry(_concat, args);
|
|
553
|
-
}
|
|
554
|
-
function _concat(arr1, arr2) {
|
|
555
|
-
return arr1.concat(arr2);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
// src/array/count-by.ts
|
|
559
|
-
function _countBy(indexed) {
|
|
560
|
-
return (array, fn) => {
|
|
561
|
-
return array.reduce((ret, item, index) => {
|
|
562
|
-
const value = indexed ? fn(item, index, array) : fn(item);
|
|
563
|
-
return ret + (value ? 1 : 0);
|
|
564
|
-
}, 0);
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
function countBy(...args) {
|
|
568
|
-
return purry(_countBy(false), args);
|
|
569
|
-
}
|
|
570
|
-
((countBy2) => {
|
|
571
|
-
function indexed(...args) {
|
|
572
|
-
return purry(_countBy(true), args);
|
|
573
|
-
}
|
|
574
|
-
countBy2.indexed = indexed;
|
|
575
|
-
})(countBy || (countBy = {}));
|
|
576
|
-
|
|
577
|
-
// src/utils/reduce-lazy.ts
|
|
578
|
-
function _reduceLazy(array, lazy, indexed) {
|
|
579
|
-
const newArray = [];
|
|
580
|
-
for (let index = 0; index < array.length; index++) {
|
|
581
|
-
const item = array[index];
|
|
582
|
-
const result = indexed ? lazy(item, index, array) : lazy(item);
|
|
583
|
-
if (result.hasMany === true) {
|
|
584
|
-
newArray.push(...result.next);
|
|
585
|
-
} else if (result.hasNext) {
|
|
586
|
-
newArray.push(result.next);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
return newArray;
|
|
286
|
+
return newArray;
|
|
590
287
|
}
|
|
591
288
|
|
|
592
289
|
// src/array/difference-with.ts
|
|
@@ -595,7 +292,7 @@ function differenceWith(...args) {
|
|
|
595
292
|
}
|
|
596
293
|
function _differenceWith(array, other, isEquals) {
|
|
597
294
|
const lazy = differenceWith.lazy(other, isEquals);
|
|
598
|
-
return
|
|
295
|
+
return reduceLazy(array, lazy);
|
|
599
296
|
}
|
|
600
297
|
((differenceWith2) => {
|
|
601
298
|
function lazy(other, isEquals) {
|
|
@@ -622,7 +319,7 @@ function difference(...args) {
|
|
|
622
319
|
}
|
|
623
320
|
function _difference(array, other) {
|
|
624
321
|
const lazy = difference.lazy(other);
|
|
625
|
-
return
|
|
322
|
+
return reduceLazy(array, lazy);
|
|
626
323
|
}
|
|
627
324
|
((difference2) => {
|
|
628
325
|
function lazy(other) {
|
|
@@ -661,7 +358,7 @@ function drop(...args) {
|
|
|
661
358
|
return purry(_drop, args, drop.lazy);
|
|
662
359
|
}
|
|
663
360
|
function _drop(array, n) {
|
|
664
|
-
return
|
|
361
|
+
return reduceLazy(array, drop.lazy(n));
|
|
665
362
|
}
|
|
666
363
|
((drop2) => {
|
|
667
364
|
function lazy(n) {
|
|
@@ -684,26 +381,179 @@ function _drop(array, n) {
|
|
|
684
381
|
drop2.lazy = lazy;
|
|
685
382
|
})(drop || (drop = {}));
|
|
686
383
|
|
|
384
|
+
// src/array/has-at-least.ts
|
|
385
|
+
function hasAtLeast(...args) {
|
|
386
|
+
return purry(hasAtLeastImplementation, args);
|
|
387
|
+
}
|
|
388
|
+
function hasAtLeastImplementation(data, minimum) {
|
|
389
|
+
return data.length >= minimum;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/utils/swap-in-place.ts
|
|
393
|
+
function swapInPlace(data, i, j) {
|
|
394
|
+
[data[i], data[j]] = [data[j], data[i]];
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/utils/heap.ts
|
|
398
|
+
function heapify(heap, compareFn) {
|
|
399
|
+
for (let i = Math.floor(heap.length / 2) - 1; i >= 0; i--) {
|
|
400
|
+
heapSiftDown(heap, i, compareFn);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function heapMaybeInsert(heap, compareFn, item) {
|
|
404
|
+
if (!hasAtLeast(heap, 1)) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const head = heap[0];
|
|
408
|
+
if (compareFn(item, head) >= 0) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
heap[0] = item;
|
|
412
|
+
heapSiftDown(heap, 0, compareFn);
|
|
413
|
+
return head;
|
|
414
|
+
}
|
|
415
|
+
function heapSiftDown(heap, index, compareFn) {
|
|
416
|
+
let currentIndex = index;
|
|
417
|
+
while (currentIndex * 2 + 1 < heap.length) {
|
|
418
|
+
const firstChildIndex = currentIndex * 2 + 1;
|
|
419
|
+
let swapIndex = compareFn(heap[currentIndex], heap[firstChildIndex]) < 0 ? firstChildIndex : currentIndex;
|
|
420
|
+
const secondChildIndex = firstChildIndex + 1;
|
|
421
|
+
if (secondChildIndex < heap.length && compareFn(heap[swapIndex], heap[secondChildIndex]) < 0) {
|
|
422
|
+
swapIndex = secondChildIndex;
|
|
423
|
+
}
|
|
424
|
+
if (swapIndex === currentIndex) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
swapInPlace(heap, currentIndex, swapIndex);
|
|
428
|
+
currentIndex = swapIndex;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// src/utils/purry-order-rules.ts
|
|
433
|
+
var COMPARATORS = {
|
|
434
|
+
asc: (x, y) => x > y,
|
|
435
|
+
desc: (x, y) => x < y
|
|
436
|
+
};
|
|
437
|
+
function purryOrderRules(func, inputArgs) {
|
|
438
|
+
const [dataOrRule, ...rules] = Array.isArray(inputArgs) ? inputArgs : Array.from(inputArgs);
|
|
439
|
+
if (!isOrderRule(dataOrRule)) {
|
|
440
|
+
const compareFn2 = orderRuleComparer(...rules);
|
|
441
|
+
return func(dataOrRule, compareFn2);
|
|
442
|
+
}
|
|
443
|
+
const compareFn = orderRuleComparer(dataOrRule, ...rules);
|
|
444
|
+
return (data) => func(data, compareFn);
|
|
445
|
+
}
|
|
446
|
+
function purryOrderRulesWithArgument(func, inputArgs) {
|
|
447
|
+
const [first2, second, ...rest] = Array.from(inputArgs);
|
|
448
|
+
let arg;
|
|
449
|
+
let argRemoved;
|
|
450
|
+
if (isOrderRule(second)) {
|
|
451
|
+
arg = first2;
|
|
452
|
+
argRemoved = [second, ...rest];
|
|
453
|
+
} else {
|
|
454
|
+
arg = second;
|
|
455
|
+
argRemoved = [first2, ...rest];
|
|
456
|
+
}
|
|
457
|
+
return purryOrderRules((...args) => func(...args, arg), argRemoved);
|
|
458
|
+
}
|
|
459
|
+
function orderRuleComparer(primaryRule, secondaryRule, ...otherRules) {
|
|
460
|
+
const projector = typeof primaryRule === "function" ? primaryRule : primaryRule[0];
|
|
461
|
+
const direction = typeof primaryRule === "function" ? "asc" : primaryRule[1];
|
|
462
|
+
const comparator = COMPARATORS[direction];
|
|
463
|
+
const nextComparer = secondaryRule === void 0 ? void 0 : orderRuleComparer(secondaryRule, ...otherRules);
|
|
464
|
+
return (a, b) => {
|
|
465
|
+
const projectedA = projector(a);
|
|
466
|
+
const projectedB = projector(b);
|
|
467
|
+
if (comparator(projectedA, projectedB)) {
|
|
468
|
+
return 1;
|
|
469
|
+
}
|
|
470
|
+
if (comparator(projectedB, projectedA)) {
|
|
471
|
+
return -1;
|
|
472
|
+
}
|
|
473
|
+
return nextComparer?.(a, b) ?? 0;
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function isOrderRule(x) {
|
|
477
|
+
if (isProjection(x)) {
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
if (typeof x !== "object" || !Array.isArray(x)) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
const [maybeProjection, maybeDirection, ...rest] = x;
|
|
484
|
+
return isProjection(maybeProjection) && maybeDirection in COMPARATORS && rest.length === 0;
|
|
485
|
+
}
|
|
486
|
+
function isProjection(x) {
|
|
487
|
+
return typeof x === "function" && x.length === 1;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// src/array/drop-first-by.ts
|
|
491
|
+
function dropFirstBy(...args) {
|
|
492
|
+
return purryOrderRulesWithArgument(dropFirstByImplementation, args);
|
|
493
|
+
}
|
|
494
|
+
function dropFirstByImplementation(data, compareFn, n) {
|
|
495
|
+
if (n >= data.length) {
|
|
496
|
+
return [];
|
|
497
|
+
}
|
|
498
|
+
if (n <= 0) {
|
|
499
|
+
return [...data];
|
|
500
|
+
}
|
|
501
|
+
const heap = data.slice(0, n);
|
|
502
|
+
heapify(heap, compareFn);
|
|
503
|
+
const out = [];
|
|
504
|
+
const rest = data.slice(n);
|
|
505
|
+
for (const item of rest) {
|
|
506
|
+
const previousHead = heapMaybeInsert(heap, compareFn, item);
|
|
507
|
+
out.push(previousHead ?? item);
|
|
508
|
+
}
|
|
509
|
+
return out;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// src/array/drop-last-while.ts
|
|
513
|
+
function dropLastWhile(...args) {
|
|
514
|
+
return purry(_dropLastWhile, args);
|
|
515
|
+
}
|
|
516
|
+
function _dropLastWhile(data, predicate) {
|
|
517
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
518
|
+
if (!predicate(data[i])) {
|
|
519
|
+
return data.slice(0, i + 1);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return [];
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// src/array/drop-while.ts
|
|
526
|
+
function dropWhile(...args) {
|
|
527
|
+
return purry(_dropWhile, args);
|
|
528
|
+
}
|
|
529
|
+
function _dropWhile(data, predicate) {
|
|
530
|
+
for (let i = 0; i < data.length; i++) {
|
|
531
|
+
if (!predicate(data[i])) {
|
|
532
|
+
return data.slice(i);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return [];
|
|
536
|
+
}
|
|
537
|
+
|
|
687
538
|
// src/utils/to-lazy-indexed.ts
|
|
688
539
|
function toLazyIndexed(fn) {
|
|
689
|
-
fn
|
|
690
|
-
return fn;
|
|
540
|
+
return Object.assign(fn, { indexed: true });
|
|
691
541
|
}
|
|
692
542
|
|
|
693
543
|
// src/array/filter.ts
|
|
694
544
|
function filter(...args) {
|
|
695
|
-
return purry(
|
|
545
|
+
return purry(filter_(false), args, filter.lazy);
|
|
696
546
|
}
|
|
697
|
-
function
|
|
547
|
+
function filter_(indexed) {
|
|
698
548
|
return (array, fn) => {
|
|
699
|
-
return
|
|
549
|
+
return reduceLazy(
|
|
700
550
|
array,
|
|
701
551
|
indexed ? filter.lazyIndexed(fn) : filter.lazy(fn),
|
|
702
552
|
indexed
|
|
703
553
|
);
|
|
704
554
|
};
|
|
705
555
|
}
|
|
706
|
-
function
|
|
556
|
+
function lazy_(indexed) {
|
|
707
557
|
return (fn) => {
|
|
708
558
|
return (value, index, array) => {
|
|
709
559
|
const valid = indexed ? fn(value, index, array) : fn(value);
|
|
@@ -723,11 +573,11 @@ function _lazy(indexed) {
|
|
|
723
573
|
}
|
|
724
574
|
((filter2) => {
|
|
725
575
|
function indexed(...args) {
|
|
726
|
-
return purry(
|
|
576
|
+
return purry(filter_(true), args, filter2.lazyIndexed);
|
|
727
577
|
}
|
|
728
578
|
filter2.indexed = indexed;
|
|
729
|
-
filter2.lazy =
|
|
730
|
-
filter2.lazyIndexed = toLazyIndexed(
|
|
579
|
+
filter2.lazy = lazy_(false);
|
|
580
|
+
filter2.lazyIndexed = toLazyIndexed(lazy_(true));
|
|
731
581
|
})(filter || (filter = {}));
|
|
732
582
|
|
|
733
583
|
// src/utils/to-single.ts
|
|
@@ -748,7 +598,7 @@ function _findIndex(indexed) {
|
|
|
748
598
|
return array.findIndex((x) => fn(x));
|
|
749
599
|
};
|
|
750
600
|
}
|
|
751
|
-
function
|
|
601
|
+
function _lazy(indexed) {
|
|
752
602
|
return (fn) => {
|
|
753
603
|
let i = 0;
|
|
754
604
|
return (value, index, array) => {
|
|
@@ -773,8 +623,8 @@ function _lazy2(indexed) {
|
|
|
773
623
|
return purry(_findIndex(true), args, findIndex2.lazyIndexed);
|
|
774
624
|
}
|
|
775
625
|
findIndex2.indexed = indexed;
|
|
776
|
-
findIndex2.lazy = toSingle(
|
|
777
|
-
findIndex2.lazyIndexed = toSingle(toLazyIndexed(
|
|
626
|
+
findIndex2.lazy = toSingle(_lazy(false));
|
|
627
|
+
findIndex2.lazyIndexed = toSingle(toLazyIndexed(_lazy(true)));
|
|
778
628
|
})(findIndex || (findIndex = {}));
|
|
779
629
|
|
|
780
630
|
// src/array/find-last-index.ts
|
|
@@ -809,6 +659,7 @@ function _findLast(indexed) {
|
|
|
809
659
|
return array[i];
|
|
810
660
|
}
|
|
811
661
|
}
|
|
662
|
+
return void 0;
|
|
812
663
|
};
|
|
813
664
|
}
|
|
814
665
|
((findLast2) => {
|
|
@@ -830,7 +681,7 @@ function _find(indexed) {
|
|
|
830
681
|
return array.find((x) => fn(x));
|
|
831
682
|
};
|
|
832
683
|
}
|
|
833
|
-
function
|
|
684
|
+
function _lazy2(indexed) {
|
|
834
685
|
return (fn) => {
|
|
835
686
|
return (value, index, array) => {
|
|
836
687
|
const valid = indexed ? fn(value, index, array) : fn(value);
|
|
@@ -847,8 +698,8 @@ function _lazy3(indexed) {
|
|
|
847
698
|
return purry(_find(true), args, find2.lazyIndexed);
|
|
848
699
|
}
|
|
849
700
|
find2.indexed = indexed;
|
|
850
|
-
find2.lazy = toSingle(
|
|
851
|
-
find2.lazyIndexed = toSingle(toLazyIndexed(
|
|
701
|
+
find2.lazy = toSingle(_lazy2(false));
|
|
702
|
+
find2.lazyIndexed = toSingle(toLazyIndexed(_lazy2(true)));
|
|
852
703
|
})(find || (find = {}));
|
|
853
704
|
|
|
854
705
|
// src/array/first.ts
|
|
@@ -874,6 +725,24 @@ function _first([first2]) {
|
|
|
874
725
|
})(lazy = first2.lazy || (first2.lazy = {}));
|
|
875
726
|
})(first || (first = {}));
|
|
876
727
|
|
|
728
|
+
// src/array/first-by.ts
|
|
729
|
+
function firstBy(...args) {
|
|
730
|
+
return purryOrderRules(firstByImplementation, args);
|
|
731
|
+
}
|
|
732
|
+
function firstByImplementation(data, compareFn) {
|
|
733
|
+
if (!hasAtLeast(data, 2)) {
|
|
734
|
+
return data[0];
|
|
735
|
+
}
|
|
736
|
+
let [currentFirst] = data;
|
|
737
|
+
const [, ...rest] = data;
|
|
738
|
+
for (const item of rest) {
|
|
739
|
+
if (compareFn(item, currentFirst) < 0) {
|
|
740
|
+
currentFirst = item;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return currentFirst;
|
|
744
|
+
}
|
|
745
|
+
|
|
877
746
|
// src/array/flat-map-to-obj.ts
|
|
878
747
|
function flatMapToObj(...args) {
|
|
879
748
|
return purry(_flatMapToObj(false), args);
|
|
@@ -901,7 +770,7 @@ function flatten(...args) {
|
|
|
901
770
|
return purry(_flatten, args, flatten.lazy);
|
|
902
771
|
}
|
|
903
772
|
function _flatten(items) {
|
|
904
|
-
return
|
|
773
|
+
return reduceLazy(items, flatten.lazy());
|
|
905
774
|
}
|
|
906
775
|
((flatten2) => {
|
|
907
776
|
function lazy() {
|
|
@@ -958,7 +827,7 @@ function flattenDeep(...args) {
|
|
|
958
827
|
return purry(_flattenDeep, args, flattenDeep.lazy);
|
|
959
828
|
}
|
|
960
829
|
function _flattenDeep(items) {
|
|
961
|
-
return
|
|
830
|
+
return reduceLazy(items, flattenDeep.lazy());
|
|
962
831
|
}
|
|
963
832
|
function _flattenDeepValue(value) {
|
|
964
833
|
if (!Array.isArray(value)) {
|
|
@@ -1002,14 +871,14 @@ function forEach(...args) {
|
|
|
1002
871
|
}
|
|
1003
872
|
function _forEach(indexed) {
|
|
1004
873
|
return (array, fn) => {
|
|
1005
|
-
return
|
|
874
|
+
return reduceLazy(
|
|
1006
875
|
array,
|
|
1007
876
|
indexed ? forEach.lazyIndexed(fn) : forEach.lazy(fn),
|
|
1008
877
|
indexed
|
|
1009
878
|
);
|
|
1010
879
|
};
|
|
1011
880
|
}
|
|
1012
|
-
function
|
|
881
|
+
function _lazy3(indexed) {
|
|
1013
882
|
return (fn) => {
|
|
1014
883
|
return (value, index, array) => {
|
|
1015
884
|
if (indexed) {
|
|
@@ -1030,8 +899,8 @@ function _lazy4(indexed) {
|
|
|
1030
899
|
return purry(_forEach(true), args, forEach2.lazyIndexed);
|
|
1031
900
|
}
|
|
1032
901
|
forEach2.indexed = indexed;
|
|
1033
|
-
forEach2.lazy =
|
|
1034
|
-
forEach2.lazyIndexed = toLazyIndexed(
|
|
902
|
+
forEach2.lazy = _lazy3(false);
|
|
903
|
+
forEach2.lazyIndexed = toLazyIndexed(_lazy3(true));
|
|
1035
904
|
})(forEach || (forEach = {}));
|
|
1036
905
|
|
|
1037
906
|
// src/array/group-by.ts
|
|
@@ -1045,10 +914,12 @@ function _groupBy(indexed) {
|
|
|
1045
914
|
const key = indexed ? fn(item, index, array) : fn(item);
|
|
1046
915
|
if (key !== void 0) {
|
|
1047
916
|
const actualKey = String(key);
|
|
1048
|
-
|
|
1049
|
-
|
|
917
|
+
let items = ret[actualKey];
|
|
918
|
+
if (items === void 0) {
|
|
919
|
+
items = [];
|
|
920
|
+
ret[actualKey] = items;
|
|
1050
921
|
}
|
|
1051
|
-
|
|
922
|
+
items.push(item);
|
|
1052
923
|
}
|
|
1053
924
|
});
|
|
1054
925
|
return ret;
|
|
@@ -1089,7 +960,7 @@ function intersection(...args) {
|
|
|
1089
960
|
}
|
|
1090
961
|
function _intersection(array, other) {
|
|
1091
962
|
const lazy = intersection.lazy(other);
|
|
1092
|
-
return
|
|
963
|
+
return reduceLazy(array, lazy);
|
|
1093
964
|
}
|
|
1094
965
|
((intersection2) => {
|
|
1095
966
|
function lazy(other) {
|
|
@@ -1117,7 +988,7 @@ function intersectionWith(...args) {
|
|
|
1117
988
|
}
|
|
1118
989
|
function _intersectionWith(array, other, comparator) {
|
|
1119
990
|
const lazy = intersectionWith.lazy(other, comparator);
|
|
1120
|
-
return
|
|
991
|
+
return reduceLazy(array, lazy);
|
|
1121
992
|
}
|
|
1122
993
|
((intersectionWith2) => {
|
|
1123
994
|
function lazy(other, comparator) {
|
|
@@ -1168,14 +1039,14 @@ function map(...args) {
|
|
|
1168
1039
|
}
|
|
1169
1040
|
function _map(indexed) {
|
|
1170
1041
|
return (array, fn) => {
|
|
1171
|
-
return
|
|
1042
|
+
return reduceLazy(
|
|
1172
1043
|
array,
|
|
1173
1044
|
indexed ? map.lazyIndexed(fn) : map.lazy(fn),
|
|
1174
1045
|
indexed
|
|
1175
1046
|
);
|
|
1176
1047
|
};
|
|
1177
1048
|
}
|
|
1178
|
-
function
|
|
1049
|
+
function _lazy4(indexed) {
|
|
1179
1050
|
return (fn) => {
|
|
1180
1051
|
return (value, index, array) => {
|
|
1181
1052
|
return {
|
|
@@ -1191,8 +1062,8 @@ function _lazy5(indexed) {
|
|
|
1191
1062
|
return purry(_map(true), args, map2.lazyIndexed);
|
|
1192
1063
|
}
|
|
1193
1064
|
map2.indexed = indexed;
|
|
1194
|
-
map2.lazy =
|
|
1195
|
-
map2.lazyIndexed = toLazyIndexed(
|
|
1065
|
+
map2.lazy = _lazy4(false);
|
|
1066
|
+
map2.lazyIndexed = toLazyIndexed(_lazy4(true));
|
|
1196
1067
|
map2.strict = map2;
|
|
1197
1068
|
})(map || (map = {}));
|
|
1198
1069
|
|
|
@@ -1202,11 +1073,14 @@ function mapToObj(...args) {
|
|
|
1202
1073
|
}
|
|
1203
1074
|
function _mapToObj(indexed) {
|
|
1204
1075
|
return (array, fn) => {
|
|
1205
|
-
return array.reduce(
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1076
|
+
return array.reduce(
|
|
1077
|
+
(result, element, index) => {
|
|
1078
|
+
const [key, value] = indexed ? fn(element, index, array) : fn(element);
|
|
1079
|
+
result[key] = value;
|
|
1080
|
+
return result;
|
|
1081
|
+
},
|
|
1082
|
+
{}
|
|
1083
|
+
);
|
|
1210
1084
|
};
|
|
1211
1085
|
}
|
|
1212
1086
|
((mapToObj2) => {
|
|
@@ -1294,8 +1168,70 @@ function minBy(...args) {
|
|
|
1294
1168
|
minBy2.indexed = indexed;
|
|
1295
1169
|
})(minBy || (minBy = {}));
|
|
1296
1170
|
|
|
1171
|
+
// src/utils/quick-select.ts
|
|
1172
|
+
function quickSelect(data, index, compareFn) {
|
|
1173
|
+
return index < 0 || index >= data.length ? void 0 : quickSelectImplementation(
|
|
1174
|
+
// We need to clone the array because quickSelect mutates it in-place.
|
|
1175
|
+
[...data],
|
|
1176
|
+
0,
|
|
1177
|
+
data.length - 1,
|
|
1178
|
+
index,
|
|
1179
|
+
compareFn
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
function quickSelectImplementation(data, left, right, index, compareFn) {
|
|
1183
|
+
if (left === right) {
|
|
1184
|
+
return data[left];
|
|
1185
|
+
}
|
|
1186
|
+
const pivotIndex = partition(data, left, right, compareFn);
|
|
1187
|
+
return index === pivotIndex ? data[index] : quickSelectImplementation(
|
|
1188
|
+
data,
|
|
1189
|
+
// We continue by recursing into the partition where index would be
|
|
1190
|
+
index < pivotIndex ? left : pivotIndex + 1,
|
|
1191
|
+
index < pivotIndex ? pivotIndex - 1 : right,
|
|
1192
|
+
index,
|
|
1193
|
+
compareFn
|
|
1194
|
+
);
|
|
1195
|
+
}
|
|
1196
|
+
function partition(data, left, right, compareFn) {
|
|
1197
|
+
const pivot = data[right];
|
|
1198
|
+
let i = left;
|
|
1199
|
+
for (let j = left; j < right; j++) {
|
|
1200
|
+
if (compareFn(data[j], pivot) < 0) {
|
|
1201
|
+
swapInPlace(data, i, j);
|
|
1202
|
+
i++;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
swapInPlace(data, i, right);
|
|
1206
|
+
return i;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// src/array/nth-by.ts
|
|
1210
|
+
function nthBy(...args) {
|
|
1211
|
+
return purryOrderRulesWithArgument(nthByImplementation, args);
|
|
1212
|
+
}
|
|
1213
|
+
function nthByImplementation(data, compareFn, index) {
|
|
1214
|
+
return quickSelect(
|
|
1215
|
+
data,
|
|
1216
|
+
// Allow negative indices gracefully
|
|
1217
|
+
index >= 0 ? index : data.length + index,
|
|
1218
|
+
compareFn
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
// src/array/only.ts
|
|
1223
|
+
function only(...args) {
|
|
1224
|
+
return purry(_only, args);
|
|
1225
|
+
}
|
|
1226
|
+
function _only(array) {
|
|
1227
|
+
if (array.length === 1) {
|
|
1228
|
+
return array[0];
|
|
1229
|
+
}
|
|
1230
|
+
return void 0;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1297
1233
|
// src/array/partition.ts
|
|
1298
|
-
function
|
|
1234
|
+
function partition2(...args) {
|
|
1299
1235
|
return purry(_partition(false), args);
|
|
1300
1236
|
}
|
|
1301
1237
|
function _partition(indexed) {
|
|
@@ -1308,12 +1244,12 @@ function _partition(indexed) {
|
|
|
1308
1244
|
return ret;
|
|
1309
1245
|
};
|
|
1310
1246
|
}
|
|
1311
|
-
((
|
|
1247
|
+
((partition3) => {
|
|
1312
1248
|
function indexed(...args) {
|
|
1313
1249
|
return purry(_partition(true), args);
|
|
1314
1250
|
}
|
|
1315
|
-
|
|
1316
|
-
})(
|
|
1251
|
+
partition3.indexed = indexed;
|
|
1252
|
+
})(partition2 || (partition2 = {}));
|
|
1317
1253
|
|
|
1318
1254
|
// src/array/range.ts
|
|
1319
1255
|
function range(...args) {
|
|
@@ -1327,6 +1263,20 @@ function _range(start, end) {
|
|
|
1327
1263
|
return ret;
|
|
1328
1264
|
}
|
|
1329
1265
|
|
|
1266
|
+
// src/array/rank-by.ts
|
|
1267
|
+
function rankBy(...args) {
|
|
1268
|
+
return purryOrderRulesWithArgument(rankByImplementation, args);
|
|
1269
|
+
}
|
|
1270
|
+
function rankByImplementation(data, compareFn, targetItem) {
|
|
1271
|
+
let rank = 0;
|
|
1272
|
+
for (const item of data) {
|
|
1273
|
+
if (compareFn(targetItem, item) > 0) {
|
|
1274
|
+
rank++;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return rank;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1330
1280
|
// src/array/reduce.ts
|
|
1331
1281
|
function reduce(...args) {
|
|
1332
1282
|
return purry(_reduce(false), args);
|
|
@@ -1352,14 +1302,14 @@ function reject(...args) {
|
|
|
1352
1302
|
}
|
|
1353
1303
|
function _reject(indexed) {
|
|
1354
1304
|
return (array, fn) => {
|
|
1355
|
-
return
|
|
1305
|
+
return reduceLazy(
|
|
1356
1306
|
array,
|
|
1357
1307
|
indexed ? reject.lazyIndexed(fn) : reject.lazy(fn),
|
|
1358
1308
|
indexed
|
|
1359
1309
|
);
|
|
1360
1310
|
};
|
|
1361
1311
|
}
|
|
1362
|
-
function
|
|
1312
|
+
function _lazy5(indexed) {
|
|
1363
1313
|
return (fn) => {
|
|
1364
1314
|
return (value, index, array) => {
|
|
1365
1315
|
const valid = indexed ? fn(value, index, array) : fn(value);
|
|
@@ -1382,8 +1332,8 @@ function _lazy6(indexed) {
|
|
|
1382
1332
|
return purry(_reject(true), args, reject2.lazyIndexed);
|
|
1383
1333
|
}
|
|
1384
1334
|
reject2.indexed = indexed;
|
|
1385
|
-
reject2.lazy =
|
|
1386
|
-
reject2.lazyIndexed = toLazyIndexed(
|
|
1335
|
+
reject2.lazy = _lazy5(false);
|
|
1336
|
+
reject2.lazyIndexed = toLazyIndexed(_lazy5(true));
|
|
1387
1337
|
})(reject || (reject = {}));
|
|
1388
1338
|
|
|
1389
1339
|
// src/array/reverse.ts
|
|
@@ -1495,6 +1445,16 @@ function comparer(primaryRule, secondaryRule, ...otherRules) {
|
|
|
1495
1445
|
sortBy2.strict = sortBy2;
|
|
1496
1446
|
})(sortBy || (sortBy = {}));
|
|
1497
1447
|
|
|
1448
|
+
// src/array/splice.ts
|
|
1449
|
+
function splice(...args) {
|
|
1450
|
+
return purry(_splice, args);
|
|
1451
|
+
}
|
|
1452
|
+
function _splice(items, start, deleteCount, replacement) {
|
|
1453
|
+
const result = [...items];
|
|
1454
|
+
result.splice(start, deleteCount, ...replacement);
|
|
1455
|
+
return result;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1498
1458
|
// src/array/split-at.ts
|
|
1499
1459
|
function splitAt(...args) {
|
|
1500
1460
|
return purry(_splitAt, args);
|
|
@@ -1563,193 +1523,611 @@ function _swapArray(item, index1, index2) {
|
|
|
1563
1523
|
result[positiveIndexB] = item[positiveIndexA];
|
|
1564
1524
|
return result;
|
|
1565
1525
|
}
|
|
1566
|
-
function _swapString(item, index1, index2) {
|
|
1567
|
-
const result = _swapArray(item.split(""), index1, index2);
|
|
1568
|
-
return result.join("");
|
|
1526
|
+
function _swapString(item, index1, index2) {
|
|
1527
|
+
const result = _swapArray(item.split(""), index1, index2);
|
|
1528
|
+
return result.join("");
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
// src/array/take.ts
|
|
1532
|
+
function take(...args) {
|
|
1533
|
+
return purry(_take, args, take.lazy);
|
|
1534
|
+
}
|
|
1535
|
+
function _take(array, n) {
|
|
1536
|
+
return reduceLazy(array, take.lazy(n));
|
|
1537
|
+
}
|
|
1538
|
+
((take2) => {
|
|
1539
|
+
function lazy(n) {
|
|
1540
|
+
return (value) => {
|
|
1541
|
+
if (n === 0) {
|
|
1542
|
+
return {
|
|
1543
|
+
done: true,
|
|
1544
|
+
hasNext: false
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
n--;
|
|
1548
|
+
if (n === 0) {
|
|
1549
|
+
return {
|
|
1550
|
+
done: true,
|
|
1551
|
+
hasNext: true,
|
|
1552
|
+
next: value
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
return {
|
|
1556
|
+
done: false,
|
|
1557
|
+
hasNext: true,
|
|
1558
|
+
next: value
|
|
1559
|
+
};
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
take2.lazy = lazy;
|
|
1563
|
+
})(take || (take = {}));
|
|
1564
|
+
|
|
1565
|
+
// src/array/take-first-by.ts
|
|
1566
|
+
function takeFirstBy(...args) {
|
|
1567
|
+
return purryOrderRulesWithArgument(takeFirstByImplementation, args);
|
|
1568
|
+
}
|
|
1569
|
+
function takeFirstByImplementation(data, compareFn, n) {
|
|
1570
|
+
if (n <= 0) {
|
|
1571
|
+
return [];
|
|
1572
|
+
}
|
|
1573
|
+
if (n >= data.length) {
|
|
1574
|
+
return [...data];
|
|
1575
|
+
}
|
|
1576
|
+
const heap = data.slice(0, n);
|
|
1577
|
+
heapify(heap, compareFn);
|
|
1578
|
+
const rest = data.slice(n);
|
|
1579
|
+
for (const item of rest) {
|
|
1580
|
+
heapMaybeInsert(heap, compareFn, item);
|
|
1581
|
+
}
|
|
1582
|
+
return heap;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
// src/array/take-while.ts
|
|
1586
|
+
function takeWhile(...args) {
|
|
1587
|
+
return purry(_takeWhile, args);
|
|
1588
|
+
}
|
|
1589
|
+
function _takeWhile(array, fn) {
|
|
1590
|
+
const ret = [];
|
|
1591
|
+
for (const item of array) {
|
|
1592
|
+
if (!fn(item)) {
|
|
1593
|
+
break;
|
|
1594
|
+
}
|
|
1595
|
+
ret.push(item);
|
|
1596
|
+
}
|
|
1597
|
+
return ret;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
// src/array/uniq.ts
|
|
1601
|
+
function uniq(...args) {
|
|
1602
|
+
return purry(_uniq, args, uniq.lazy);
|
|
1603
|
+
}
|
|
1604
|
+
function _uniq(array) {
|
|
1605
|
+
return reduceLazy(array, uniq.lazy());
|
|
1606
|
+
}
|
|
1607
|
+
((uniq2) => {
|
|
1608
|
+
function lazy() {
|
|
1609
|
+
const set2 = /* @__PURE__ */ new Set();
|
|
1610
|
+
return (value) => {
|
|
1611
|
+
if (set2.has(value)) {
|
|
1612
|
+
return {
|
|
1613
|
+
done: false,
|
|
1614
|
+
hasNext: false
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
set2.add(value);
|
|
1618
|
+
return {
|
|
1619
|
+
done: false,
|
|
1620
|
+
hasNext: true,
|
|
1621
|
+
next: value
|
|
1622
|
+
};
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
uniq2.lazy = lazy;
|
|
1626
|
+
})(uniq || (uniq = {}));
|
|
1627
|
+
|
|
1628
|
+
// src/array/uniq-by.ts
|
|
1629
|
+
function uniqBy(...args) {
|
|
1630
|
+
return purry(_uniqBy, args, lazyUniqBy);
|
|
1631
|
+
}
|
|
1632
|
+
function _uniqBy(array, transformer) {
|
|
1633
|
+
return reduceLazy(array, lazyUniqBy(transformer));
|
|
1634
|
+
}
|
|
1635
|
+
function lazyUniqBy(transformer) {
|
|
1636
|
+
const set2 = /* @__PURE__ */ new Set();
|
|
1637
|
+
return (value) => {
|
|
1638
|
+
const appliedItem = transformer(value);
|
|
1639
|
+
if (set2.has(appliedItem)) {
|
|
1640
|
+
return {
|
|
1641
|
+
done: false,
|
|
1642
|
+
hasNext: false
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
set2.add(appliedItem);
|
|
1646
|
+
return {
|
|
1647
|
+
done: false,
|
|
1648
|
+
hasNext: true,
|
|
1649
|
+
next: value
|
|
1650
|
+
};
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// src/array/uniq-with.ts
|
|
1655
|
+
function uniqWith(...args) {
|
|
1656
|
+
return purry(_uniqWith, args, uniqWith.lazy);
|
|
1657
|
+
}
|
|
1658
|
+
function _uniqWith(array, isEquals) {
|
|
1659
|
+
const lazy = uniqWith.lazy(isEquals);
|
|
1660
|
+
return reduceLazy(array, lazy, true);
|
|
1661
|
+
}
|
|
1662
|
+
function _lazy6(isEquals) {
|
|
1663
|
+
return (value, index, array) => {
|
|
1664
|
+
if (array && array.findIndex((otherValue) => isEquals(value, otherValue)) === index) {
|
|
1665
|
+
return {
|
|
1666
|
+
done: false,
|
|
1667
|
+
hasNext: true,
|
|
1668
|
+
next: value
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
return {
|
|
1672
|
+
done: false,
|
|
1673
|
+
hasNext: false
|
|
1674
|
+
};
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
((uniqWith2) => {
|
|
1678
|
+
uniqWith2.lazy = toLazyIndexed(_lazy6);
|
|
1679
|
+
})(uniqWith || (uniqWith = {}));
|
|
1680
|
+
|
|
1681
|
+
// src/array/zip.ts
|
|
1682
|
+
function zip(...args) {
|
|
1683
|
+
return purry(_zip, args);
|
|
1684
|
+
}
|
|
1685
|
+
function _zip(first2, second) {
|
|
1686
|
+
const resultLength = first2.length > second.length ? second.length : first2.length;
|
|
1687
|
+
const result = [];
|
|
1688
|
+
for (let i = 0; i < resultLength; i++) {
|
|
1689
|
+
result.push([first2[i], second[i]]);
|
|
1690
|
+
}
|
|
1691
|
+
return result;
|
|
1692
|
+
}
|
|
1693
|
+
((zip2) => {
|
|
1694
|
+
zip2.strict = zip2;
|
|
1695
|
+
})(zip || (zip = {}));
|
|
1696
|
+
|
|
1697
|
+
// src/array/zip-obj.ts
|
|
1698
|
+
function zipObj(...args) {
|
|
1699
|
+
return purry(_zipObj, args);
|
|
1700
|
+
}
|
|
1701
|
+
function _zipObj(first2, second) {
|
|
1702
|
+
const resultLength = first2.length > second.length ? second.length : first2.length;
|
|
1703
|
+
const result = {};
|
|
1704
|
+
for (let i = 0; i < resultLength; i++) {
|
|
1705
|
+
result[first2[i]] = second[i];
|
|
1706
|
+
}
|
|
1707
|
+
return result;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
// src/array/zip-with.ts
|
|
1711
|
+
function zipWith(arg0, arg1, arg2) {
|
|
1712
|
+
if (typeof arg0 === "function") {
|
|
1713
|
+
return arg1 === void 0 ? (f, s) => _zipWith(f, s, arg0) : (f) => _zipWith(f, arg1, arg0);
|
|
1714
|
+
}
|
|
1715
|
+
if (arg1 === void 0 || arg2 === void 0) {
|
|
1716
|
+
throw new Error("zipWith: Missing arguments in dataFirst function call");
|
|
1717
|
+
}
|
|
1718
|
+
return _zipWith(arg0, arg1, arg2);
|
|
1719
|
+
}
|
|
1720
|
+
function _zipWith(first2, second, fn) {
|
|
1721
|
+
const resultLength = first2.length > second.length ? second.length : first2.length;
|
|
1722
|
+
const result = [];
|
|
1723
|
+
for (let i = 0; i < resultLength; i++) {
|
|
1724
|
+
result.push(fn(first2[i], second[i]));
|
|
1725
|
+
}
|
|
1726
|
+
return result;
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
// src/utils/purry-on.ts
|
|
1730
|
+
function purryOn(isArg, implementation, args) {
|
|
1731
|
+
const callArgs = Array.from(args);
|
|
1732
|
+
return isArg(args[0]) ? (data) => implementation(data, ...callArgs) : implementation(...callArgs);
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// src/function/conditional.ts
|
|
1736
|
+
function conditional(...args) {
|
|
1737
|
+
return purryOn(isCase, conditionalImplementation, args);
|
|
1738
|
+
}
|
|
1739
|
+
function conditionalImplementation(data, ...cases) {
|
|
1740
|
+
for (const [when, then] of cases) {
|
|
1741
|
+
if (when(data)) {
|
|
1742
|
+
return then(data);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
throw new Error("conditional: data failed for all cases");
|
|
1746
|
+
}
|
|
1747
|
+
function isCase(maybeCase) {
|
|
1748
|
+
if (!Array.isArray(maybeCase)) {
|
|
1749
|
+
return false;
|
|
1750
|
+
}
|
|
1751
|
+
const [when, then, ...rest] = maybeCase;
|
|
1752
|
+
return typeof when === "function" && when.length <= 1 && typeof then === "function" && then.length <= 1 && rest.length === 0;
|
|
1753
|
+
}
|
|
1754
|
+
var trivialDefaultCase = () => void 0;
|
|
1755
|
+
((conditional2) => {
|
|
1756
|
+
function defaultCase(then = trivialDefaultCase) {
|
|
1757
|
+
return [() => true, then];
|
|
1758
|
+
}
|
|
1759
|
+
conditional2.defaultCase = defaultCase;
|
|
1760
|
+
})(conditional || (conditional = {}));
|
|
1761
|
+
|
|
1762
|
+
// src/function/pipe.ts
|
|
1763
|
+
function pipe(input, ...operations) {
|
|
1764
|
+
let output = input;
|
|
1765
|
+
const lazyOperations = operations.map(
|
|
1766
|
+
(op) => "lazy" in op ? toPipedLazy(op) : void 0
|
|
1767
|
+
);
|
|
1768
|
+
let operationIndex = 0;
|
|
1769
|
+
while (operationIndex < operations.length) {
|
|
1770
|
+
const lazyOperation = lazyOperations[operationIndex];
|
|
1771
|
+
if (lazyOperation === void 0 || !isIterable(output)) {
|
|
1772
|
+
const operation = operations[operationIndex];
|
|
1773
|
+
output = operation(output);
|
|
1774
|
+
operationIndex++;
|
|
1775
|
+
continue;
|
|
1776
|
+
}
|
|
1777
|
+
const lazySequence = [];
|
|
1778
|
+
for (let j = operationIndex; j < operations.length; j++) {
|
|
1779
|
+
const lazyOp = lazyOperations[j];
|
|
1780
|
+
if (lazyOp === void 0) {
|
|
1781
|
+
break;
|
|
1782
|
+
}
|
|
1783
|
+
lazySequence.push(lazyOp);
|
|
1784
|
+
if (lazyOp.isSingle) {
|
|
1785
|
+
break;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
const accumulator = [];
|
|
1789
|
+
const iterator = output[Symbol.iterator]();
|
|
1790
|
+
while (true) {
|
|
1791
|
+
const result = iterator.next();
|
|
1792
|
+
if (result.done ?? false) {
|
|
1793
|
+
break;
|
|
1794
|
+
}
|
|
1795
|
+
const shouldExitEarly = processItem_(
|
|
1796
|
+
result.value,
|
|
1797
|
+
accumulator,
|
|
1798
|
+
lazySequence
|
|
1799
|
+
);
|
|
1800
|
+
if (shouldExitEarly) {
|
|
1801
|
+
break;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
const { isSingle } = lazySequence[lazySequence.length - 1];
|
|
1805
|
+
if (isSingle) {
|
|
1806
|
+
output = accumulator[0];
|
|
1807
|
+
} else {
|
|
1808
|
+
output = accumulator;
|
|
1809
|
+
}
|
|
1810
|
+
operationIndex += lazySequence.length;
|
|
1811
|
+
}
|
|
1812
|
+
return output;
|
|
1813
|
+
}
|
|
1814
|
+
function processItem_(item, accumulator, lazySequence) {
|
|
1815
|
+
if (lazySequence.length === 0) {
|
|
1816
|
+
accumulator.push(item);
|
|
1817
|
+
return false;
|
|
1818
|
+
}
|
|
1819
|
+
let lazyResult = { done: false, hasNext: false };
|
|
1820
|
+
let isDone = false;
|
|
1821
|
+
for (let i = 0; i < lazySequence.length; i++) {
|
|
1822
|
+
const lazyFn = lazySequence[i];
|
|
1823
|
+
const { index, isIndexed, items } = lazyFn;
|
|
1824
|
+
items.push(item);
|
|
1825
|
+
lazyResult = isIndexed ? lazyFn(item, index, items) : lazyFn(item);
|
|
1826
|
+
lazyFn.index++;
|
|
1827
|
+
if (lazyResult.hasNext) {
|
|
1828
|
+
if (lazyResult.hasMany) {
|
|
1829
|
+
const nextValues = lazyResult.next;
|
|
1830
|
+
for (const subItem of nextValues) {
|
|
1831
|
+
const subResult = processItem_(
|
|
1832
|
+
subItem,
|
|
1833
|
+
accumulator,
|
|
1834
|
+
lazySequence.slice(i + 1)
|
|
1835
|
+
);
|
|
1836
|
+
if (subResult) {
|
|
1837
|
+
return true;
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
return false;
|
|
1841
|
+
} else {
|
|
1842
|
+
item = lazyResult.next;
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
if (!lazyResult.hasNext) {
|
|
1846
|
+
break;
|
|
1847
|
+
}
|
|
1848
|
+
if (lazyResult.done) {
|
|
1849
|
+
isDone = true;
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
if (lazyResult.hasNext) {
|
|
1853
|
+
accumulator.push(item);
|
|
1854
|
+
}
|
|
1855
|
+
return isDone;
|
|
1856
|
+
}
|
|
1857
|
+
function toPipedLazy(op) {
|
|
1858
|
+
const { lazy, lazyArgs } = op;
|
|
1859
|
+
const fn = lazy(...lazyArgs ?? []);
|
|
1860
|
+
return Object.assign(fn, {
|
|
1861
|
+
index: 0,
|
|
1862
|
+
isIndexed: lazy.indexed,
|
|
1863
|
+
isSingle: lazy.single,
|
|
1864
|
+
items: []
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
function isIterable(something) {
|
|
1868
|
+
return typeof something === "string" || typeof something === "object" && something !== null && Symbol.iterator in something;
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
// src/function/create-pipe.ts
|
|
1872
|
+
function createPipe(...operations) {
|
|
1873
|
+
return (value) => pipe(value, ...operations);
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
// src/function/identity.ts
|
|
1877
|
+
function identity(value) {
|
|
1878
|
+
return value;
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// src/function/noop.ts
|
|
1882
|
+
function noop() {
|
|
1883
|
+
return void 0;
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
// src/function/once.ts
|
|
1887
|
+
function once(fn) {
|
|
1888
|
+
let called = false;
|
|
1889
|
+
let ret;
|
|
1890
|
+
return () => {
|
|
1891
|
+
if (!called) {
|
|
1892
|
+
ret = fn();
|
|
1893
|
+
called = true;
|
|
1894
|
+
}
|
|
1895
|
+
return ret;
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
// src/function/debounce.ts
|
|
1900
|
+
function debounce(func, {
|
|
1901
|
+
maxWaitMs,
|
|
1902
|
+
timing = "trailing",
|
|
1903
|
+
waitMs
|
|
1904
|
+
}) {
|
|
1905
|
+
if (maxWaitMs !== void 0 && waitMs !== void 0 && maxWaitMs < waitMs) {
|
|
1906
|
+
throw new Error(
|
|
1907
|
+
`debounce: maxWaitMs (${maxWaitMs}) cannot be less than waitMs (${waitMs})`
|
|
1908
|
+
);
|
|
1909
|
+
}
|
|
1910
|
+
let coolDownTimeoutId;
|
|
1911
|
+
let maxWaitTimeoutId;
|
|
1912
|
+
let latestCallArgs;
|
|
1913
|
+
let result;
|
|
1914
|
+
function handleDebouncedCall(args) {
|
|
1915
|
+
latestCallArgs = args;
|
|
1916
|
+
if (maxWaitMs !== void 0 && maxWaitTimeoutId === void 0) {
|
|
1917
|
+
maxWaitTimeoutId = setTimeout(handleInvoke, maxWaitMs);
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
function handleInvoke() {
|
|
1921
|
+
if (latestCallArgs === void 0) {
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
if (maxWaitTimeoutId !== void 0) {
|
|
1925
|
+
const timeoutId = maxWaitTimeoutId;
|
|
1926
|
+
maxWaitTimeoutId = void 0;
|
|
1927
|
+
clearTimeout(timeoutId);
|
|
1928
|
+
}
|
|
1929
|
+
const args = latestCallArgs;
|
|
1930
|
+
latestCallArgs = void 0;
|
|
1931
|
+
result = func(...args);
|
|
1932
|
+
}
|
|
1933
|
+
function handleCoolDownEnd() {
|
|
1934
|
+
if (coolDownTimeoutId === void 0) {
|
|
1935
|
+
return;
|
|
1936
|
+
}
|
|
1937
|
+
const timeoutId = coolDownTimeoutId;
|
|
1938
|
+
coolDownTimeoutId = void 0;
|
|
1939
|
+
clearTimeout(timeoutId);
|
|
1940
|
+
if (latestCallArgs !== void 0) {
|
|
1941
|
+
handleInvoke();
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return {
|
|
1945
|
+
get cachedValue() {
|
|
1946
|
+
return result;
|
|
1947
|
+
},
|
|
1948
|
+
call: (...args) => {
|
|
1949
|
+
if (coolDownTimeoutId === void 0) {
|
|
1950
|
+
if (timing === "trailing") {
|
|
1951
|
+
handleDebouncedCall(args);
|
|
1952
|
+
} else {
|
|
1953
|
+
result = func(...args);
|
|
1954
|
+
}
|
|
1955
|
+
} else {
|
|
1956
|
+
if (timing !== "leading") {
|
|
1957
|
+
handleDebouncedCall(args);
|
|
1958
|
+
}
|
|
1959
|
+
const timeoutId = coolDownTimeoutId;
|
|
1960
|
+
coolDownTimeoutId = void 0;
|
|
1961
|
+
clearTimeout(timeoutId);
|
|
1962
|
+
}
|
|
1963
|
+
coolDownTimeoutId = setTimeout(
|
|
1964
|
+
handleCoolDownEnd,
|
|
1965
|
+
// If waitMs is not defined but maxWaitMs *is* it means the user is only
|
|
1966
|
+
// interested in the leaky-bucket nature of the debouncer which is
|
|
1967
|
+
// achieved by setting waitMs === maxWaitMs. If both are not defined we
|
|
1968
|
+
// default to 0 which would wait until the end of the execution frame.
|
|
1969
|
+
waitMs ?? maxWaitMs ?? 0
|
|
1970
|
+
);
|
|
1971
|
+
return result;
|
|
1972
|
+
},
|
|
1973
|
+
cancel: () => {
|
|
1974
|
+
if (coolDownTimeoutId !== void 0) {
|
|
1975
|
+
const timeoutId = coolDownTimeoutId;
|
|
1976
|
+
coolDownTimeoutId = void 0;
|
|
1977
|
+
clearTimeout(timeoutId);
|
|
1978
|
+
}
|
|
1979
|
+
if (maxWaitTimeoutId !== void 0) {
|
|
1980
|
+
const timeoutId = maxWaitTimeoutId;
|
|
1981
|
+
maxWaitTimeoutId = void 0;
|
|
1982
|
+
clearTimeout(timeoutId);
|
|
1983
|
+
}
|
|
1984
|
+
latestCallArgs = void 0;
|
|
1985
|
+
},
|
|
1986
|
+
flush: () => {
|
|
1987
|
+
handleCoolDownEnd();
|
|
1988
|
+
return result;
|
|
1989
|
+
},
|
|
1990
|
+
get isPending() {
|
|
1991
|
+
return coolDownTimeoutId !== void 0;
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
// src/function/sleep.ts
|
|
1997
|
+
function sleep(timeout) {
|
|
1998
|
+
return new Promise((resolve) => {
|
|
1999
|
+
setTimeout(resolve, timeout);
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
// src/guard/is-array.ts
|
|
2004
|
+
function isArray(data) {
|
|
2005
|
+
return Array.isArray(data);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
// src/guard/is-boolean.ts
|
|
2009
|
+
function isBoolean(data) {
|
|
2010
|
+
return typeof data === "boolean";
|
|
1569
2011
|
}
|
|
1570
2012
|
|
|
1571
|
-
// src/
|
|
1572
|
-
function
|
|
1573
|
-
return
|
|
2013
|
+
// src/guard/is-date.ts
|
|
2014
|
+
function isDate(data) {
|
|
2015
|
+
return data instanceof Date;
|
|
1574
2016
|
}
|
|
1575
|
-
|
|
1576
|
-
|
|
2017
|
+
|
|
2018
|
+
// src/guard/is-defined.ts
|
|
2019
|
+
function isDefined(data) {
|
|
2020
|
+
return typeof data !== "undefined" && data !== null;
|
|
1577
2021
|
}
|
|
1578
|
-
((
|
|
1579
|
-
function
|
|
1580
|
-
return
|
|
1581
|
-
if (n === 0) {
|
|
1582
|
-
return {
|
|
1583
|
-
done: true,
|
|
1584
|
-
hasNext: false
|
|
1585
|
-
};
|
|
1586
|
-
}
|
|
1587
|
-
n--;
|
|
1588
|
-
if (n === 0) {
|
|
1589
|
-
return {
|
|
1590
|
-
done: true,
|
|
1591
|
-
hasNext: true,
|
|
1592
|
-
next: value
|
|
1593
|
-
};
|
|
1594
|
-
}
|
|
1595
|
-
return {
|
|
1596
|
-
done: false,
|
|
1597
|
-
hasNext: true,
|
|
1598
|
-
next: value
|
|
1599
|
-
};
|
|
1600
|
-
};
|
|
2022
|
+
((isDefined2) => {
|
|
2023
|
+
function strict(data) {
|
|
2024
|
+
return data !== void 0;
|
|
1601
2025
|
}
|
|
1602
|
-
|
|
1603
|
-
})(
|
|
2026
|
+
isDefined2.strict = strict;
|
|
2027
|
+
})(isDefined || (isDefined = {}));
|
|
1604
2028
|
|
|
1605
|
-
// src/
|
|
1606
|
-
function
|
|
1607
|
-
|
|
2029
|
+
// src/guard/is-object.ts
|
|
2030
|
+
function isObject(data) {
|
|
2031
|
+
if (typeof data !== "object" || data === null) {
|
|
2032
|
+
return false;
|
|
2033
|
+
}
|
|
2034
|
+
const proto = Object.getPrototypeOf(data);
|
|
2035
|
+
return proto === null || proto === Object.prototype;
|
|
1608
2036
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
2037
|
+
|
|
2038
|
+
// src/guard/is-string.ts
|
|
2039
|
+
function isString(data) {
|
|
2040
|
+
return typeof data === "string";
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
// src/guard/is-empty.ts
|
|
2044
|
+
function isEmpty(data) {
|
|
2045
|
+
if (isArray(data) || isString(data)) {
|
|
2046
|
+
return data.length === 0;
|
|
2047
|
+
}
|
|
2048
|
+
if (isObject(data)) {
|
|
2049
|
+
for (const _ in data) {
|
|
2050
|
+
return false;
|
|
1614
2051
|
}
|
|
1615
|
-
|
|
2052
|
+
return !(data instanceof RegExp);
|
|
1616
2053
|
}
|
|
1617
|
-
return
|
|
2054
|
+
return false;
|
|
1618
2055
|
}
|
|
1619
2056
|
|
|
1620
|
-
// src/
|
|
1621
|
-
function
|
|
1622
|
-
return
|
|
2057
|
+
// src/guard/is-error.ts
|
|
2058
|
+
function isError(data) {
|
|
2059
|
+
return data instanceof Error;
|
|
1623
2060
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
2061
|
+
|
|
2062
|
+
// src/guard/is-function.ts
|
|
2063
|
+
function isFunction(data) {
|
|
2064
|
+
return typeof data === "function";
|
|
1626
2065
|
}
|
|
1627
|
-
((uniq2) => {
|
|
1628
|
-
function lazy() {
|
|
1629
|
-
const set2 = /* @__PURE__ */ new Set();
|
|
1630
|
-
return (value) => {
|
|
1631
|
-
if (set2.has(value)) {
|
|
1632
|
-
return {
|
|
1633
|
-
done: false,
|
|
1634
|
-
hasNext: false
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1637
|
-
set2.add(value);
|
|
1638
|
-
return {
|
|
1639
|
-
done: false,
|
|
1640
|
-
hasNext: true,
|
|
1641
|
-
next: value
|
|
1642
|
-
};
|
|
1643
|
-
};
|
|
1644
|
-
}
|
|
1645
|
-
uniq2.lazy = lazy;
|
|
1646
|
-
})(uniq || (uniq = {}));
|
|
1647
2066
|
|
|
1648
|
-
// src/
|
|
1649
|
-
function
|
|
1650
|
-
return
|
|
2067
|
+
// src/guard/is-nil.ts
|
|
2068
|
+
function isNil(data) {
|
|
2069
|
+
return data == null;
|
|
1651
2070
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
2071
|
+
|
|
2072
|
+
// src/guard/is-non-null.ts
|
|
2073
|
+
function isNonNull(data) {
|
|
2074
|
+
return data !== null;
|
|
1654
2075
|
}
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
return {
|
|
1661
|
-
done: false,
|
|
1662
|
-
hasNext: false
|
|
1663
|
-
};
|
|
1664
|
-
}
|
|
1665
|
-
set2.add(appliedItem);
|
|
1666
|
-
return {
|
|
1667
|
-
done: false,
|
|
1668
|
-
hasNext: true,
|
|
1669
|
-
next: value
|
|
1670
|
-
};
|
|
2076
|
+
|
|
2077
|
+
// src/guard/is-not.ts
|
|
2078
|
+
function isNot(predicate) {
|
|
2079
|
+
return (data) => {
|
|
2080
|
+
return !predicate(data);
|
|
1671
2081
|
};
|
|
1672
2082
|
}
|
|
1673
2083
|
|
|
1674
|
-
// src/
|
|
1675
|
-
function
|
|
1676
|
-
return
|
|
1677
|
-
}
|
|
1678
|
-
function _uniqWith(array, isEquals) {
|
|
1679
|
-
const lazy = uniqWith.lazy(isEquals);
|
|
1680
|
-
return _reduceLazy(array, lazy, true);
|
|
1681
|
-
}
|
|
1682
|
-
function _lazy7(isEquals) {
|
|
1683
|
-
return (value, index, array) => {
|
|
1684
|
-
if (array && array.findIndex((otherValue) => isEquals(value, otherValue)) === index) {
|
|
1685
|
-
return {
|
|
1686
|
-
done: false,
|
|
1687
|
-
hasNext: true,
|
|
1688
|
-
next: value
|
|
1689
|
-
};
|
|
1690
|
-
}
|
|
1691
|
-
return {
|
|
1692
|
-
done: false,
|
|
1693
|
-
hasNext: false
|
|
1694
|
-
};
|
|
1695
|
-
};
|
|
2084
|
+
// src/guard/is-number.ts
|
|
2085
|
+
function isNumber(data) {
|
|
2086
|
+
return typeof data === "number" && !Number.isNaN(data);
|
|
1696
2087
|
}
|
|
1697
|
-
((uniqWith2) => {
|
|
1698
|
-
uniqWith2.lazy = toLazyIndexed(_lazy7);
|
|
1699
|
-
})(uniqWith || (uniqWith = {}));
|
|
1700
2088
|
|
|
1701
|
-
// src/
|
|
1702
|
-
function
|
|
1703
|
-
return
|
|
2089
|
+
// src/guard/is-promise.ts
|
|
2090
|
+
function isPromise(data) {
|
|
2091
|
+
return data instanceof Promise;
|
|
1704
2092
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
result.push([first2[i], second[i]]);
|
|
1710
|
-
}
|
|
1711
|
-
return result;
|
|
2093
|
+
|
|
2094
|
+
// src/guard/is-symbol.ts
|
|
2095
|
+
function isSymbol(data) {
|
|
2096
|
+
return typeof data === "symbol";
|
|
1712
2097
|
}
|
|
1713
|
-
((zip2) => {
|
|
1714
|
-
zip2.strict = zip2;
|
|
1715
|
-
})(zip || (zip = {}));
|
|
1716
2098
|
|
|
1717
|
-
// src/
|
|
1718
|
-
function
|
|
1719
|
-
return purry(
|
|
2099
|
+
// src/number/add.ts
|
|
2100
|
+
function add(...args) {
|
|
2101
|
+
return purry(_add, args);
|
|
1720
2102
|
}
|
|
1721
|
-
function
|
|
1722
|
-
|
|
1723
|
-
const result = {};
|
|
1724
|
-
for (let i = 0; i < resultLength; i++) {
|
|
1725
|
-
result[first2[i]] = second[i];
|
|
1726
|
-
}
|
|
1727
|
-
return result;
|
|
2103
|
+
function _add(value, addend) {
|
|
2104
|
+
return value + addend;
|
|
1728
2105
|
}
|
|
1729
2106
|
|
|
1730
|
-
// src/
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
2107
|
+
// src/utils/with-precision.ts
|
|
2108
|
+
var MAX_PRECISION = 15;
|
|
2109
|
+
function withPrecision(roundingFn) {
|
|
2110
|
+
return (value, precision) => {
|
|
2111
|
+
if (precision === 0) {
|
|
2112
|
+
return roundingFn(value);
|
|
2113
|
+
}
|
|
2114
|
+
if (!Number.isInteger(precision)) {
|
|
2115
|
+
throw new TypeError(`precision must be an integer: ${precision}`);
|
|
2116
|
+
}
|
|
2117
|
+
if (precision > MAX_PRECISION || precision < -MAX_PRECISION) {
|
|
2118
|
+
throw new RangeError(`precision must be between ${-MAX_PRECISION} and ${MAX_PRECISION}`);
|
|
2119
|
+
}
|
|
2120
|
+
if (Number.isNaN(value) || !Number.isFinite(value)) {
|
|
2121
|
+
return roundingFn(value);
|
|
2122
|
+
}
|
|
2123
|
+
const multiplier = 10 ** precision;
|
|
2124
|
+
return roundingFn(value * multiplier) / multiplier;
|
|
2125
|
+
};
|
|
1745
2126
|
}
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
result.push(fn(first2[i], second[i]));
|
|
1751
|
-
}
|
|
1752
|
-
return result;
|
|
2127
|
+
|
|
2128
|
+
// src/number/ceil.ts
|
|
2129
|
+
function ceil(...args) {
|
|
2130
|
+
return purry(withPrecision(Math.ceil), args);
|
|
1753
2131
|
}
|
|
1754
2132
|
|
|
1755
2133
|
// src/number/clamp.ts
|
|
@@ -1766,6 +2144,40 @@ function _clamp(value, limits) {
|
|
|
1766
2144
|
return value;
|
|
1767
2145
|
}
|
|
1768
2146
|
|
|
2147
|
+
// src/number/divide.ts
|
|
2148
|
+
function divide(...args) {
|
|
2149
|
+
return purry(_divide, args);
|
|
2150
|
+
}
|
|
2151
|
+
function _divide(value, divisor) {
|
|
2152
|
+
return value / divisor;
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
// src/number/floor.ts
|
|
2156
|
+
function floor(...args) {
|
|
2157
|
+
return purry(withPrecision(Math.floor), args);
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
// src/number/multiply.ts
|
|
2161
|
+
function multiply(...args) {
|
|
2162
|
+
return purry(_multiply, args);
|
|
2163
|
+
}
|
|
2164
|
+
function _multiply(value, multiplicand) {
|
|
2165
|
+
return value * multiplicand;
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
// src/number/round.ts
|
|
2169
|
+
function round(...args) {
|
|
2170
|
+
return purry(withPrecision(Math.round), args);
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
// src/number/subtract.ts
|
|
2174
|
+
function subtract(...args) {
|
|
2175
|
+
return purry(_subtract, args);
|
|
2176
|
+
}
|
|
2177
|
+
function _subtract(value, subtrahend) {
|
|
2178
|
+
return value - subtrahend;
|
|
2179
|
+
}
|
|
2180
|
+
|
|
1769
2181
|
// src/object/add-prop.ts
|
|
1770
2182
|
function addProp(...args) {
|
|
1771
2183
|
return purry(_addProp, args);
|
|
@@ -1955,32 +2367,36 @@ function keys(source) {
|
|
|
1955
2367
|
keys2.strict = keys2;
|
|
1956
2368
|
})(keys || (keys = {}));
|
|
1957
2369
|
|
|
2370
|
+
// src/object/to-pairs.ts
|
|
2371
|
+
function toPairs(...args) {
|
|
2372
|
+
return purry(Object.entries, args);
|
|
2373
|
+
}
|
|
2374
|
+
((toPairs2) => {
|
|
2375
|
+
toPairs2.strict = toPairs2;
|
|
2376
|
+
})(toPairs || (toPairs = {}));
|
|
2377
|
+
|
|
1958
2378
|
// src/object/map-keys.ts
|
|
1959
|
-
function mapKeys(
|
|
1960
|
-
|
|
1961
|
-
return (data) => _mapKeys(data, arg1);
|
|
1962
|
-
}
|
|
1963
|
-
return _mapKeys(arg1, arg2);
|
|
2379
|
+
function mapKeys(...args) {
|
|
2380
|
+
return purry(_mapKeys, args);
|
|
1964
2381
|
}
|
|
1965
|
-
function _mapKeys(
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
}
|
|
2382
|
+
function _mapKeys(data, fn) {
|
|
2383
|
+
const out = {};
|
|
2384
|
+
for (const [key, value] of toPairs.strict(data)) {
|
|
2385
|
+
out[fn(key, value)] = value;
|
|
2386
|
+
}
|
|
2387
|
+
return out;
|
|
1970
2388
|
}
|
|
1971
2389
|
|
|
1972
2390
|
// src/object/map-values.ts
|
|
1973
|
-
function mapValues(
|
|
1974
|
-
|
|
1975
|
-
return (data) => _mapValues(data, arg1);
|
|
1976
|
-
}
|
|
1977
|
-
return _mapValues(arg1, arg2);
|
|
2391
|
+
function mapValues(...args) {
|
|
2392
|
+
return purry(_mapValues, args);
|
|
1978
2393
|
}
|
|
1979
|
-
function _mapValues(
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
}
|
|
2394
|
+
function _mapValues(data, fn) {
|
|
2395
|
+
const out = {};
|
|
2396
|
+
for (const [key, value] of toPairs.strict(data)) {
|
|
2397
|
+
out[key] = fn(value, key);
|
|
2398
|
+
}
|
|
2399
|
+
return out;
|
|
1984
2400
|
}
|
|
1985
2401
|
|
|
1986
2402
|
// src/object/merge.ts
|
|
@@ -2022,10 +2438,10 @@ function omit(...args) {
|
|
|
2022
2438
|
return purry(_omit, args);
|
|
2023
2439
|
}
|
|
2024
2440
|
function _omit(data, propNames) {
|
|
2025
|
-
if (propNames
|
|
2441
|
+
if (!hasAtLeast(propNames, 1)) {
|
|
2026
2442
|
return { ...data };
|
|
2027
2443
|
}
|
|
2028
|
-
if (propNames
|
|
2444
|
+
if (!hasAtLeast(propNames, 2)) {
|
|
2029
2445
|
const [propName] = propNames;
|
|
2030
2446
|
const {
|
|
2031
2447
|
[propName]: omitted,
|
|
@@ -2047,7 +2463,10 @@ function omitBy(...args) {
|
|
|
2047
2463
|
return purry(_omitBy, args);
|
|
2048
2464
|
}
|
|
2049
2465
|
function _omitBy(object, fn) {
|
|
2050
|
-
|
|
2466
|
+
if (object === void 0 || object === null) {
|
|
2467
|
+
return object;
|
|
2468
|
+
}
|
|
2469
|
+
return keys.strict(object).reduce((acc, key) => {
|
|
2051
2470
|
if (!fn(object[key], key)) {
|
|
2052
2471
|
acc[key] = object[key];
|
|
2053
2472
|
}
|
|
@@ -2094,7 +2513,7 @@ function _pickBy(object, fn) {
|
|
|
2094
2513
|
if (object == null) {
|
|
2095
2514
|
return {};
|
|
2096
2515
|
}
|
|
2097
|
-
return
|
|
2516
|
+
return keys.strict(object).reduce((acc, key) => {
|
|
2098
2517
|
if (fn(object[key], key)) {
|
|
2099
2518
|
acc[key] = object[key];
|
|
2100
2519
|
}
|
|
@@ -2153,17 +2572,6 @@ function _swapProps(obj, key1, key2) {
|
|
|
2153
2572
|
};
|
|
2154
2573
|
}
|
|
2155
2574
|
|
|
2156
|
-
// src/object/to-pairs.ts
|
|
2157
|
-
function toPairs(object) {
|
|
2158
|
-
return Object.entries(object);
|
|
2159
|
-
}
|
|
2160
|
-
((toPairs2) => {
|
|
2161
|
-
function strict(object) {
|
|
2162
|
-
return Object.entries(object);
|
|
2163
|
-
}
|
|
2164
|
-
toPairs2.strict = strict;
|
|
2165
|
-
})(toPairs || (toPairs = {}));
|
|
2166
|
-
|
|
2167
2575
|
// src/object/values.ts
|
|
2168
2576
|
function values(source) {
|
|
2169
2577
|
return Object.values(source);
|
|
@@ -2176,18 +2584,18 @@ function isUppercase(char = "") {
|
|
|
2176
2584
|
if (RE_NUMBER_CHAR.test(char)) {
|
|
2177
2585
|
return void 0;
|
|
2178
2586
|
}
|
|
2179
|
-
return char.
|
|
2587
|
+
return char !== char.toLowerCase();
|
|
2180
2588
|
}
|
|
2181
|
-
function splitByCase(
|
|
2589
|
+
function splitByCase(str, separators) {
|
|
2182
2590
|
const splitters = separators ?? STR_SPLITTERS;
|
|
2183
2591
|
const parts = [];
|
|
2184
|
-
if (!
|
|
2592
|
+
if (!str || !isString(str)) {
|
|
2185
2593
|
return parts;
|
|
2186
2594
|
}
|
|
2187
2595
|
let buff = "";
|
|
2188
2596
|
let previousUpper;
|
|
2189
2597
|
let previousSplitter;
|
|
2190
|
-
for (const char of
|
|
2598
|
+
for (const char of str) {
|
|
2191
2599
|
const isSplitter = splitters.includes(char);
|
|
2192
2600
|
if (isSplitter === true) {
|
|
2193
2601
|
parts.push(buff);
|
|
@@ -2204,7 +2612,7 @@ function splitByCase(string_, separators) {
|
|
|
2204
2612
|
continue;
|
|
2205
2613
|
}
|
|
2206
2614
|
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
2207
|
-
const lastChar = buff
|
|
2615
|
+
const lastChar = buff.at(-1);
|
|
2208
2616
|
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
2209
2617
|
buff = lastChar + char;
|
|
2210
2618
|
previousUpper = isUpper;
|
|
@@ -2218,23 +2626,33 @@ function splitByCase(string_, separators) {
|
|
|
2218
2626
|
parts.push(buff);
|
|
2219
2627
|
return parts;
|
|
2220
2628
|
}
|
|
2221
|
-
function toUpperFirst(
|
|
2222
|
-
return
|
|
2629
|
+
function toUpperFirst(str) {
|
|
2630
|
+
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
2631
|
+
}
|
|
2632
|
+
function toLowerFirst(str) {
|
|
2633
|
+
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
2634
|
+
}
|
|
2635
|
+
function toPascalCase(str, opts) {
|
|
2636
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => toUpperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
2637
|
+
}
|
|
2638
|
+
function toCamelCase(str, opts) {
|
|
2639
|
+
return toLowerFirst(toPascalCase(str || "", opts));
|
|
2223
2640
|
}
|
|
2224
|
-
function
|
|
2225
|
-
return
|
|
2641
|
+
function toKebabCase(str, joiner) {
|
|
2642
|
+
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
2226
2643
|
}
|
|
2227
|
-
function
|
|
2228
|
-
return
|
|
2644
|
+
function toSnakeCase(str) {
|
|
2645
|
+
return toKebabCase(str || "", "_");
|
|
2229
2646
|
}
|
|
2230
|
-
function
|
|
2231
|
-
return
|
|
2647
|
+
function toFlatCase(str) {
|
|
2648
|
+
return toKebabCase(str || "", "");
|
|
2232
2649
|
}
|
|
2233
|
-
function
|
|
2234
|
-
return
|
|
2650
|
+
function toTrainCase(str, opts) {
|
|
2651
|
+
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => toUpperFirst(opts?.normalize ? p.toLowerCase() : p)).join("-");
|
|
2235
2652
|
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2653
|
+
var titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
|
|
2654
|
+
function titleCase(str, opts) {
|
|
2655
|
+
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => titleCaseExceptions.test(p) ? p.toLowerCase() : toUpperFirst(opts?.normalize ? p.toLowerCase() : p)).join(" ");
|
|
2238
2656
|
}
|
|
2239
2657
|
|
|
2240
2658
|
// src/string/human-readable-file-size.ts
|
|
@@ -2285,21 +2703,28 @@ var isBrowser = typeof window !== "undefined";
|
|
|
2285
2703
|
0 && (module.exports = {
|
|
2286
2704
|
KEY_CODES,
|
|
2287
2705
|
_setPath,
|
|
2706
|
+
add,
|
|
2288
2707
|
addProp,
|
|
2289
2708
|
allPass,
|
|
2290
2709
|
anyPass,
|
|
2710
|
+
ceil,
|
|
2291
2711
|
chunk,
|
|
2292
2712
|
clamp,
|
|
2293
2713
|
clone,
|
|
2294
2714
|
compact,
|
|
2295
2715
|
concat,
|
|
2716
|
+
conditional,
|
|
2296
2717
|
countBy,
|
|
2297
2718
|
createPipe,
|
|
2298
2719
|
debounce,
|
|
2299
2720
|
difference,
|
|
2300
2721
|
differenceWith,
|
|
2722
|
+
divide,
|
|
2301
2723
|
drop,
|
|
2724
|
+
dropFirstBy,
|
|
2302
2725
|
dropLast,
|
|
2726
|
+
dropLastWhile,
|
|
2727
|
+
dropWhile,
|
|
2303
2728
|
equals,
|
|
2304
2729
|
filter,
|
|
2305
2730
|
find,
|
|
@@ -2307,14 +2732,17 @@ var isBrowser = typeof window !== "undefined";
|
|
|
2307
2732
|
findLast,
|
|
2308
2733
|
findLastIndex,
|
|
2309
2734
|
first,
|
|
2735
|
+
firstBy,
|
|
2310
2736
|
flatMap,
|
|
2311
2737
|
flatMapToObj,
|
|
2312
2738
|
flatten,
|
|
2313
2739
|
flattenDeep,
|
|
2740
|
+
floor,
|
|
2314
2741
|
forEach,
|
|
2315
2742
|
forEachObj,
|
|
2316
2743
|
fromPairs,
|
|
2317
2744
|
groupBy,
|
|
2745
|
+
hasAtLeast,
|
|
2318
2746
|
humanReadableFileSize,
|
|
2319
2747
|
identity,
|
|
2320
2748
|
indexBy,
|
|
@@ -2336,6 +2764,7 @@ var isBrowser = typeof window !== "undefined";
|
|
|
2336
2764
|
isObject,
|
|
2337
2765
|
isPromise,
|
|
2338
2766
|
isString,
|
|
2767
|
+
isSymbol,
|
|
2339
2768
|
isTruthy,
|
|
2340
2769
|
isUppercase,
|
|
2341
2770
|
join,
|
|
@@ -2352,10 +2781,13 @@ var isBrowser = typeof window !== "undefined";
|
|
|
2352
2781
|
mergeAll,
|
|
2353
2782
|
mergeDeep,
|
|
2354
2783
|
minBy,
|
|
2784
|
+
multiply,
|
|
2355
2785
|
noop,
|
|
2786
|
+
nthBy,
|
|
2356
2787
|
omit,
|
|
2357
2788
|
omitBy,
|
|
2358
2789
|
once,
|
|
2790
|
+
only,
|
|
2359
2791
|
partition,
|
|
2360
2792
|
pathOr,
|
|
2361
2793
|
pick,
|
|
@@ -2365,9 +2797,11 @@ var isBrowser = typeof window !== "undefined";
|
|
|
2365
2797
|
purry,
|
|
2366
2798
|
randomString,
|
|
2367
2799
|
range,
|
|
2800
|
+
rankBy,
|
|
2368
2801
|
reduce,
|
|
2369
2802
|
reject,
|
|
2370
2803
|
reverse,
|
|
2804
|
+
round,
|
|
2371
2805
|
sample,
|
|
2372
2806
|
set,
|
|
2373
2807
|
setPath,
|
|
@@ -2376,21 +2810,27 @@ var isBrowser = typeof window !== "undefined";
|
|
|
2376
2810
|
slugify,
|
|
2377
2811
|
sort,
|
|
2378
2812
|
sortBy,
|
|
2813
|
+
splice,
|
|
2379
2814
|
splitAt,
|
|
2380
2815
|
splitByCase,
|
|
2381
2816
|
splitWhen,
|
|
2382
2817
|
stringToPath,
|
|
2818
|
+
subtract,
|
|
2383
2819
|
sumBy,
|
|
2384
2820
|
swapIndices,
|
|
2385
2821
|
swapProps,
|
|
2386
2822
|
take,
|
|
2823
|
+
takeFirstBy,
|
|
2387
2824
|
takeWhile,
|
|
2825
|
+
titleCase,
|
|
2388
2826
|
toCamelCase,
|
|
2827
|
+
toFlatCase,
|
|
2389
2828
|
toKebabCase,
|
|
2390
2829
|
toLowerFirst,
|
|
2391
2830
|
toPairs,
|
|
2392
2831
|
toPascalCase,
|
|
2393
2832
|
toSnakeCase,
|
|
2833
|
+
toTrainCase,
|
|
2394
2834
|
toUpperFirst,
|
|
2395
2835
|
type,
|
|
2396
2836
|
uniq,
|