rambda 10.0.0-beta.1 → 10.0.0
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 +11 -8
- package/README.md +947 -306
- package/dist/rambda.cjs +212 -105
- package/dist/rambda.js +202 -104
- package/dist/rambda.umd.js +212 -105
- package/index.d.ts +587 -16
- package/package.json +9 -12
- package/rambda.js +7 -1
- package/src/addPropToObjects.js +14 -0
- package/src/defaultTo.js +2 -6
- package/src/drop.js +2 -6
- package/src/flattenObject.js +76 -0
- package/src/map.js +13 -9
- package/src/{replaceItemAtIndex.js → modifyItemAtIndex.js} +1 -1
- package/src/path.js +24 -26
- package/src/pathSatisfies.js +5 -0
- package/src/propOr.js +1 -1
- package/src/range.js +14 -21
- package/src/shuffle.js +2 -0
- package/src/sortBy.js +21 -12
- package/src/sortByDescending.js +5 -0
- package/src/sortByPath.js +6 -0
- package/src/sortByPathDescending.js +6 -0
- package/immutable.d.ts +0 -1617
- package/immutable.js +0 -1
package/dist/rambda.umd.js
CHANGED
|
@@ -8,6 +8,35 @@
|
|
|
8
8
|
return obj => ({ ...obj, [key]: value })
|
|
9
9
|
}
|
|
10
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
|
+
|
|
11
40
|
function all(predicate) {
|
|
12
41
|
return list => {
|
|
13
42
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -62,11 +91,11 @@
|
|
|
62
91
|
}
|
|
63
92
|
}
|
|
64
93
|
|
|
65
|
-
const cloneList
|
|
94
|
+
const cloneList = list => Array.prototype.slice.call(list);
|
|
66
95
|
|
|
67
96
|
function append(x) {
|
|
68
97
|
return list => {
|
|
69
|
-
const clone = cloneList
|
|
98
|
+
const clone = cloneList(list);
|
|
70
99
|
clone.push(x);
|
|
71
100
|
|
|
72
101
|
return clone
|
|
@@ -207,12 +236,8 @@
|
|
|
207
236
|
return input === undefined || input === null || Number.isNaN(input) === true
|
|
208
237
|
}
|
|
209
238
|
|
|
210
|
-
function defaultTo(defaultArgument
|
|
211
|
-
|
|
212
|
-
return _input => defaultTo(defaultArgument, _input)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return isFalsy(input) ? defaultArgument : input
|
|
239
|
+
function defaultTo(defaultArgument) {
|
|
240
|
+
return input => isFalsy(input) ? defaultArgument : input
|
|
216
241
|
}
|
|
217
242
|
|
|
218
243
|
function descend(getFunction) {
|
|
@@ -224,12 +249,8 @@
|
|
|
224
249
|
}
|
|
225
250
|
}
|
|
226
251
|
|
|
227
|
-
function drop(howManyToDrop,
|
|
228
|
-
|
|
229
|
-
return _list => drop(howManyToDrop, _list)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0)
|
|
252
|
+
function drop(howManyToDrop, ) {
|
|
253
|
+
return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
|
|
233
254
|
}
|
|
234
255
|
|
|
235
256
|
function dropLast(numberItems) {
|
|
@@ -664,6 +685,81 @@
|
|
|
664
685
|
return willReturn
|
|
665
686
|
}
|
|
666
687
|
|
|
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;
|
|
696
|
+
|
|
697
|
+
return
|
|
698
|
+
} else if (accumulator.length > 0){
|
|
699
|
+
const finalKey = [ ...accumulator, key ].join('.');
|
|
700
|
+
willReturn[ finalKey ] = obj[ key ];
|
|
701
|
+
|
|
702
|
+
return
|
|
703
|
+
}
|
|
704
|
+
willReturn[ key ] = obj[ key ];
|
|
705
|
+
});
|
|
706
|
+
if (accumulator.length > 0) return [ willReturn, accumulator ]
|
|
707
|
+
|
|
708
|
+
return willReturn
|
|
709
|
+
}
|
|
710
|
+
|
|
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
|
+
|
|
667
763
|
function groupByFallback(groupFn, list) {
|
|
668
764
|
const result = {};
|
|
669
765
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -827,18 +923,6 @@
|
|
|
827
923
|
return list => _lastIndexOf(valueToFind, list)
|
|
828
924
|
}
|
|
829
925
|
|
|
830
|
-
function map(fn) {
|
|
831
|
-
return list => {
|
|
832
|
-
let index = 0;
|
|
833
|
-
const willReturn = Array(list.length);
|
|
834
|
-
while (index < list.length) {
|
|
835
|
-
willReturn[index] = fn(list[index], index);
|
|
836
|
-
index++;
|
|
837
|
-
}
|
|
838
|
-
return willReturn
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
926
|
function mapAsync(fn) {
|
|
843
927
|
return async list => {
|
|
844
928
|
const willReturn = [];
|
|
@@ -903,9 +987,23 @@
|
|
|
903
987
|
return y => (compareFn(y) < compareFn(x) ? y : x)
|
|
904
988
|
}
|
|
905
989
|
|
|
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
|
+
}
|
|
996
|
+
|
|
997
|
+
const clone = cloneList(list);
|
|
998
|
+
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
999
|
+
|
|
1000
|
+
return clone
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
906
1004
|
function update(index, newValue) {
|
|
907
1005
|
return list => {
|
|
908
|
-
const clone = cloneList
|
|
1006
|
+
const clone = cloneList(list);
|
|
909
1007
|
if (index === -1) {
|
|
910
1008
|
return clone.fill(newValue, index)
|
|
911
1009
|
}
|
|
@@ -1030,32 +1128,34 @@
|
|
|
1030
1128
|
}
|
|
1031
1129
|
}
|
|
1032
1130
|
|
|
1033
|
-
function path(pathInput
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
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
|
+
}
|
|
1057
1156
|
|
|
1058
|
-
|
|
1157
|
+
function pathSatisfies(fn, pathInput) {
|
|
1158
|
+
return obj => Boolean(fn(path(pathInput)(obj)))
|
|
1059
1159
|
}
|
|
1060
1160
|
|
|
1061
1161
|
/**
|
|
@@ -1064,7 +1164,7 @@
|
|
|
1064
1164
|
*/
|
|
1065
1165
|
function permutations(inputArray) {
|
|
1066
1166
|
const result = [];
|
|
1067
|
-
const array = cloneList
|
|
1167
|
+
const array = cloneList(inputArray);
|
|
1068
1168
|
const k = array.length;
|
|
1069
1169
|
if (k === 0) {
|
|
1070
1170
|
return result;
|
|
@@ -1264,7 +1364,7 @@
|
|
|
1264
1364
|
return defaultValue
|
|
1265
1365
|
}
|
|
1266
1366
|
|
|
1267
|
-
return defaultTo(defaultValue
|
|
1367
|
+
return defaultTo(defaultValue)(obj[property])
|
|
1268
1368
|
}
|
|
1269
1369
|
}
|
|
1270
1370
|
|
|
@@ -1272,42 +1372,33 @@
|
|
|
1272
1372
|
return obj => predicate(obj[property])
|
|
1273
1373
|
}
|
|
1274
1374
|
|
|
1275
|
-
function
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
throw new TypeError('Both arguments to range must be numbers')
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
|
-
if (end <= start) {
|
|
1282
|
-
return []
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
const len = end - start;
|
|
1286
|
-
const willReturn = Array(len);
|
|
1375
|
+
function rangeDescending(start, end) {
|
|
1376
|
+
const len = start - end;
|
|
1377
|
+
const willReturn = Array(len);
|
|
1287
1378
|
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1379
|
+
for (let i = 0; i < len; i++) {
|
|
1380
|
+
willReturn[i] = start - i;
|
|
1381
|
+
}
|
|
1291
1382
|
|
|
1292
|
-
|
|
1293
|
-
}
|
|
1383
|
+
return willReturn
|
|
1294
1384
|
}
|
|
1295
1385
|
|
|
1296
|
-
function
|
|
1386
|
+
function range(start) {
|
|
1297
1387
|
return end => {
|
|
1298
1388
|
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
1299
1389
|
throw new TypeError('Both arguments to range must be numbers')
|
|
1300
1390
|
}
|
|
1301
1391
|
|
|
1302
|
-
if (end
|
|
1392
|
+
if (end === start) {
|
|
1303
1393
|
return []
|
|
1304
1394
|
}
|
|
1395
|
+
if (end < start) return rangeDescending(start,end)
|
|
1305
1396
|
|
|
1306
|
-
const len =
|
|
1397
|
+
const len = end - start;
|
|
1307
1398
|
const willReturn = Array(len);
|
|
1308
1399
|
|
|
1309
|
-
for (let i = 0; i < len
|
|
1310
|
-
willReturn[i] = start
|
|
1400
|
+
for (let i = 0; i < len; i++) {
|
|
1401
|
+
willReturn[i] = start + i;
|
|
1311
1402
|
}
|
|
1312
1403
|
|
|
1313
1404
|
return willReturn
|
|
@@ -1318,20 +1409,6 @@
|
|
|
1318
1409
|
return str => str.replace(pattern, replacer)
|
|
1319
1410
|
}
|
|
1320
1411
|
|
|
1321
|
-
function replaceItemAtIndex(index, replaceFn) {
|
|
1322
|
-
return list => {
|
|
1323
|
-
const actualIndex = index < 0 ? list.length + index : index;
|
|
1324
|
-
if (index >= list.length || actualIndex < 0) {
|
|
1325
|
-
return list
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
const clone = cloneList$1(list);
|
|
1329
|
-
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
1330
|
-
|
|
1331
|
-
return clone
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
1412
|
function shuffle(listInput) {
|
|
1336
1413
|
const list = cloneList(listInput);
|
|
1337
1414
|
let counter = list.length;
|
|
@@ -1347,24 +1424,45 @@
|
|
|
1347
1424
|
}
|
|
1348
1425
|
|
|
1349
1426
|
function sort(sortFn) {
|
|
1350
|
-
return list => cloneList
|
|
1427
|
+
return list => cloneList(list).sort(sortFn)
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
function sortByFn (
|
|
1431
|
+
sortFn,
|
|
1432
|
+
list,
|
|
1433
|
+
descending
|
|
1434
|
+
){
|
|
1435
|
+
const clone = cloneList(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
|
+
})
|
|
1351
1450
|
}
|
|
1352
1451
|
|
|
1353
1452
|
function sortBy(sortFn) {
|
|
1354
|
-
return list =>
|
|
1355
|
-
|
|
1453
|
+
return list => sortByFn(sortFn, list, false)
|
|
1454
|
+
}
|
|
1356
1455
|
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1456
|
+
function sortByDescending(sortFn) {
|
|
1457
|
+
return list => sortByFn(sortFn, list, true)
|
|
1458
|
+
}
|
|
1360
1459
|
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1460
|
+
function sortByPath(sortPath) {
|
|
1461
|
+
return list => sortBy(path(sortPath))(list)
|
|
1462
|
+
}
|
|
1364
1463
|
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
}
|
|
1464
|
+
function sortByPathDescending(sortPath) {
|
|
1465
|
+
return list => sortByDescending(path(sortPath))(list)
|
|
1368
1466
|
}
|
|
1369
1467
|
|
|
1370
1468
|
function sortObject(predicate) {
|
|
@@ -1529,7 +1627,7 @@
|
|
|
1529
1627
|
|
|
1530
1628
|
function union(x) {
|
|
1531
1629
|
return y => {
|
|
1532
|
-
const toReturn = cloneList
|
|
1630
|
+
const toReturn = cloneList(x);
|
|
1533
1631
|
|
|
1534
1632
|
y.forEach(yInstance => {
|
|
1535
1633
|
if (!includes(yInstance)(x)) {
|
|
@@ -1686,6 +1784,7 @@
|
|
|
1686
1784
|
exports._indexOf = _indexOf;
|
|
1687
1785
|
exports._lastIndexOf = _lastIndexOf;
|
|
1688
1786
|
exports.addProp = addProp;
|
|
1787
|
+
exports.addPropToObjects = addPropToObjects;
|
|
1689
1788
|
exports.all = all;
|
|
1690
1789
|
exports.allPass = allPass;
|
|
1691
1790
|
exports.any = any;
|
|
@@ -1721,6 +1820,8 @@
|
|
|
1721
1820
|
exports.findNth = findNth;
|
|
1722
1821
|
exports.flatMap = flatMap;
|
|
1723
1822
|
exports.flatten = flatten;
|
|
1823
|
+
exports.flattenObject = flattenObject;
|
|
1824
|
+
exports.flattenObjectHelper = flattenObjectHelper;
|
|
1724
1825
|
exports.groupBy = groupBy;
|
|
1725
1826
|
exports.groupByFallback = groupByFallback;
|
|
1726
1827
|
exports.head = head;
|
|
@@ -1736,6 +1837,7 @@
|
|
|
1736
1837
|
exports.lastIndexOf = lastIndexOf;
|
|
1737
1838
|
exports.map = map;
|
|
1738
1839
|
exports.mapAsync = mapAsync;
|
|
1840
|
+
exports.mapFn = mapFn;
|
|
1739
1841
|
exports.mapKeys = mapKeys;
|
|
1740
1842
|
exports.mapObject = mapObject;
|
|
1741
1843
|
exports.mapObjectAsync = mapObjectAsync;
|
|
@@ -1745,6 +1847,7 @@
|
|
|
1745
1847
|
exports.merge = merge;
|
|
1746
1848
|
exports.mergeTypes = mergeTypes;
|
|
1747
1849
|
exports.minBy = minBy;
|
|
1850
|
+
exports.modifyItemAtIndex = modifyItemAtIndex;
|
|
1748
1851
|
exports.modifyProp = modifyProp;
|
|
1749
1852
|
exports.none = none;
|
|
1750
1853
|
exports.objOf = objOf;
|
|
@@ -1753,6 +1856,7 @@
|
|
|
1753
1856
|
exports.partition = partition;
|
|
1754
1857
|
exports.partitionObject = partitionObject;
|
|
1755
1858
|
exports.path = path;
|
|
1859
|
+
exports.pathSatisfies = pathSatisfies;
|
|
1756
1860
|
exports.permutations = permutations;
|
|
1757
1861
|
exports.pick = pick;
|
|
1758
1862
|
exports.pipe = pipe;
|
|
@@ -1764,15 +1868,17 @@
|
|
|
1764
1868
|
exports.propOr = propOr;
|
|
1765
1869
|
exports.propSatisfies = propSatisfies;
|
|
1766
1870
|
exports.range = range;
|
|
1767
|
-
exports.rangeDescending = rangeDescending;
|
|
1768
1871
|
exports.reduce = reduce;
|
|
1769
1872
|
exports.reject = reject;
|
|
1770
1873
|
exports.rejectObject = rejectObject;
|
|
1771
1874
|
exports.replace = replace;
|
|
1772
|
-
exports.replaceItemAtIndex = replaceItemAtIndex;
|
|
1773
1875
|
exports.shuffle = shuffle;
|
|
1774
1876
|
exports.sort = sort;
|
|
1775
1877
|
exports.sortBy = sortBy;
|
|
1878
|
+
exports.sortByDescending = sortByDescending;
|
|
1879
|
+
exports.sortByFn = sortByFn;
|
|
1880
|
+
exports.sortByPath = sortByPath;
|
|
1881
|
+
exports.sortByPathDescending = sortByPathDescending;
|
|
1776
1882
|
exports.sortObject = sortObject;
|
|
1777
1883
|
exports.sortWith = sortWith;
|
|
1778
1884
|
exports.split = split;
|
|
@@ -1785,6 +1891,7 @@
|
|
|
1785
1891
|
exports.takeWhile = takeWhile;
|
|
1786
1892
|
exports.tap = tap;
|
|
1787
1893
|
exports.test = test;
|
|
1894
|
+
exports.transformFlatObject = transformFlatObject;
|
|
1788
1895
|
exports.tryCatch = tryCatch;
|
|
1789
1896
|
exports.type = type;
|
|
1790
1897
|
exports.union = union;
|