rambda 10.0.0-alpha.0 → 10.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +125 -16
- package/README.md +8035 -3592
- package/dist/{rambda.esm.js → rambda.cjs} +800 -385
- package/dist/rambda.js +673 -486
- package/dist/rambda.umd.js +701 -388
- package/immutable.d.ts +896 -345
- package/index.d.ts +896 -345
- package/package.json +22 -15
- package/rambda.js +23 -2
- package/src/addProp.js +3 -0
- package/src/addPropToObjects.js +14 -0
- package/src/append.js +5 -5
- package/src/ascend.js +16 -0
- package/src/compact.js +12 -0
- package/src/concat.js +1 -1
- package/src/count.js +7 -7
- package/src/countBy.js +12 -12
- package/src/createObjectFromKeys.js +10 -0
- package/src/defaultTo.js +2 -6
- package/src/descend.js +10 -0
- package/src/drop.js +2 -6
- package/src/dropLast.js +1 -3
- package/src/eqProps.js +1 -2
- package/src/equals.js +2 -2
- package/src/evolve.js +2 -23
- package/src/filter.js +14 -14
- package/src/find.js +10 -10
- package/src/findIndex.js +9 -9
- package/src/findLast.js +8 -8
- package/src/findLastIndex.js +8 -8
- package/src/findNth.js +16 -0
- package/src/flattenObject.js +76 -0
- package/src/groupBy.js +14 -13
- package/src/includes.js +12 -13
- package/src/interpolate.js +29 -0
- package/src/intersection.js +1 -1
- package/src/intersperse.js +12 -12
- package/src/join.js +1 -1
- package/src/map.js +13 -9
- package/src/mapAsync.js +3 -3
- package/src/mapKeys.js +11 -0
- package/src/mapObjectAsync.js +9 -9
- package/src/mapParallelAsync.js +3 -0
- package/src/match.js +5 -5
- package/src/{replaceItemAtIndex.js → modifyItemAtIndex.js} +1 -1
- package/src/modifyProp.js +20 -0
- package/src/objectIncludes.js +12 -0
- package/src/partition.js +13 -37
- package/src/partitionObject.js +15 -0
- package/src/path.js +24 -26
- package/src/pathSatisfies.js +5 -0
- package/src/permutations.js +40 -0
- package/src/pipeAsync.js +7 -6
- package/src/pluck.js +9 -9
- package/src/prepend.js +1 -1
- package/src/propOr.js +1 -1
- package/src/propSatisfies.js +1 -3
- package/src/range.js +29 -13
- package/src/reject.js +1 -1
- package/src/rejectObject.js +13 -0
- package/src/shuffle.js +13 -0
- package/src/sort.js +1 -1
- package/src/sortBy.js +20 -9
- package/src/sortByDescending.js +5 -0
- package/src/sortByPath.js +6 -0
- package/src/sortByPathDescending.js +6 -0
- package/src/sortObject.js +15 -0
- package/src/sortWith.js +8 -8
- package/src/split.js +2 -2
- package/src/splitEvery.js +11 -11
- package/src/takeLastWhile.js +18 -18
- package/src/tap.js +4 -4
- package/src/test.js +1 -1
- package/src/uniqBy.js +4 -4
- package/src/uniqWith.js +10 -10
- package/src/modifyPath.js +0 -30
package/dist/rambda.umd.js
CHANGED
|
@@ -4,6 +4,39 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.R = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
+
function addProp(key, value) {
|
|
8
|
+
return obj => ({ ...obj, [key]: value })
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function mapFn(
|
|
12
|
+
fn, list
|
|
13
|
+
){
|
|
14
|
+
let index = 0;
|
|
15
|
+
const willReturn = Array(list.length);
|
|
16
|
+
while (index < list.length) {
|
|
17
|
+
willReturn[index] = fn(list[index], index);
|
|
18
|
+
index++;
|
|
19
|
+
}
|
|
20
|
+
return willReturn
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function map(fn) {
|
|
24
|
+
return list => mapFn(fn, list)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function addPropToObjects (
|
|
28
|
+
property,
|
|
29
|
+
fn
|
|
30
|
+
){
|
|
31
|
+
return listOfObjects => mapFn(
|
|
32
|
+
(obj) => ({
|
|
33
|
+
...(obj),
|
|
34
|
+
[property]: fn(obj)
|
|
35
|
+
}),
|
|
36
|
+
listOfObjects
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
7
40
|
function all(predicate) {
|
|
8
41
|
return list => {
|
|
9
42
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -58,15 +91,32 @@
|
|
|
58
91
|
}
|
|
59
92
|
}
|
|
60
93
|
|
|
61
|
-
const cloneList = list => Array.prototype.slice.call(list);
|
|
94
|
+
const cloneList$1 = list => Array.prototype.slice.call(list);
|
|
62
95
|
|
|
63
96
|
function append(x) {
|
|
64
|
-
return list=> {
|
|
65
|
-
|
|
66
|
-
|
|
97
|
+
return list => {
|
|
98
|
+
const clone = cloneList$1(list);
|
|
99
|
+
clone.push(x);
|
|
67
100
|
|
|
68
|
-
|
|
69
|
-
|
|
101
|
+
return clone
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function createCompareFunction(a, b, winner, loser) {
|
|
106
|
+
if (a === b) {
|
|
107
|
+
return 0
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return a < b ? winner : loser
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function ascend(getFunction) {
|
|
114
|
+
return (a, b) => {
|
|
115
|
+
const aValue = getFunction(a);
|
|
116
|
+
const bValue = getFunction(b);
|
|
117
|
+
|
|
118
|
+
return createCompareFunction(aValue, bValue, -1, 1)
|
|
119
|
+
}
|
|
70
120
|
}
|
|
71
121
|
|
|
72
122
|
function checkObjectWithSpec(conditions) {
|
|
@@ -86,67 +136,125 @@
|
|
|
86
136
|
}
|
|
87
137
|
}
|
|
88
138
|
|
|
139
|
+
const { isArray } = Array;
|
|
140
|
+
|
|
141
|
+
function filter(predicate) {
|
|
142
|
+
return list => {
|
|
143
|
+
if (!list) {
|
|
144
|
+
throw new Error('Incorrect iterable input')
|
|
145
|
+
}
|
|
146
|
+
let index = 0;
|
|
147
|
+
const len = list.length;
|
|
148
|
+
const willReturn = [];
|
|
149
|
+
|
|
150
|
+
while (index < len) {
|
|
151
|
+
if (predicate(list[index], index)) {
|
|
152
|
+
willReturn.push(list[index]);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
index++;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return willReturn
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function reject(predicate) {
|
|
163
|
+
return list => filter(x => !predicate(x))(list)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function rejectObject(predicate) {
|
|
167
|
+
return obj => {
|
|
168
|
+
const willReturn = {};
|
|
169
|
+
|
|
170
|
+
for (const prop in obj) {
|
|
171
|
+
if (!predicate(obj[prop], prop, obj)) {
|
|
172
|
+
willReturn[prop] = obj[prop];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return willReturn
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const isNullOrUndefined = x => x === null || x === undefined;
|
|
181
|
+
|
|
182
|
+
function compact(input){
|
|
183
|
+
if(isArray(input)){
|
|
184
|
+
return reject(isNullOrUndefined)(input)
|
|
185
|
+
}
|
|
186
|
+
return rejectObject(isNullOrUndefined)(input)
|
|
187
|
+
}
|
|
188
|
+
|
|
89
189
|
function complement(fn) {
|
|
90
190
|
return (...input) => !fn(...input)
|
|
91
191
|
}
|
|
92
192
|
|
|
93
193
|
function concat(x) {
|
|
94
|
-
return y => typeof x === 'string' ? `${x}${y}` : [...x, ...y]
|
|
194
|
+
return y => (typeof x === 'string' ? `${x}${y}` : [...x, ...y])
|
|
95
195
|
}
|
|
96
196
|
|
|
97
|
-
|
|
197
|
+
function count(predicate) {
|
|
198
|
+
return list => {
|
|
199
|
+
if (!isArray(list)) {
|
|
200
|
+
return 0
|
|
201
|
+
}
|
|
98
202
|
|
|
99
|
-
|
|
100
|
-
return list => {
|
|
101
|
-
if (!isArray(list)) {
|
|
102
|
-
return 0
|
|
203
|
+
return list.filter(x => predicate(x)).length
|
|
103
204
|
}
|
|
104
|
-
|
|
105
|
-
return list.filter(x => predicate(x)).length
|
|
106
|
-
}
|
|
107
205
|
}
|
|
108
206
|
|
|
109
207
|
function countBy(fn) {
|
|
110
|
-
|
|
111
|
-
|
|
208
|
+
return list => {
|
|
209
|
+
const willReturn = {};
|
|
112
210
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
211
|
+
list.forEach(item => {
|
|
212
|
+
const key = fn(item);
|
|
213
|
+
if (!willReturn[key]) {
|
|
214
|
+
willReturn[key] = 1;
|
|
215
|
+
} else {
|
|
216
|
+
willReturn[key]++;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
121
219
|
|
|
122
|
-
|
|
220
|
+
return willReturn
|
|
221
|
+
}
|
|
123
222
|
}
|
|
223
|
+
|
|
224
|
+
function createObjectFromKeys(keys) {
|
|
225
|
+
return fn => {
|
|
226
|
+
const result = {};
|
|
227
|
+
keys.forEach((key, index) => {
|
|
228
|
+
result[key] = fn(key, index);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
return result
|
|
232
|
+
}
|
|
124
233
|
}
|
|
125
234
|
|
|
126
235
|
function isFalsy(input) {
|
|
127
236
|
return input === undefined || input === null || Number.isNaN(input) === true
|
|
128
237
|
}
|
|
129
238
|
|
|
130
|
-
function defaultTo(defaultArgument
|
|
131
|
-
|
|
132
|
-
return _input => defaultTo(defaultArgument, _input)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return isFalsy(input) ? defaultArgument : input
|
|
239
|
+
function defaultTo(defaultArgument) {
|
|
240
|
+
return input => isFalsy(input) ? defaultArgument : input
|
|
136
241
|
}
|
|
137
242
|
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
243
|
+
function descend(getFunction) {
|
|
244
|
+
return (a, b) => {
|
|
245
|
+
const aValue = getFunction(a);
|
|
246
|
+
const bValue = getFunction(b);
|
|
247
|
+
|
|
248
|
+
return createCompareFunction(aValue, bValue, 1, -1)
|
|
141
249
|
}
|
|
250
|
+
}
|
|
142
251
|
|
|
143
|
-
|
|
252
|
+
function drop(howManyToDrop, ) {
|
|
253
|
+
return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
|
|
144
254
|
}
|
|
145
255
|
|
|
146
256
|
function dropLast(numberItems) {
|
|
147
|
-
|
|
148
|
-
? list.slice(0, -numberItems)
|
|
149
|
-
: list.slice()
|
|
257
|
+
return list => (numberItems > 0 ? list.slice(0, -numberItems) : list.slice())
|
|
150
258
|
}
|
|
151
259
|
|
|
152
260
|
function dropLastWhile(predicate) {
|
|
@@ -306,7 +414,7 @@
|
|
|
306
414
|
}
|
|
307
415
|
|
|
308
416
|
function equalsFn(a, b) {
|
|
309
|
-
|
|
417
|
+
if (Object.is(a, b)) {
|
|
310
418
|
return true
|
|
311
419
|
}
|
|
312
420
|
|
|
@@ -415,19 +523,15 @@
|
|
|
415
523
|
return false
|
|
416
524
|
}
|
|
417
525
|
function equals(a) {
|
|
418
|
-
|
|
526
|
+
return b => equalsFn(a, b)
|
|
419
527
|
}
|
|
420
528
|
|
|
421
529
|
function eqBy(fn, a) {
|
|
422
530
|
return b => equalsFn(fn(a), fn(b))
|
|
423
531
|
}
|
|
424
532
|
|
|
425
|
-
function prop(searchProperty) {
|
|
426
|
-
return obj => (obj ? obj[searchProperty] : undefined)
|
|
427
|
-
}
|
|
428
|
-
|
|
429
533
|
function eqProps(property, objA) {
|
|
430
|
-
return objB => equalsFn(
|
|
534
|
+
return objB => equalsFn( objA[property], objB[property] )
|
|
431
535
|
}
|
|
432
536
|
|
|
433
537
|
const { keys } = Object;
|
|
@@ -449,73 +553,30 @@
|
|
|
449
553
|
}
|
|
450
554
|
}
|
|
451
555
|
|
|
452
|
-
function evolveFn(rules, obj) {
|
|
453
|
-
return mapObject((x, prop) => {
|
|
454
|
-
if (type(x) === 'Object') {
|
|
455
|
-
const typeRule = type(rules[prop]);
|
|
456
|
-
if (typeRule === 'Function') {
|
|
457
|
-
return rules[prop](x)
|
|
458
|
-
}
|
|
459
|
-
if (typeRule === 'Object') {
|
|
460
|
-
return evolveFn(rules[prop], x)
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
return x
|
|
464
|
-
}
|
|
465
|
-
if (type(rules[prop]) === 'Function') {
|
|
466
|
-
return rules[prop](x)
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return x
|
|
470
|
-
})(obj)
|
|
471
|
-
}
|
|
472
|
-
|
|
473
556
|
function evolve(rules) {
|
|
474
|
-
return
|
|
475
|
-
|
|
557
|
+
return mapObject((x, prop) => type(rules[prop]) === 'Function' ? rules[prop](x): x)
|
|
558
|
+
}
|
|
476
559
|
|
|
477
560
|
function includes(valueToFind) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
561
|
+
return iterable => {
|
|
562
|
+
if (typeof iterable === 'string') {
|
|
563
|
+
return iterable.includes(valueToFind)
|
|
564
|
+
}
|
|
565
|
+
if (!iterable) {
|
|
566
|
+
throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`)
|
|
567
|
+
}
|
|
568
|
+
if (!isArray(iterable)) {
|
|
569
|
+
return false
|
|
570
|
+
}
|
|
489
571
|
|
|
490
|
-
|
|
491
|
-
|
|
572
|
+
return _indexOf(valueToFind, iterable) > -1
|
|
573
|
+
}
|
|
492
574
|
}
|
|
493
575
|
|
|
494
576
|
function excludes(valueToFind) {
|
|
495
577
|
return iterable => !includes(valueToFind)(iterable)
|
|
496
578
|
}
|
|
497
579
|
|
|
498
|
-
function filter(predicate) {
|
|
499
|
-
return list => {
|
|
500
|
-
if (!list) {
|
|
501
|
-
throw new Error('Incorrect iterable input')
|
|
502
|
-
}
|
|
503
|
-
let index = 0;
|
|
504
|
-
const len = list.length;
|
|
505
|
-
const willReturn = [];
|
|
506
|
-
|
|
507
|
-
while (index < len) {
|
|
508
|
-
if (predicate(list[index], index)) {
|
|
509
|
-
willReturn.push(list[index]);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
index++;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
return willReturn
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
580
|
function filterObject(predicate) {
|
|
520
581
|
return obj => {
|
|
521
582
|
const willReturn = {};
|
|
@@ -531,62 +592,79 @@
|
|
|
531
592
|
}
|
|
532
593
|
|
|
533
594
|
function find(predicate) {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
595
|
+
return list => {
|
|
596
|
+
let index = 0;
|
|
597
|
+
const len = list.length;
|
|
537
598
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
599
|
+
while (index < len) {
|
|
600
|
+
const x = list[index];
|
|
601
|
+
if (predicate(x)) {
|
|
602
|
+
return x
|
|
603
|
+
}
|
|
543
604
|
|
|
544
|
-
|
|
605
|
+
index++;
|
|
606
|
+
}
|
|
545
607
|
}
|
|
546
608
|
}
|
|
547
|
-
}
|
|
548
609
|
|
|
549
610
|
function findIndex(predicate) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
611
|
+
return list => {
|
|
612
|
+
const len = list.length;
|
|
613
|
+
let index = -1;
|
|
553
614
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
615
|
+
while (++index < len) {
|
|
616
|
+
if (predicate(list[index])) {
|
|
617
|
+
return index
|
|
618
|
+
}
|
|
557
619
|
}
|
|
558
|
-
}
|
|
559
620
|
|
|
560
|
-
|
|
561
|
-
|
|
621
|
+
return -1
|
|
622
|
+
}
|
|
562
623
|
}
|
|
563
624
|
|
|
564
625
|
function findLast(predicate) {
|
|
565
|
-
|
|
566
|
-
|
|
626
|
+
return list => {
|
|
627
|
+
let index = list.length;
|
|
567
628
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
629
|
+
while (--index >= 0) {
|
|
630
|
+
if (predicate(list[index])) {
|
|
631
|
+
return list[index]
|
|
632
|
+
}
|
|
571
633
|
}
|
|
572
|
-
}
|
|
573
634
|
|
|
574
|
-
|
|
575
|
-
|
|
635
|
+
return undefined
|
|
636
|
+
}
|
|
576
637
|
}
|
|
577
638
|
|
|
578
639
|
function findLastIndex(fn) {
|
|
579
|
-
|
|
580
|
-
|
|
640
|
+
return list => {
|
|
641
|
+
let index = list.length;
|
|
581
642
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
643
|
+
while (--index >= 0) {
|
|
644
|
+
if (fn(list[index])) {
|
|
645
|
+
return index
|
|
646
|
+
}
|
|
585
647
|
}
|
|
586
|
-
}
|
|
587
648
|
|
|
588
|
-
|
|
649
|
+
return -1
|
|
650
|
+
}
|
|
589
651
|
}
|
|
652
|
+
|
|
653
|
+
function findNth(predicate, nth) {
|
|
654
|
+
return list => {
|
|
655
|
+
let index = 0;
|
|
656
|
+
const len = list.length;
|
|
657
|
+
|
|
658
|
+
while (index < len) {
|
|
659
|
+
const x = list[index];
|
|
660
|
+
if (predicate(x)) {
|
|
661
|
+
if (nth === 0) return x
|
|
662
|
+
nth--;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
index++;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
590
668
|
}
|
|
591
669
|
|
|
592
670
|
function flatMap(fn) {
|
|
@@ -607,24 +685,100 @@
|
|
|
607
685
|
return willReturn
|
|
608
686
|
}
|
|
609
687
|
|
|
610
|
-
function
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
688
|
+
function flattenObjectHelper(obj, accumulator = []){
|
|
689
|
+
const willReturn = {};
|
|
690
|
+
Object.keys(obj).forEach(key => {
|
|
691
|
+
const typeIs = type(obj[ key ]);
|
|
692
|
+
if (typeIs === 'Object'){
|
|
693
|
+
const [ flatResultValue, flatResultPath ] = flattenObjectHelper(obj[ key ],
|
|
694
|
+
[ ...accumulator, key ]);
|
|
695
|
+
willReturn[ flatResultPath.join('.') ] = flatResultValue;
|
|
614
696
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
697
|
+
return
|
|
698
|
+
} else if (accumulator.length > 0){
|
|
699
|
+
const finalKey = [ ...accumulator, key ].join('.');
|
|
700
|
+
willReturn[ finalKey ] = obj[ key ];
|
|
619
701
|
|
|
620
|
-
|
|
621
|
-
result[key] = [];
|
|
702
|
+
return
|
|
622
703
|
}
|
|
704
|
+
willReturn[ key ] = obj[ key ];
|
|
705
|
+
});
|
|
706
|
+
if (accumulator.length > 0) return [ willReturn, accumulator ]
|
|
623
707
|
|
|
624
|
-
|
|
625
|
-
|
|
708
|
+
return willReturn
|
|
709
|
+
}
|
|
626
710
|
|
|
627
|
-
|
|
711
|
+
function transformFlatObject(obj){
|
|
712
|
+
const willReturn = {};
|
|
713
|
+
|
|
714
|
+
const transformFlatObjectFn = objLocal => {
|
|
715
|
+
const willReturnLocal = {};
|
|
716
|
+
Object.keys(objLocal).forEach(key => {
|
|
717
|
+
const typeIs = type(objLocal[ key ]);
|
|
718
|
+
if (typeIs === 'Object'){
|
|
719
|
+
transformFlatObjectFn(objLocal[ key ]);
|
|
720
|
+
|
|
721
|
+
return
|
|
722
|
+
}
|
|
723
|
+
willReturnLocal[ key ] = objLocal[ key ];
|
|
724
|
+
willReturn[ key ] = objLocal[ key ];
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
return willReturnLocal
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
Object.keys(obj).forEach(key => {
|
|
731
|
+
const typeIs = type(obj[ key ]);
|
|
732
|
+
if (typeIs === 'Object'){
|
|
733
|
+
transformFlatObjectFn(obj[ key ]);
|
|
734
|
+
|
|
735
|
+
return
|
|
736
|
+
}
|
|
737
|
+
willReturn[ key ] = obj[ key ];
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
return willReturn
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function flattenObject(obj){
|
|
744
|
+
const willReturn = {};
|
|
745
|
+
|
|
746
|
+
Object.keys(obj).forEach(key => {
|
|
747
|
+
const typeIs = type(obj[ key ]);
|
|
748
|
+
if (typeIs === 'Object'){
|
|
749
|
+
const flatObject = flattenObjectHelper(obj[ key ]);
|
|
750
|
+
const transformed = transformFlatObject(flatObject);
|
|
751
|
+
|
|
752
|
+
Object.keys(transformed).forEach(keyTransformed => {
|
|
753
|
+
willReturn[ `${ key }.${ keyTransformed }` ] = transformed[ keyTransformed ];
|
|
754
|
+
});
|
|
755
|
+
} else {
|
|
756
|
+
willReturn[ key ] = obj[ key ];
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
return willReturn
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function groupByFallback(groupFn, list) {
|
|
764
|
+
const result = {};
|
|
765
|
+
for (let i = 0; i < list.length; i++) {
|
|
766
|
+
const item = list[i];
|
|
767
|
+
const key = groupFn(item);
|
|
768
|
+
|
|
769
|
+
if (!result[key]) {
|
|
770
|
+
result[key] = [];
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
result[key].push(item);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
return result
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
function groupBy(groupFn) {
|
|
781
|
+
return iterable => Object.groupBy ? Object.groupBy(iterable,groupFn) : groupByFallback(groupFn, iterable)
|
|
628
782
|
}
|
|
629
783
|
|
|
630
784
|
function head(listOrString) {
|
|
@@ -701,30 +855,60 @@
|
|
|
701
855
|
return ys => _filter(x => _includesWith(pred, x, ys), xs)
|
|
702
856
|
}
|
|
703
857
|
|
|
858
|
+
const getOccurrences = input => input.match(/{{\s*.+?\s*}}/g);
|
|
859
|
+
const getOccurrenceProp = occurrence => occurrence.replace(/{{\s*|\s*}}/g, '');
|
|
860
|
+
|
|
861
|
+
const replace$1 = ({ inputHolder, prop, replacer }) => {
|
|
862
|
+
const regexBase = `{{${prop}}}`;
|
|
863
|
+
const regex = new RegExp(regexBase, 'g');
|
|
864
|
+
return inputHolder.replace(regex, replacer)
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
function interpolate(input) {
|
|
868
|
+
return templateInput => {
|
|
869
|
+
const occurrences = getOccurrences(input);
|
|
870
|
+
if (occurrences === null) {
|
|
871
|
+
return input
|
|
872
|
+
}
|
|
873
|
+
let inputHolder = input;
|
|
874
|
+
|
|
875
|
+
for (const occurrence of occurrences) {
|
|
876
|
+
const prop = getOccurrenceProp(occurrence);
|
|
877
|
+
inputHolder = replace$1({
|
|
878
|
+
inputHolder,
|
|
879
|
+
prop,
|
|
880
|
+
replacer: templateInput[prop],
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
return inputHolder
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
704
888
|
function intersection(listA) {
|
|
705
|
-
return listB =>filter(x => includes(x)(listA))(listB)
|
|
889
|
+
return listB => filter(x => includes(x)(listA))(listB)
|
|
706
890
|
}
|
|
707
891
|
|
|
708
892
|
function intersperse(separator) {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
893
|
+
return list => {
|
|
894
|
+
let index = -1;
|
|
895
|
+
const len = list.length;
|
|
896
|
+
const willReturn = [];
|
|
713
897
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
898
|
+
while (++index < len) {
|
|
899
|
+
if (index === len - 1) {
|
|
900
|
+
willReturn.push(list[index]);
|
|
901
|
+
} else {
|
|
902
|
+
willReturn.push(list[index], separator);
|
|
903
|
+
}
|
|
719
904
|
}
|
|
720
|
-
}
|
|
721
905
|
|
|
722
|
-
|
|
723
|
-
|
|
906
|
+
return willReturn
|
|
907
|
+
}
|
|
724
908
|
}
|
|
725
909
|
|
|
726
910
|
function join(glue) {
|
|
727
|
-
return list=> list.join(glue)
|
|
911
|
+
return list => list.join(glue)
|
|
728
912
|
}
|
|
729
913
|
|
|
730
914
|
function last(listOrString) {
|
|
@@ -739,47 +923,51 @@
|
|
|
739
923
|
return list => _lastIndexOf(valueToFind, list)
|
|
740
924
|
}
|
|
741
925
|
|
|
742
|
-
function map(fn) {
|
|
743
|
-
return list => {
|
|
744
|
-
let index = 0;
|
|
745
|
-
const willReturn = Array(list.length);
|
|
746
|
-
while (index < list.length) {
|
|
747
|
-
willReturn[index] = fn(list[index], index);
|
|
748
|
-
index++;
|
|
749
|
-
}
|
|
750
|
-
return willReturn
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
926
|
function mapAsync(fn) {
|
|
755
|
-
|
|
756
|
-
|
|
927
|
+
return async list => {
|
|
928
|
+
const willReturn = [];
|
|
757
929
|
let i = 0;
|
|
758
930
|
for (const a of list) {
|
|
759
931
|
willReturn.push(await fn(a, i++));
|
|
760
932
|
}
|
|
761
933
|
|
|
762
934
|
return willReturn
|
|
763
|
-
|
|
935
|
+
}
|
|
764
936
|
}
|
|
765
937
|
|
|
766
|
-
function
|
|
767
|
-
|
|
938
|
+
function mapKeys(fn) {
|
|
939
|
+
return obj => {
|
|
768
940
|
const willReturn = {};
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
941
|
+
|
|
942
|
+
Object.keys(obj).forEach(key => {
|
|
943
|
+
willReturn[fn(key, obj[key])] = obj[key];
|
|
944
|
+
});
|
|
945
|
+
|
|
773
946
|
return willReturn
|
|
774
947
|
}
|
|
775
948
|
}
|
|
776
949
|
|
|
950
|
+
function mapObjectAsync(fn) {
|
|
951
|
+
return async obj => {
|
|
952
|
+
const willReturn = {};
|
|
953
|
+
for (const prop in obj) {
|
|
954
|
+
willReturn[prop] = await fn(obj[prop], prop);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
return willReturn
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function mapParallelAsync(fn) {
|
|
962
|
+
return async list => Promise.all(list.map((x, i) => fn(x, i)))
|
|
963
|
+
}
|
|
964
|
+
|
|
777
965
|
function match(pattern) {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
966
|
+
return input => {
|
|
967
|
+
const willReturn = input.match(pattern);
|
|
968
|
+
|
|
969
|
+
return willReturn === null ? [] : willReturn
|
|
970
|
+
}
|
|
783
971
|
}
|
|
784
972
|
|
|
785
973
|
function maxBy(compareFn, x) {
|
|
@@ -799,66 +987,47 @@
|
|
|
799
987
|
return y => (compareFn(y) < compareFn(x) ? y : x)
|
|
800
988
|
}
|
|
801
989
|
|
|
802
|
-
function
|
|
803
|
-
return
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
990
|
+
function modifyItemAtIndex(index, replaceFn) {
|
|
991
|
+
return list => {
|
|
992
|
+
const actualIndex = index < 0 ? list.length + index : index;
|
|
993
|
+
if (index >= list.length || actualIndex < 0) {
|
|
994
|
+
return list
|
|
995
|
+
}
|
|
807
996
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
return _obj => path(pathInput, _obj)
|
|
811
|
-
}
|
|
997
|
+
const clone = cloneList$1(list);
|
|
998
|
+
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
812
999
|
|
|
813
|
-
|
|
814
|
-
return undefined
|
|
1000
|
+
return clone
|
|
815
1001
|
}
|
|
816
|
-
|
|
817
|
-
let counter = 0;
|
|
818
|
-
|
|
819
|
-
const pathArrValue = createPath(pathInput);
|
|
1002
|
+
}
|
|
820
1003
|
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
return undefined
|
|
1004
|
+
function update(index, newValue) {
|
|
1005
|
+
return list => {
|
|
1006
|
+
const clone = cloneList$1(list);
|
|
1007
|
+
if (index === -1) {
|
|
1008
|
+
return clone.fill(newValue, index)
|
|
827
1009
|
}
|
|
828
1010
|
|
|
829
|
-
|
|
830
|
-
counter++;
|
|
1011
|
+
return clone.fill(newValue, index, index + 1)
|
|
831
1012
|
}
|
|
832
|
-
|
|
833
|
-
return willReturn
|
|
834
1013
|
}
|
|
835
1014
|
|
|
836
|
-
function
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
return {
|
|
844
|
-
...obj,
|
|
845
|
-
[path$1[0]]: fn(obj[path$1[0]]),
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
if (path(path$1)(obj) === undefined) {
|
|
849
|
-
return obj
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
const val = modifyPathFn(Array.prototype.slice.call(path$1, 1), fn, obj[path$1[0]]);
|
|
853
|
-
if (val === obj[path$1[0]]) {
|
|
854
|
-
return obj
|
|
855
|
-
}
|
|
1015
|
+
function modifyFn(property, fn, list) {
|
|
1016
|
+
if (list[property] === undefined) {
|
|
1017
|
+
return list
|
|
1018
|
+
}
|
|
1019
|
+
if (isArray(list)) {
|
|
1020
|
+
return update(property, fn(list[property]))(list)
|
|
1021
|
+
}
|
|
856
1022
|
|
|
857
|
-
|
|
1023
|
+
return {
|
|
1024
|
+
...list,
|
|
1025
|
+
[property]: fn(list[property]),
|
|
1026
|
+
}
|
|
858
1027
|
}
|
|
859
1028
|
|
|
860
|
-
function
|
|
861
|
-
return obj =>
|
|
1029
|
+
function modifyProp(property, fn) {
|
|
1030
|
+
return obj => modifyFn(property, fn, obj)
|
|
862
1031
|
}
|
|
863
1032
|
|
|
864
1033
|
function none(predicate) {
|
|
@@ -877,6 +1046,22 @@
|
|
|
877
1046
|
return value => ({ [key]: value })
|
|
878
1047
|
}
|
|
879
1048
|
|
|
1049
|
+
function objectIncludes(condition) {
|
|
1050
|
+
return obj => {
|
|
1051
|
+
const result = filterObject((conditionValue, conditionProp) =>
|
|
1052
|
+
equals(conditionValue)(obj[conditionProp]),
|
|
1053
|
+
)(condition);
|
|
1054
|
+
|
|
1055
|
+
return Object.keys(result).length === Object.keys(condition).length
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function createPath(path, delimiter = '.') {
|
|
1060
|
+
return typeof path === 'string'
|
|
1061
|
+
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1062
|
+
: path
|
|
1063
|
+
}
|
|
1064
|
+
|
|
880
1065
|
function _includes(x, list) {
|
|
881
1066
|
let index = -1;
|
|
882
1067
|
const { length } = list;
|
|
@@ -909,10 +1094,29 @@
|
|
|
909
1094
|
}
|
|
910
1095
|
}
|
|
911
1096
|
|
|
912
|
-
function
|
|
1097
|
+
function partition(predicate) {
|
|
1098
|
+
return list => {
|
|
1099
|
+
const yes = [];
|
|
1100
|
+
const no = [];
|
|
1101
|
+
let counter = -1;
|
|
1102
|
+
|
|
1103
|
+
while (counter++ < list.length - 1) {
|
|
1104
|
+
if (predicate(list[counter], counter)) {
|
|
1105
|
+
yes.push(list[counter]);
|
|
1106
|
+
} else {
|
|
1107
|
+
no.push(list[counter]);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
return [yes, no]
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
function partitionObject(predicate) {
|
|
1116
|
+
return obj => {
|
|
913
1117
|
const yes = {};
|
|
914
1118
|
const no = {};
|
|
915
|
-
Object.entries(
|
|
1119
|
+
Object.entries(obj).forEach(([prop, value]) => {
|
|
916
1120
|
if (predicate(value, prop)) {
|
|
917
1121
|
yes[prop] = value;
|
|
918
1122
|
} else {
|
|
@@ -922,31 +1126,75 @@
|
|
|
922
1126
|
|
|
923
1127
|
return [yes, no]
|
|
924
1128
|
}
|
|
1129
|
+
}
|
|
925
1130
|
|
|
926
|
-
function
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
1131
|
+
function path(pathInput) {
|
|
1132
|
+
return (obj) => {
|
|
1133
|
+
if (!obj) {
|
|
1134
|
+
return undefined
|
|
1135
|
+
}
|
|
1136
|
+
let willReturn = obj;
|
|
1137
|
+
let counter = 0;
|
|
1138
|
+
|
|
1139
|
+
const pathArrValue = createPath(pathInput);
|
|
1140
|
+
|
|
1141
|
+
while (counter < pathArrValue.length) {
|
|
1142
|
+
if (willReturn === null || willReturn === undefined) {
|
|
1143
|
+
return undefined
|
|
1144
|
+
}
|
|
1145
|
+
if (willReturn[pathArrValue[counter]] === null) {
|
|
1146
|
+
return undefined
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
willReturn = willReturn[pathArrValue[counter]];
|
|
1150
|
+
counter++;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
return willReturn
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
function pathSatisfies(fn, pathInput) {
|
|
1158
|
+
return obj => Boolean(fn(path(pathInput)(obj)))
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* Source:
|
|
1163
|
+
* https://github.com/denoland/std/blob/main/collections/permutations.ts
|
|
1164
|
+
*/
|
|
1165
|
+
function permutations(inputArray) {
|
|
1166
|
+
const result = [];
|
|
1167
|
+
const array = cloneList$1(inputArray);
|
|
1168
|
+
const k = array.length;
|
|
1169
|
+
if (k === 0) {
|
|
1170
|
+
return result;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
const c = new Array(k).fill(0);
|
|
1174
|
+
|
|
1175
|
+
result.push([...array]);
|
|
1176
|
+
|
|
1177
|
+
let i = 1;
|
|
1178
|
+
|
|
1179
|
+
while (i < k) {
|
|
1180
|
+
if (c[i] < i) {
|
|
1181
|
+
if (i % 2 === 0) {
|
|
1182
|
+
[array[0], array[i]] = [array[i], array[0]];
|
|
1183
|
+
} else {
|
|
1184
|
+
[array[c[i]], array[i]] = [array[i], array[c[i]]];
|
|
1185
|
+
}
|
|
930
1186
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
1187
|
+
result.push([...array]);
|
|
1188
|
+
|
|
1189
|
+
c[i] += 1;
|
|
1190
|
+
i = 1;
|
|
934
1191
|
} else {
|
|
935
|
-
|
|
1192
|
+
c[i] = 0;
|
|
1193
|
+
i += 1;
|
|
936
1194
|
}
|
|
937
1195
|
}
|
|
938
1196
|
|
|
939
|
-
return
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
function partition(predicate) {
|
|
943
|
-
return iterable => {
|
|
944
|
-
if (!isArray(iterable)) {
|
|
945
|
-
return partitionObject(predicate, iterable)
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
return partitionArray(predicate, iterable)
|
|
949
|
-
}
|
|
1197
|
+
return result;
|
|
950
1198
|
}
|
|
951
1199
|
|
|
952
1200
|
function pick(propsToPick) {
|
|
@@ -1069,30 +1317,35 @@
|
|
|
1069
1317
|
}
|
|
1070
1318
|
|
|
1071
1319
|
async function pipeAsync(input, ...fnList) {
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1320
|
+
let willReturn = input;
|
|
1321
|
+
for (const fn of fnList) {
|
|
1322
|
+
const initialResult = fn(willReturn);
|
|
1323
|
+
willReturn =
|
|
1324
|
+
type(initialResult) === 'Promise' ? await initialResult : initialResult;
|
|
1325
|
+
}
|
|
1326
|
+
return willReturn
|
|
1078
1327
|
}
|
|
1079
1328
|
|
|
1080
1329
|
function pluck(property) {
|
|
1081
|
-
|
|
1082
|
-
|
|
1330
|
+
return list => {
|
|
1331
|
+
const willReturn = [];
|
|
1083
1332
|
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1333
|
+
list.forEach(x => {
|
|
1334
|
+
if (x[property] !== undefined) {
|
|
1335
|
+
willReturn.push(x[property]);
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1089
1338
|
|
|
1090
|
-
|
|
1091
|
-
|
|
1339
|
+
return willReturn
|
|
1340
|
+
}
|
|
1092
1341
|
}
|
|
1093
1342
|
|
|
1094
1343
|
function prepend(x) {
|
|
1095
|
-
return list=> [x].concat(list)
|
|
1344
|
+
return list => [x].concat(list)
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
function prop(searchProperty) {
|
|
1348
|
+
return obj => (obj ? obj[searchProperty] : undefined)
|
|
1096
1349
|
}
|
|
1097
1350
|
|
|
1098
1351
|
function propEq(valueToMatch, propToFind) {
|
|
@@ -1111,72 +1364,119 @@
|
|
|
1111
1364
|
return defaultValue
|
|
1112
1365
|
}
|
|
1113
1366
|
|
|
1114
|
-
return defaultTo(defaultValue
|
|
1367
|
+
return defaultTo(defaultValue)(obj[property])
|
|
1115
1368
|
}
|
|
1116
1369
|
}
|
|
1117
1370
|
|
|
1118
1371
|
function propSatisfies(predicate, property) {
|
|
1119
|
-
return obj => predicate(
|
|
1372
|
+
return obj => predicate(obj[property])
|
|
1120
1373
|
}
|
|
1121
1374
|
|
|
1122
|
-
function
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1375
|
+
function rangeDescending(start, end) {
|
|
1376
|
+
const len = start - end;
|
|
1377
|
+
const willReturn = Array(len);
|
|
1378
|
+
|
|
1379
|
+
for (let i = 0; i < len; i++) {
|
|
1380
|
+
willReturn[i] = start - i;
|
|
1381
|
+
}
|
|
1127
1382
|
|
|
1128
|
-
|
|
1383
|
+
return willReturn
|
|
1384
|
+
}
|
|
1129
1385
|
|
|
1130
|
-
|
|
1131
|
-
|
|
1386
|
+
function range(start) {
|
|
1387
|
+
return end => {
|
|
1388
|
+
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
1389
|
+
throw new TypeError('Both arguments to range must be numbers')
|
|
1390
|
+
}
|
|
1132
1391
|
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1392
|
+
if (end === start) {
|
|
1393
|
+
return []
|
|
1394
|
+
}
|
|
1395
|
+
if (end < start) return rangeDescending(start,end)
|
|
1136
1396
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
}
|
|
1397
|
+
const len = end - start;
|
|
1398
|
+
const willReturn = Array(len);
|
|
1140
1399
|
|
|
1141
|
-
|
|
1142
|
-
|
|
1400
|
+
for (let i = 0; i < len; i++) {
|
|
1401
|
+
willReturn[i] = start + i;
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
return willReturn
|
|
1405
|
+
}
|
|
1143
1406
|
}
|
|
1144
1407
|
|
|
1145
1408
|
function replace(pattern, replacer) {
|
|
1146
1409
|
return str => str.replace(pattern, replacer)
|
|
1147
1410
|
}
|
|
1148
1411
|
|
|
1149
|
-
function
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1412
|
+
function shuffle(listInput) {
|
|
1413
|
+
const list = cloneList(listInput);
|
|
1414
|
+
let counter = list.length;
|
|
1415
|
+
while (counter > 0) {
|
|
1416
|
+
const index = Math.floor(Math.random() * counter);
|
|
1417
|
+
counter--;
|
|
1418
|
+
const temp = list[counter];
|
|
1419
|
+
list[counter] = list[index];
|
|
1420
|
+
list[index] = temp;
|
|
1421
|
+
}
|
|
1155
1422
|
|
|
1156
|
-
|
|
1157
|
-
|
|
1423
|
+
return list
|
|
1424
|
+
}
|
|
1158
1425
|
|
|
1159
|
-
|
|
1160
|
-
|
|
1426
|
+
function sort(sortFn) {
|
|
1427
|
+
return list => cloneList$1(list).sort(sortFn)
|
|
1161
1428
|
}
|
|
1162
1429
|
|
|
1163
|
-
function
|
|
1164
|
-
|
|
1430
|
+
function sortByFn (
|
|
1431
|
+
sortFn,
|
|
1432
|
+
list,
|
|
1433
|
+
descending
|
|
1434
|
+
){
|
|
1435
|
+
const clone = cloneList$1(list);
|
|
1436
|
+
|
|
1437
|
+
return clone.sort((a, b) => {
|
|
1438
|
+
const aSortResult = sortFn(a);
|
|
1439
|
+
const bSortResult = sortFn(b);
|
|
1440
|
+
|
|
1441
|
+
if (aSortResult === bSortResult) {
|
|
1442
|
+
return 0
|
|
1443
|
+
}
|
|
1444
|
+
if(
|
|
1445
|
+
descending
|
|
1446
|
+
) return aSortResult > bSortResult ? -1 : 1
|
|
1447
|
+
|
|
1448
|
+
return aSortResult < bSortResult ? -1 : 1
|
|
1449
|
+
})
|
|
1165
1450
|
}
|
|
1166
1451
|
|
|
1167
|
-
function sortBy(sortFn){
|
|
1168
|
-
|
|
1169
|
-
|
|
1452
|
+
function sortBy(sortFn) {
|
|
1453
|
+
return list => sortByFn(sortFn, list, false)
|
|
1454
|
+
}
|
|
1170
1455
|
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1456
|
+
function sortByDescending(sortFn) {
|
|
1457
|
+
return list => sortByFn(sortFn, list, true)
|
|
1458
|
+
}
|
|
1174
1459
|
|
|
1175
|
-
|
|
1460
|
+
function sortByPath(sortPath) {
|
|
1461
|
+
return list => sortBy(path(sortPath))(list)
|
|
1462
|
+
}
|
|
1176
1463
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1464
|
+
function sortByPathDescending(sortPath) {
|
|
1465
|
+
return list => sortByDescending(path(sortPath))(list)
|
|
1179
1466
|
}
|
|
1467
|
+
|
|
1468
|
+
function sortObject(predicate) {
|
|
1469
|
+
return obj => {
|
|
1470
|
+
const keys = Object.keys(obj);
|
|
1471
|
+
const sortedKeys = sort((a, b) => predicate(a, b, obj[a], obj[b]))(keys);
|
|
1472
|
+
|
|
1473
|
+
const toReturn = {};
|
|
1474
|
+
sortedKeys.forEach(singleKey => {
|
|
1475
|
+
toReturn[singleKey] = obj[singleKey];
|
|
1476
|
+
});
|
|
1477
|
+
|
|
1478
|
+
return toReturn
|
|
1479
|
+
}
|
|
1180
1480
|
}
|
|
1181
1481
|
|
|
1182
1482
|
function sortHelper(a, b, listOfSortingFns) {
|
|
@@ -1191,37 +1491,37 @@
|
|
|
1191
1491
|
}
|
|
1192
1492
|
|
|
1193
1493
|
function sortWith(listOfSortingFns) {
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1494
|
+
return list => {
|
|
1495
|
+
if (Array.isArray(list) === false) {
|
|
1496
|
+
return []
|
|
1497
|
+
}
|
|
1198
1498
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1499
|
+
const clone = list.slice();
|
|
1500
|
+
clone.sort((a, b) => sortHelper(a, b, listOfSortingFns));
|
|
1201
1501
|
|
|
1202
|
-
|
|
1203
|
-
|
|
1502
|
+
return clone
|
|
1503
|
+
}
|
|
1204
1504
|
}
|
|
1205
1505
|
|
|
1206
|
-
function split(separator){
|
|
1207
|
-
|
|
1506
|
+
function split(separator) {
|
|
1507
|
+
return str => str.split(separator)
|
|
1208
1508
|
}
|
|
1209
1509
|
|
|
1210
1510
|
function splitEvery(sliceLength) {
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1511
|
+
return list => {
|
|
1512
|
+
if (sliceLength < 1) {
|
|
1513
|
+
throw new Error('First argument to splitEvery must be a positive integer')
|
|
1514
|
+
}
|
|
1215
1515
|
|
|
1216
|
-
|
|
1217
|
-
|
|
1516
|
+
const willReturn = [];
|
|
1517
|
+
let counter = 0;
|
|
1218
1518
|
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1519
|
+
while (counter < list.length) {
|
|
1520
|
+
willReturn.push(list.slice(counter, (counter += sliceLength)));
|
|
1521
|
+
}
|
|
1222
1522
|
|
|
1223
|
-
|
|
1224
|
-
|
|
1523
|
+
return willReturn
|
|
1524
|
+
}
|
|
1225
1525
|
}
|
|
1226
1526
|
|
|
1227
1527
|
function symmetricDifference(x) {
|
|
@@ -1267,24 +1567,24 @@
|
|
|
1267
1567
|
}
|
|
1268
1568
|
|
|
1269
1569
|
function takeLastWhile(predicate) {
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1570
|
+
return input => {
|
|
1571
|
+
if (input.length === 0) {
|
|
1572
|
+
return input
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
const toReturn = [];
|
|
1576
|
+
let counter = input.length;
|
|
1577
|
+
|
|
1578
|
+
while (counter) {
|
|
1579
|
+
const item = input[--counter];
|
|
1580
|
+
if (!predicate(item)) {
|
|
1581
|
+
break
|
|
1582
|
+
}
|
|
1583
|
+
toReturn.push(item);
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
return toReturn.reverse()
|
|
1587
|
+
}
|
|
1288
1588
|
}
|
|
1289
1589
|
|
|
1290
1590
|
function takeWhile(predicate) {
|
|
@@ -1304,15 +1604,15 @@
|
|
|
1304
1604
|
}
|
|
1305
1605
|
|
|
1306
1606
|
function tap(fn) {
|
|
1307
|
-
|
|
1308
|
-
|
|
1607
|
+
return x => {
|
|
1608
|
+
fn(x);
|
|
1309
1609
|
|
|
1310
|
-
|
|
1311
|
-
|
|
1610
|
+
return x
|
|
1611
|
+
}
|
|
1312
1612
|
}
|
|
1313
1613
|
|
|
1314
1614
|
function test(pattern) {
|
|
1315
|
-
|
|
1615
|
+
return str => str.search(pattern) !== -1
|
|
1316
1616
|
}
|
|
1317
1617
|
|
|
1318
1618
|
function tryCatch(fn, fallback) {
|
|
@@ -1327,7 +1627,7 @@
|
|
|
1327
1627
|
|
|
1328
1628
|
function union(x) {
|
|
1329
1629
|
return y => {
|
|
1330
|
-
const toReturn = cloneList(x);
|
|
1630
|
+
const toReturn = cloneList$1(x);
|
|
1331
1631
|
|
|
1332
1632
|
y.forEach(yInstance => {
|
|
1333
1633
|
if (!includes(yInstance)(x)) {
|
|
@@ -1391,11 +1691,11 @@
|
|
|
1391
1691
|
}
|
|
1392
1692
|
|
|
1393
1693
|
function uniqBy(fn) {
|
|
1394
|
-
|
|
1395
|
-
|
|
1694
|
+
return list => {
|
|
1695
|
+
const set = new _Set();
|
|
1396
1696
|
|
|
1397
|
-
|
|
1398
|
-
|
|
1697
|
+
return list.filter(item => set.checkUniqueness(fn(item)))
|
|
1698
|
+
}
|
|
1399
1699
|
}
|
|
1400
1700
|
|
|
1401
1701
|
function includesWith(predicate, target, list) {
|
|
@@ -1414,20 +1714,20 @@
|
|
|
1414
1714
|
}
|
|
1415
1715
|
|
|
1416
1716
|
function uniqWith(predicate) {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1717
|
+
return list => {
|
|
1718
|
+
let index = -1;
|
|
1719
|
+
const willReturn = [];
|
|
1420
1720
|
|
|
1421
|
-
|
|
1422
|
-
|
|
1721
|
+
while (++index < list.length) {
|
|
1722
|
+
const value = list[index];
|
|
1423
1723
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1724
|
+
if (!includesWith(predicate, value, willReturn)) {
|
|
1725
|
+
willReturn.push(value);
|
|
1726
|
+
}
|
|
1426
1727
|
}
|
|
1427
|
-
}
|
|
1428
1728
|
|
|
1429
|
-
|
|
1430
|
-
|
|
1729
|
+
return willReturn
|
|
1730
|
+
}
|
|
1431
1731
|
}
|
|
1432
1732
|
|
|
1433
1733
|
function unless(predicate, whenFalseFn) {
|
|
@@ -1449,17 +1749,6 @@
|
|
|
1449
1749
|
}
|
|
1450
1750
|
}
|
|
1451
1751
|
|
|
1452
|
-
function update(index, newValue) {
|
|
1453
|
-
return list => {
|
|
1454
|
-
const clone = cloneList(list);
|
|
1455
|
-
if (index === -1) {
|
|
1456
|
-
return clone.fill(newValue, index)
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
return clone.fill(newValue, index, index + 1)
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
1752
|
function when(predicate, whenTrueFn) {
|
|
1464
1753
|
return input => {
|
|
1465
1754
|
if (!predicate(input)) {
|
|
@@ -1494,17 +1783,24 @@
|
|
|
1494
1783
|
exports._includes = _includes;
|
|
1495
1784
|
exports._indexOf = _indexOf;
|
|
1496
1785
|
exports._lastIndexOf = _lastIndexOf;
|
|
1786
|
+
exports.addProp = addProp;
|
|
1787
|
+
exports.addPropToObjects = addPropToObjects;
|
|
1497
1788
|
exports.all = all;
|
|
1498
1789
|
exports.allPass = allPass;
|
|
1499
1790
|
exports.any = any;
|
|
1500
1791
|
exports.anyPass = anyPass;
|
|
1501
1792
|
exports.append = append;
|
|
1793
|
+
exports.ascend = ascend;
|
|
1502
1794
|
exports.checkObjectWithSpec = checkObjectWithSpec;
|
|
1795
|
+
exports.compact = compact;
|
|
1503
1796
|
exports.complement = complement;
|
|
1504
1797
|
exports.concat = concat;
|
|
1505
1798
|
exports.count = count;
|
|
1506
1799
|
exports.countBy = countBy;
|
|
1800
|
+
exports.createCompareFunction = createCompareFunction;
|
|
1801
|
+
exports.createObjectFromKeys = createObjectFromKeys;
|
|
1507
1802
|
exports.defaultTo = defaultTo;
|
|
1803
|
+
exports.descend = descend;
|
|
1508
1804
|
exports.drop = drop;
|
|
1509
1805
|
exports.dropLast = dropLast;
|
|
1510
1806
|
exports.dropLastWhile = dropLastWhile;
|
|
@@ -1514,7 +1810,6 @@
|
|
|
1514
1810
|
exports.equals = equals;
|
|
1515
1811
|
exports.equalsFn = equalsFn;
|
|
1516
1812
|
exports.evolve = evolve;
|
|
1517
|
-
exports.evolveFn = evolveFn;
|
|
1518
1813
|
exports.excludes = excludes;
|
|
1519
1814
|
exports.filter = filter;
|
|
1520
1815
|
exports.filterObject = filterObject;
|
|
@@ -1522,14 +1817,19 @@
|
|
|
1522
1817
|
exports.findIndex = findIndex;
|
|
1523
1818
|
exports.findLast = findLast;
|
|
1524
1819
|
exports.findLastIndex = findLastIndex;
|
|
1820
|
+
exports.findNth = findNth;
|
|
1525
1821
|
exports.flatMap = flatMap;
|
|
1526
1822
|
exports.flatten = flatten;
|
|
1823
|
+
exports.flattenObject = flattenObject;
|
|
1824
|
+
exports.flattenObjectHelper = flattenObjectHelper;
|
|
1527
1825
|
exports.groupBy = groupBy;
|
|
1826
|
+
exports.groupByFallback = groupByFallback;
|
|
1528
1827
|
exports.head = head;
|
|
1529
1828
|
exports.includes = includes;
|
|
1530
1829
|
exports.indexOf = indexOf;
|
|
1531
1830
|
exports.init = init;
|
|
1532
1831
|
exports.innerJoin = innerJoin;
|
|
1832
|
+
exports.interpolate = interpolate;
|
|
1533
1833
|
exports.intersection = intersection;
|
|
1534
1834
|
exports.intersperse = intersperse;
|
|
1535
1835
|
exports.join = join;
|
|
@@ -1537,21 +1837,27 @@
|
|
|
1537
1837
|
exports.lastIndexOf = lastIndexOf;
|
|
1538
1838
|
exports.map = map;
|
|
1539
1839
|
exports.mapAsync = mapAsync;
|
|
1840
|
+
exports.mapFn = mapFn;
|
|
1841
|
+
exports.mapKeys = mapKeys;
|
|
1540
1842
|
exports.mapObject = mapObject;
|
|
1541
1843
|
exports.mapObjectAsync = mapObjectAsync;
|
|
1844
|
+
exports.mapParallelAsync = mapParallelAsync;
|
|
1542
1845
|
exports.match = match;
|
|
1543
1846
|
exports.maxBy = maxBy;
|
|
1544
1847
|
exports.merge = merge;
|
|
1545
1848
|
exports.mergeTypes = mergeTypes;
|
|
1546
1849
|
exports.minBy = minBy;
|
|
1547
|
-
exports.
|
|
1850
|
+
exports.modifyItemAtIndex = modifyItemAtIndex;
|
|
1851
|
+
exports.modifyProp = modifyProp;
|
|
1548
1852
|
exports.none = none;
|
|
1549
1853
|
exports.objOf = objOf;
|
|
1854
|
+
exports.objectIncludes = objectIncludes;
|
|
1550
1855
|
exports.omit = omit;
|
|
1551
1856
|
exports.partition = partition;
|
|
1552
|
-
exports.partitionArray = partitionArray;
|
|
1553
1857
|
exports.partitionObject = partitionObject;
|
|
1554
1858
|
exports.path = path;
|
|
1859
|
+
exports.pathSatisfies = pathSatisfies;
|
|
1860
|
+
exports.permutations = permutations;
|
|
1555
1861
|
exports.pick = pick;
|
|
1556
1862
|
exports.pipe = pipe;
|
|
1557
1863
|
exports.pipeAsync = pipeAsync;
|
|
@@ -1564,10 +1870,16 @@
|
|
|
1564
1870
|
exports.range = range;
|
|
1565
1871
|
exports.reduce = reduce;
|
|
1566
1872
|
exports.reject = reject;
|
|
1873
|
+
exports.rejectObject = rejectObject;
|
|
1567
1874
|
exports.replace = replace;
|
|
1568
|
-
exports.
|
|
1875
|
+
exports.shuffle = shuffle;
|
|
1569
1876
|
exports.sort = sort;
|
|
1570
1877
|
exports.sortBy = sortBy;
|
|
1878
|
+
exports.sortByDescending = sortByDescending;
|
|
1879
|
+
exports.sortByFn = sortByFn;
|
|
1880
|
+
exports.sortByPath = sortByPath;
|
|
1881
|
+
exports.sortByPathDescending = sortByPathDescending;
|
|
1882
|
+
exports.sortObject = sortObject;
|
|
1571
1883
|
exports.sortWith = sortWith;
|
|
1572
1884
|
exports.split = split;
|
|
1573
1885
|
exports.splitEvery = splitEvery;
|
|
@@ -1579,6 +1891,7 @@
|
|
|
1579
1891
|
exports.takeWhile = takeWhile;
|
|
1580
1892
|
exports.tap = tap;
|
|
1581
1893
|
exports.test = test;
|
|
1894
|
+
exports.transformFlatObject = transformFlatObject;
|
|
1582
1895
|
exports.tryCatch = tryCatch;
|
|
1583
1896
|
exports.type = type;
|
|
1584
1897
|
exports.union = union;
|