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