rambda 10.0.0-beta.1 → 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 +9 -8
- package/README.md +947 -300
- package/dist/rambda.cjs +206 -99
- package/dist/rambda.js +196 -98
- package/dist/rambda.umd.js +206 -99
- package/immutable.d.ts +586 -13
- package/index.d.ts +586 -13
- package/package.json +7 -7
- 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/sortBy.js +21 -12
- package/src/sortByDescending.js +5 -0
- package/src/sortByPath.js +6 -0
- package/src/sortByPathDescending.js +6 -0
package/dist/rambda.js
CHANGED
|
@@ -2,6 +2,35 @@ function addProp(key, value) {
|
|
|
2
2
|
return obj => ({ ...obj, [key]: value })
|
|
3
3
|
}
|
|
4
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
|
+
}
|
|
33
|
+
|
|
5
34
|
function all(predicate) {
|
|
6
35
|
return list => {
|
|
7
36
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -201,12 +230,8 @@ function isFalsy(input) {
|
|
|
201
230
|
return input === undefined || input === null || Number.isNaN(input) === true
|
|
202
231
|
}
|
|
203
232
|
|
|
204
|
-
function defaultTo(defaultArgument
|
|
205
|
-
|
|
206
|
-
return _input => defaultTo(defaultArgument, _input)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return isFalsy(input) ? defaultArgument : input
|
|
233
|
+
function defaultTo(defaultArgument) {
|
|
234
|
+
return input => isFalsy(input) ? defaultArgument : input
|
|
210
235
|
}
|
|
211
236
|
|
|
212
237
|
function descend(getFunction) {
|
|
@@ -218,12 +243,8 @@ function descend(getFunction) {
|
|
|
218
243
|
}
|
|
219
244
|
}
|
|
220
245
|
|
|
221
|
-
function drop(howManyToDrop,
|
|
222
|
-
|
|
223
|
-
return _list => drop(howManyToDrop, _list)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0)
|
|
246
|
+
function drop(howManyToDrop, ) {
|
|
247
|
+
return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
|
|
227
248
|
}
|
|
228
249
|
|
|
229
250
|
function dropLast(numberItems) {
|
|
@@ -658,6 +679,81 @@ function flatten(list, input) {
|
|
|
658
679
|
return willReturn
|
|
659
680
|
}
|
|
660
681
|
|
|
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;
|
|
690
|
+
|
|
691
|
+
return
|
|
692
|
+
} else if (accumulator.length > 0){
|
|
693
|
+
const finalKey = [ ...accumulator, key ].join('.');
|
|
694
|
+
willReturn[ finalKey ] = obj[ key ];
|
|
695
|
+
|
|
696
|
+
return
|
|
697
|
+
}
|
|
698
|
+
willReturn[ key ] = obj[ key ];
|
|
699
|
+
});
|
|
700
|
+
if (accumulator.length > 0) return [ willReturn, accumulator ]
|
|
701
|
+
|
|
702
|
+
return willReturn
|
|
703
|
+
}
|
|
704
|
+
|
|
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
|
+
|
|
661
757
|
function groupByFallback(groupFn, list) {
|
|
662
758
|
const result = {};
|
|
663
759
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -821,18 +917,6 @@ function lastIndexOf(valueToFind) {
|
|
|
821
917
|
return list => _lastIndexOf(valueToFind, list)
|
|
822
918
|
}
|
|
823
919
|
|
|
824
|
-
function map(fn) {
|
|
825
|
-
return list => {
|
|
826
|
-
let index = 0;
|
|
827
|
-
const willReturn = Array(list.length);
|
|
828
|
-
while (index < list.length) {
|
|
829
|
-
willReturn[index] = fn(list[index], index);
|
|
830
|
-
index++;
|
|
831
|
-
}
|
|
832
|
-
return willReturn
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
|
|
836
920
|
function mapAsync(fn) {
|
|
837
921
|
return async list => {
|
|
838
922
|
const willReturn = [];
|
|
@@ -897,6 +981,20 @@ function minBy(compareFn, x) {
|
|
|
897
981
|
return y => (compareFn(y) < compareFn(x) ? y : x)
|
|
898
982
|
}
|
|
899
983
|
|
|
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
|
+
}
|
|
990
|
+
|
|
991
|
+
const clone = cloneList$1(list);
|
|
992
|
+
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
993
|
+
|
|
994
|
+
return clone
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
|
|
900
998
|
function update(index, newValue) {
|
|
901
999
|
return list => {
|
|
902
1000
|
const clone = cloneList$1(list);
|
|
@@ -1024,32 +1122,34 @@ function partitionObject(predicate) {
|
|
|
1024
1122
|
}
|
|
1025
1123
|
}
|
|
1026
1124
|
|
|
1027
|
-
function path(pathInput
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
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
|
+
}
|
|
1051
1150
|
|
|
1052
|
-
|
|
1151
|
+
function pathSatisfies(fn, pathInput) {
|
|
1152
|
+
return obj => Boolean(fn(path(pathInput)(obj)))
|
|
1053
1153
|
}
|
|
1054
1154
|
|
|
1055
1155
|
/**
|
|
@@ -1258,7 +1358,7 @@ function propOr(defaultValue, property) {
|
|
|
1258
1358
|
return defaultValue
|
|
1259
1359
|
}
|
|
1260
1360
|
|
|
1261
|
-
return defaultTo(defaultValue
|
|
1361
|
+
return defaultTo(defaultValue)(obj[property])
|
|
1262
1362
|
}
|
|
1263
1363
|
}
|
|
1264
1364
|
|
|
@@ -1266,42 +1366,33 @@ function propSatisfies(predicate, property) {
|
|
|
1266
1366
|
return obj => predicate(obj[property])
|
|
1267
1367
|
}
|
|
1268
1368
|
|
|
1269
|
-
function
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
throw new TypeError('Both arguments to range must be numbers')
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
if (end <= start) {
|
|
1276
|
-
return []
|
|
1277
|
-
}
|
|
1369
|
+
function rangeDescending(start, end) {
|
|
1370
|
+
const len = start - end;
|
|
1371
|
+
const willReturn = Array(len);
|
|
1278
1372
|
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
for (let i = 0; i < len + 1; i++) {
|
|
1283
|
-
willReturn[i] = start + i;
|
|
1284
|
-
}
|
|
1373
|
+
for (let i = 0; i < len; i++) {
|
|
1374
|
+
willReturn[i] = start - i;
|
|
1375
|
+
}
|
|
1285
1376
|
|
|
1286
|
-
|
|
1287
|
-
}
|
|
1377
|
+
return willReturn
|
|
1288
1378
|
}
|
|
1289
1379
|
|
|
1290
|
-
function
|
|
1380
|
+
function range(start) {
|
|
1291
1381
|
return end => {
|
|
1292
1382
|
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
1293
1383
|
throw new TypeError('Both arguments to range must be numbers')
|
|
1294
1384
|
}
|
|
1295
1385
|
|
|
1296
|
-
if (end
|
|
1386
|
+
if (end === start) {
|
|
1297
1387
|
return []
|
|
1298
1388
|
}
|
|
1389
|
+
if (end < start) return rangeDescending(start,end)
|
|
1299
1390
|
|
|
1300
|
-
const len =
|
|
1391
|
+
const len = end - start;
|
|
1301
1392
|
const willReturn = Array(len);
|
|
1302
1393
|
|
|
1303
|
-
for (let i = 0; i < len
|
|
1304
|
-
willReturn[i] = start
|
|
1394
|
+
for (let i = 0; i < len; i++) {
|
|
1395
|
+
willReturn[i] = start + i;
|
|
1305
1396
|
}
|
|
1306
1397
|
|
|
1307
1398
|
return willReturn
|
|
@@ -1312,20 +1403,6 @@ function replace(pattern, replacer) {
|
|
|
1312
1403
|
return str => str.replace(pattern, replacer)
|
|
1313
1404
|
}
|
|
1314
1405
|
|
|
1315
|
-
function replaceItemAtIndex(index, replaceFn) {
|
|
1316
|
-
return list => {
|
|
1317
|
-
const actualIndex = index < 0 ? list.length + index : index;
|
|
1318
|
-
if (index >= list.length || actualIndex < 0) {
|
|
1319
|
-
return list
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
const clone = cloneList$1(list);
|
|
1323
|
-
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
1324
|
-
|
|
1325
|
-
return clone
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
1406
|
function shuffle(listInput) {
|
|
1330
1407
|
const list = cloneList(listInput);
|
|
1331
1408
|
let counter = list.length;
|
|
@@ -1344,21 +1421,42 @@ function sort(sortFn) {
|
|
|
1344
1421
|
return list => cloneList$1(list).sort(sortFn)
|
|
1345
1422
|
}
|
|
1346
1423
|
|
|
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
|
+
})
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1347
1446
|
function sortBy(sortFn) {
|
|
1348
|
-
return list =>
|
|
1349
|
-
|
|
1447
|
+
return list => sortByFn(sortFn, list, false)
|
|
1448
|
+
}
|
|
1350
1449
|
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1450
|
+
function sortByDescending(sortFn) {
|
|
1451
|
+
return list => sortByFn(sortFn, list, true)
|
|
1452
|
+
}
|
|
1354
1453
|
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1454
|
+
function sortByPath(sortPath) {
|
|
1455
|
+
return list => sortBy(path(sortPath))(list)
|
|
1456
|
+
}
|
|
1358
1457
|
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
}
|
|
1458
|
+
function sortByPathDescending(sortPath) {
|
|
1459
|
+
return list => sortByDescending(path(sortPath))(list)
|
|
1362
1460
|
}
|
|
1363
1461
|
|
|
1364
1462
|
function sortObject(predicate) {
|
|
@@ -1675,4 +1773,4 @@ function zipWith(fn, x) {
|
|
|
1675
1773
|
)
|
|
1676
1774
|
}
|
|
1677
1775
|
|
|
1678
|
-
export { _arity, _includes, _indexOf, _lastIndexOf, addProp, 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, groupBy, groupByFallback, head, includes, indexOf, init, innerJoin, interpolate, intersection, intersperse, join, last, lastIndexOf, map, mapAsync, mapKeys, mapObject, mapObjectAsync, mapParallelAsync, match, maxBy, merge, mergeTypes, minBy, modifyProp, none, objOf, objectIncludes, omit, partition, partitionObject, path, permutations, pick, pipe, pipeAsync, pluck, prepend, prop, propEq, propOr, propSatisfies, range,
|
|
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 };
|