rambda 10.1.0 → 10.3.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 +125 -10
- package/README.md +1021 -259
- package/dist/rambda.cjs +167 -73
- package/dist/rambda.js +162 -74
- package/dist/rambda.umd.js +167 -73
- package/index.d.cts +179 -44
- package/index.d.ts +179 -44
- package/package.json +8 -8
- package/rambda.js +6 -0
- package/src/duplicateBy.js +9 -0
- package/src/filterAsync.js +14 -0
- package/src/indexBy.js +14 -0
- package/src/mapAsync.js +2 -2
- package/src/mapPropObject.js +10 -0
- package/src/modifyPath.js +30 -0
- package/src/replaceAll.js +10 -0
package/dist/rambda.cjs
CHANGED
|
@@ -535,6 +535,53 @@ function equals(a) {
|
|
|
535
535
|
return b => equalsFn(a, b)
|
|
536
536
|
}
|
|
537
537
|
|
|
538
|
+
class _Set {
|
|
539
|
+
constructor() {
|
|
540
|
+
this.set = new Set();
|
|
541
|
+
this.items = {};
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
checkUniqueness(item) {
|
|
545
|
+
const type$1 = type(item);
|
|
546
|
+
if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
|
|
547
|
+
if (type$1 in this.items) {
|
|
548
|
+
return false
|
|
549
|
+
}
|
|
550
|
+
this.items[type$1] = true;
|
|
551
|
+
|
|
552
|
+
return true
|
|
553
|
+
}
|
|
554
|
+
if (!['Object', 'Array'].includes(type$1)) {
|
|
555
|
+
const prevSize = this.set.size;
|
|
556
|
+
this.set.add(item);
|
|
557
|
+
|
|
558
|
+
return this.set.size !== prevSize
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (!(type$1 in this.items)) {
|
|
562
|
+
this.items[type$1] = [item];
|
|
563
|
+
|
|
564
|
+
return true
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (_indexOf(item, this.items[type$1]) === -1) {
|
|
568
|
+
this.items[type$1].push(item);
|
|
569
|
+
|
|
570
|
+
return true
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
return false
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function duplicateBy(fn) {
|
|
578
|
+
return list => {
|
|
579
|
+
const set = new _Set();
|
|
580
|
+
|
|
581
|
+
return list.filter(item => !set.checkUniqueness(fn(item)))
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
538
585
|
function eqBy(fn, a) {
|
|
539
586
|
return b => equalsFn(fn(a), fn(b))
|
|
540
587
|
}
|
|
@@ -586,6 +633,21 @@ function excludes(valueToFind) {
|
|
|
586
633
|
return iterable => !includes(valueToFind)(iterable)
|
|
587
634
|
}
|
|
588
635
|
|
|
636
|
+
function filterAsync(predicate) {
|
|
637
|
+
return async list => {
|
|
638
|
+
const willReturn = [];
|
|
639
|
+
let index = 0;
|
|
640
|
+
for (const x of list) {
|
|
641
|
+
if (await predicate(x, index)) {
|
|
642
|
+
willReturn.push(list[index]);
|
|
643
|
+
}
|
|
644
|
+
index++;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
return willReturn
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
589
651
|
function filterObject(predicate) {
|
|
590
652
|
return obj => {
|
|
591
653
|
const willReturn = {};
|
|
@@ -798,6 +860,21 @@ function head(listOrString) {
|
|
|
798
860
|
return listOrString[0]
|
|
799
861
|
}
|
|
800
862
|
|
|
863
|
+
function indexBy(property){
|
|
864
|
+
return list => {
|
|
865
|
+
const toReturn = {};
|
|
866
|
+
for (let i = 0; i < list.length; i++){
|
|
867
|
+
const item = list[ i ];
|
|
868
|
+
const key = item[property];
|
|
869
|
+
if(key !== undefined){
|
|
870
|
+
toReturn[ key ] = item;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
return toReturn
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
801
878
|
function indexOf(valueToFind) {
|
|
802
879
|
return list => _indexOf(valueToFind, list)
|
|
803
880
|
}
|
|
@@ -936,8 +1013,8 @@ function mapAsync(fn) {
|
|
|
936
1013
|
return async list => {
|
|
937
1014
|
const willReturn = [];
|
|
938
1015
|
let i = 0;
|
|
939
|
-
for (const
|
|
940
|
-
willReturn.push(await fn(
|
|
1016
|
+
for (const x of list) {
|
|
1017
|
+
willReturn.push(await fn(x, i++));
|
|
941
1018
|
}
|
|
942
1019
|
|
|
943
1020
|
return willReturn
|
|
@@ -971,6 +1048,17 @@ function mapParallelAsync(fn) {
|
|
|
971
1048
|
return async list => Promise.all(list.map((x, i) => fn(x, i)))
|
|
972
1049
|
}
|
|
973
1050
|
|
|
1051
|
+
function mapPropObject(fn, prop) {
|
|
1052
|
+
return obj => {
|
|
1053
|
+
if (!Array.isArray(obj[prop])) return obj
|
|
1054
|
+
|
|
1055
|
+
return {
|
|
1056
|
+
...obj,
|
|
1057
|
+
[prop]: obj[prop].map(fn)
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
974
1062
|
function match(pattern) {
|
|
975
1063
|
return input => {
|
|
976
1064
|
const willReturn = input.match(pattern);
|
|
@@ -1010,6 +1098,66 @@ function modifyItemAtIndex(index, replaceFn) {
|
|
|
1010
1098
|
}
|
|
1011
1099
|
}
|
|
1012
1100
|
|
|
1101
|
+
function createPath(path, delimiter = '.') {
|
|
1102
|
+
return typeof path === 'string'
|
|
1103
|
+
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1104
|
+
: path
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
function path(pathInput) {
|
|
1108
|
+
return (obj) => {
|
|
1109
|
+
if (!obj) {
|
|
1110
|
+
return undefined
|
|
1111
|
+
}
|
|
1112
|
+
let willReturn = obj;
|
|
1113
|
+
let counter = 0;
|
|
1114
|
+
|
|
1115
|
+
const pathArrValue = createPath(pathInput);
|
|
1116
|
+
|
|
1117
|
+
while (counter < pathArrValue.length) {
|
|
1118
|
+
if (willReturn === null || willReturn === undefined) {
|
|
1119
|
+
return undefined
|
|
1120
|
+
}
|
|
1121
|
+
if (willReturn[pathArrValue[counter]] === null) {
|
|
1122
|
+
return undefined
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
willReturn = willReturn[pathArrValue[counter]];
|
|
1126
|
+
counter++;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
return willReturn
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
function assoc(prop, newValue) {
|
|
1134
|
+
return obj => Object.assign({}, obj, { [prop]: newValue })
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
function modifyPathFn(pathInput, fn, obj) {
|
|
1138
|
+
const path$1 = createPath(pathInput);
|
|
1139
|
+
if (path$1.length === 1) {
|
|
1140
|
+
return {
|
|
1141
|
+
...obj,
|
|
1142
|
+
[path$1[0]]: fn(obj[path$1[0]]),
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
if (path(path$1)(obj) === undefined) {
|
|
1146
|
+
return obj
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
const val = modifyPathFn(Array.prototype.slice.call(path$1, 1), fn, obj[path$1[0]]);
|
|
1150
|
+
if (val === obj[path$1[0]]) {
|
|
1151
|
+
return obj
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
return assoc(path$1[0], val)(obj)
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
function modifyPath(pathInput, fn) {
|
|
1158
|
+
return obj => modifyPathFn(pathInput, fn, obj)
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1013
1161
|
function update(index, newValue) {
|
|
1014
1162
|
return list => {
|
|
1015
1163
|
const clone = cloneList(list);
|
|
@@ -1065,12 +1213,6 @@ function objectIncludes(condition) {
|
|
|
1065
1213
|
}
|
|
1066
1214
|
}
|
|
1067
1215
|
|
|
1068
|
-
function createPath(path, delimiter = '.') {
|
|
1069
|
-
return typeof path === 'string'
|
|
1070
|
-
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1071
|
-
: path
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
1216
|
function _includes(x, list) {
|
|
1075
1217
|
let index = -1;
|
|
1076
1218
|
const { length } = list;
|
|
@@ -1137,32 +1279,6 @@ function partitionObject(predicate) {
|
|
|
1137
1279
|
}
|
|
1138
1280
|
}
|
|
1139
1281
|
|
|
1140
|
-
function path(pathInput) {
|
|
1141
|
-
return (obj) => {
|
|
1142
|
-
if (!obj) {
|
|
1143
|
-
return undefined
|
|
1144
|
-
}
|
|
1145
|
-
let willReturn = obj;
|
|
1146
|
-
let counter = 0;
|
|
1147
|
-
|
|
1148
|
-
const pathArrValue = createPath(pathInput);
|
|
1149
|
-
|
|
1150
|
-
while (counter < pathArrValue.length) {
|
|
1151
|
-
if (willReturn === null || willReturn === undefined) {
|
|
1152
|
-
return undefined
|
|
1153
|
-
}
|
|
1154
|
-
if (willReturn[pathArrValue[counter]] === null) {
|
|
1155
|
-
return undefined
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
willReturn = willReturn[pathArrValue[counter]];
|
|
1159
|
-
counter++;
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
return willReturn
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
1282
|
function pathSatisfies(fn, pathInput) {
|
|
1167
1283
|
return obj => Boolean(fn(path(pathInput)(obj)))
|
|
1168
1284
|
}
|
|
@@ -1418,6 +1534,17 @@ function replace(pattern, replacer) {
|
|
|
1418
1534
|
return str => str.replace(pattern, replacer)
|
|
1419
1535
|
}
|
|
1420
1536
|
|
|
1537
|
+
function replaceAll(patterns, replacer) {
|
|
1538
|
+
return input => {
|
|
1539
|
+
let text = input;
|
|
1540
|
+
patterns.forEach(singlePattern => {
|
|
1541
|
+
text = text.replace(singlePattern, replacer);
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1544
|
+
return text
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1421
1548
|
function shuffle(listInput) {
|
|
1422
1549
|
const list = cloneList(listInput);
|
|
1423
1550
|
let counter = list.length;
|
|
@@ -1648,45 +1775,6 @@ function union(x) {
|
|
|
1648
1775
|
}
|
|
1649
1776
|
}
|
|
1650
1777
|
|
|
1651
|
-
class _Set {
|
|
1652
|
-
constructor() {
|
|
1653
|
-
this.set = new Set();
|
|
1654
|
-
this.items = {};
|
|
1655
|
-
}
|
|
1656
|
-
|
|
1657
|
-
checkUniqueness(item) {
|
|
1658
|
-
const type$1 = type(item);
|
|
1659
|
-
if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
|
|
1660
|
-
if (type$1 in this.items) {
|
|
1661
|
-
return false
|
|
1662
|
-
}
|
|
1663
|
-
this.items[type$1] = true;
|
|
1664
|
-
|
|
1665
|
-
return true
|
|
1666
|
-
}
|
|
1667
|
-
if (!['Object', 'Array'].includes(type$1)) {
|
|
1668
|
-
const prevSize = this.set.size;
|
|
1669
|
-
this.set.add(item);
|
|
1670
|
-
|
|
1671
|
-
return this.set.size !== prevSize
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
if (!(type$1 in this.items)) {
|
|
1675
|
-
this.items[type$1] = [item];
|
|
1676
|
-
|
|
1677
|
-
return true
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
if (_indexOf(item, this.items[type$1]) === -1) {
|
|
1681
|
-
this.items[type$1].push(item);
|
|
1682
|
-
|
|
1683
|
-
return true
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
return false
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
1778
|
function uniq(list) {
|
|
1691
1779
|
const set = new _Set();
|
|
1692
1780
|
const willReturn = [];
|
|
@@ -1816,6 +1904,7 @@ exports.drop = drop;
|
|
|
1816
1904
|
exports.dropLast = dropLast;
|
|
1817
1905
|
exports.dropLastWhile = dropLastWhile;
|
|
1818
1906
|
exports.dropWhile = dropWhile;
|
|
1907
|
+
exports.duplicateBy = duplicateBy;
|
|
1819
1908
|
exports.eqBy = eqBy;
|
|
1820
1909
|
exports.eqProps = eqProps;
|
|
1821
1910
|
exports.equals = equals;
|
|
@@ -1823,6 +1912,7 @@ exports.equalsFn = equalsFn;
|
|
|
1823
1912
|
exports.evolve = evolve;
|
|
1824
1913
|
exports.excludes = excludes;
|
|
1825
1914
|
exports.filter = filter;
|
|
1915
|
+
exports.filterAsync = filterAsync;
|
|
1826
1916
|
exports.filterObject = filterObject;
|
|
1827
1917
|
exports.find = find;
|
|
1828
1918
|
exports.findIndex = findIndex;
|
|
@@ -1837,6 +1927,7 @@ exports.groupBy = groupBy;
|
|
|
1837
1927
|
exports.groupByFallback = groupByFallback;
|
|
1838
1928
|
exports.head = head;
|
|
1839
1929
|
exports.includes = includes;
|
|
1930
|
+
exports.indexBy = indexBy;
|
|
1840
1931
|
exports.indexOf = indexOf;
|
|
1841
1932
|
exports.init = init;
|
|
1842
1933
|
exports.innerJoin = innerJoin;
|
|
@@ -1853,12 +1944,14 @@ exports.mapKeys = mapKeys;
|
|
|
1853
1944
|
exports.mapObject = mapObject;
|
|
1854
1945
|
exports.mapObjectAsync = mapObjectAsync;
|
|
1855
1946
|
exports.mapParallelAsync = mapParallelAsync;
|
|
1947
|
+
exports.mapPropObject = mapPropObject;
|
|
1856
1948
|
exports.match = match;
|
|
1857
1949
|
exports.maxBy = maxBy;
|
|
1858
1950
|
exports.merge = merge;
|
|
1859
1951
|
exports.mergeTypes = mergeTypes;
|
|
1860
1952
|
exports.minBy = minBy;
|
|
1861
1953
|
exports.modifyItemAtIndex = modifyItemAtIndex;
|
|
1954
|
+
exports.modifyPath = modifyPath;
|
|
1862
1955
|
exports.modifyProp = modifyProp;
|
|
1863
1956
|
exports.none = none;
|
|
1864
1957
|
exports.objOf = objOf;
|
|
@@ -1883,6 +1976,7 @@ exports.reduce = reduce;
|
|
|
1883
1976
|
exports.reject = reject;
|
|
1884
1977
|
exports.rejectObject = rejectObject;
|
|
1885
1978
|
exports.replace = replace;
|
|
1979
|
+
exports.replaceAll = replaceAll;
|
|
1886
1980
|
exports.shuffle = shuffle;
|
|
1887
1981
|
exports.sort = sort;
|
|
1888
1982
|
exports.sortBy = sortBy;
|
package/dist/rambda.js
CHANGED
|
@@ -533,6 +533,53 @@ function equals(a) {
|
|
|
533
533
|
return b => equalsFn(a, b)
|
|
534
534
|
}
|
|
535
535
|
|
|
536
|
+
class _Set {
|
|
537
|
+
constructor() {
|
|
538
|
+
this.set = new Set();
|
|
539
|
+
this.items = {};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
checkUniqueness(item) {
|
|
543
|
+
const type$1 = type(item);
|
|
544
|
+
if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
|
|
545
|
+
if (type$1 in this.items) {
|
|
546
|
+
return false
|
|
547
|
+
}
|
|
548
|
+
this.items[type$1] = true;
|
|
549
|
+
|
|
550
|
+
return true
|
|
551
|
+
}
|
|
552
|
+
if (!['Object', 'Array'].includes(type$1)) {
|
|
553
|
+
const prevSize = this.set.size;
|
|
554
|
+
this.set.add(item);
|
|
555
|
+
|
|
556
|
+
return this.set.size !== prevSize
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (!(type$1 in this.items)) {
|
|
560
|
+
this.items[type$1] = [item];
|
|
561
|
+
|
|
562
|
+
return true
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if (_indexOf(item, this.items[type$1]) === -1) {
|
|
566
|
+
this.items[type$1].push(item);
|
|
567
|
+
|
|
568
|
+
return true
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return false
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function duplicateBy(fn) {
|
|
576
|
+
return list => {
|
|
577
|
+
const set = new _Set();
|
|
578
|
+
|
|
579
|
+
return list.filter(item => !set.checkUniqueness(fn(item)))
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
536
583
|
function eqBy(fn, a) {
|
|
537
584
|
return b => equalsFn(fn(a), fn(b))
|
|
538
585
|
}
|
|
@@ -584,6 +631,21 @@ function excludes(valueToFind) {
|
|
|
584
631
|
return iterable => !includes(valueToFind)(iterable)
|
|
585
632
|
}
|
|
586
633
|
|
|
634
|
+
function filterAsync(predicate) {
|
|
635
|
+
return async list => {
|
|
636
|
+
const willReturn = [];
|
|
637
|
+
let index = 0;
|
|
638
|
+
for (const x of list) {
|
|
639
|
+
if (await predicate(x, index)) {
|
|
640
|
+
willReturn.push(list[index]);
|
|
641
|
+
}
|
|
642
|
+
index++;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
return willReturn
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
587
649
|
function filterObject(predicate) {
|
|
588
650
|
return obj => {
|
|
589
651
|
const willReturn = {};
|
|
@@ -796,6 +858,21 @@ function head(listOrString) {
|
|
|
796
858
|
return listOrString[0]
|
|
797
859
|
}
|
|
798
860
|
|
|
861
|
+
function indexBy(property){
|
|
862
|
+
return list => {
|
|
863
|
+
const toReturn = {};
|
|
864
|
+
for (let i = 0; i < list.length; i++){
|
|
865
|
+
const item = list[ i ];
|
|
866
|
+
const key = item[property];
|
|
867
|
+
if(key !== undefined){
|
|
868
|
+
toReturn[ key ] = item;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
return toReturn
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
799
876
|
function indexOf(valueToFind) {
|
|
800
877
|
return list => _indexOf(valueToFind, list)
|
|
801
878
|
}
|
|
@@ -934,8 +1011,8 @@ function mapAsync(fn) {
|
|
|
934
1011
|
return async list => {
|
|
935
1012
|
const willReturn = [];
|
|
936
1013
|
let i = 0;
|
|
937
|
-
for (const
|
|
938
|
-
willReturn.push(await fn(
|
|
1014
|
+
for (const x of list) {
|
|
1015
|
+
willReturn.push(await fn(x, i++));
|
|
939
1016
|
}
|
|
940
1017
|
|
|
941
1018
|
return willReturn
|
|
@@ -969,6 +1046,17 @@ function mapParallelAsync(fn) {
|
|
|
969
1046
|
return async list => Promise.all(list.map((x, i) => fn(x, i)))
|
|
970
1047
|
}
|
|
971
1048
|
|
|
1049
|
+
function mapPropObject(fn, prop) {
|
|
1050
|
+
return obj => {
|
|
1051
|
+
if (!Array.isArray(obj[prop])) return obj
|
|
1052
|
+
|
|
1053
|
+
return {
|
|
1054
|
+
...obj,
|
|
1055
|
+
[prop]: obj[prop].map(fn)
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
972
1060
|
function match(pattern) {
|
|
973
1061
|
return input => {
|
|
974
1062
|
const willReturn = input.match(pattern);
|
|
@@ -1008,6 +1096,66 @@ function modifyItemAtIndex(index, replaceFn) {
|
|
|
1008
1096
|
}
|
|
1009
1097
|
}
|
|
1010
1098
|
|
|
1099
|
+
function createPath(path, delimiter = '.') {
|
|
1100
|
+
return typeof path === 'string'
|
|
1101
|
+
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1102
|
+
: path
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
function path(pathInput) {
|
|
1106
|
+
return (obj) => {
|
|
1107
|
+
if (!obj) {
|
|
1108
|
+
return undefined
|
|
1109
|
+
}
|
|
1110
|
+
let willReturn = obj;
|
|
1111
|
+
let counter = 0;
|
|
1112
|
+
|
|
1113
|
+
const pathArrValue = createPath(pathInput);
|
|
1114
|
+
|
|
1115
|
+
while (counter < pathArrValue.length) {
|
|
1116
|
+
if (willReturn === null || willReturn === undefined) {
|
|
1117
|
+
return undefined
|
|
1118
|
+
}
|
|
1119
|
+
if (willReturn[pathArrValue[counter]] === null) {
|
|
1120
|
+
return undefined
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
willReturn = willReturn[pathArrValue[counter]];
|
|
1124
|
+
counter++;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
return willReturn
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function assoc(prop, newValue) {
|
|
1132
|
+
return obj => Object.assign({}, obj, { [prop]: newValue })
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
function modifyPathFn(pathInput, fn, obj) {
|
|
1136
|
+
const path$1 = createPath(pathInput);
|
|
1137
|
+
if (path$1.length === 1) {
|
|
1138
|
+
return {
|
|
1139
|
+
...obj,
|
|
1140
|
+
[path$1[0]]: fn(obj[path$1[0]]),
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
if (path(path$1)(obj) === undefined) {
|
|
1144
|
+
return obj
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
const val = modifyPathFn(Array.prototype.slice.call(path$1, 1), fn, obj[path$1[0]]);
|
|
1148
|
+
if (val === obj[path$1[0]]) {
|
|
1149
|
+
return obj
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
return assoc(path$1[0], val)(obj)
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
function modifyPath(pathInput, fn) {
|
|
1156
|
+
return obj => modifyPathFn(pathInput, fn, obj)
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1011
1159
|
function update(index, newValue) {
|
|
1012
1160
|
return list => {
|
|
1013
1161
|
const clone = cloneList(list);
|
|
@@ -1063,12 +1211,6 @@ function objectIncludes(condition) {
|
|
|
1063
1211
|
}
|
|
1064
1212
|
}
|
|
1065
1213
|
|
|
1066
|
-
function createPath(path, delimiter = '.') {
|
|
1067
|
-
return typeof path === 'string'
|
|
1068
|
-
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1069
|
-
: path
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
1214
|
function _includes(x, list) {
|
|
1073
1215
|
let index = -1;
|
|
1074
1216
|
const { length } = list;
|
|
@@ -1135,32 +1277,6 @@ function partitionObject(predicate) {
|
|
|
1135
1277
|
}
|
|
1136
1278
|
}
|
|
1137
1279
|
|
|
1138
|
-
function path(pathInput) {
|
|
1139
|
-
return (obj) => {
|
|
1140
|
-
if (!obj) {
|
|
1141
|
-
return undefined
|
|
1142
|
-
}
|
|
1143
|
-
let willReturn = obj;
|
|
1144
|
-
let counter = 0;
|
|
1145
|
-
|
|
1146
|
-
const pathArrValue = createPath(pathInput);
|
|
1147
|
-
|
|
1148
|
-
while (counter < pathArrValue.length) {
|
|
1149
|
-
if (willReturn === null || willReturn === undefined) {
|
|
1150
|
-
return undefined
|
|
1151
|
-
}
|
|
1152
|
-
if (willReturn[pathArrValue[counter]] === null) {
|
|
1153
|
-
return undefined
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
willReturn = willReturn[pathArrValue[counter]];
|
|
1157
|
-
counter++;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
return willReturn
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
1280
|
function pathSatisfies(fn, pathInput) {
|
|
1165
1281
|
return obj => Boolean(fn(path(pathInput)(obj)))
|
|
1166
1282
|
}
|
|
@@ -1416,6 +1532,17 @@ function replace(pattern, replacer) {
|
|
|
1416
1532
|
return str => str.replace(pattern, replacer)
|
|
1417
1533
|
}
|
|
1418
1534
|
|
|
1535
|
+
function replaceAll(patterns, replacer) {
|
|
1536
|
+
return input => {
|
|
1537
|
+
let text = input;
|
|
1538
|
+
patterns.forEach(singlePattern => {
|
|
1539
|
+
text = text.replace(singlePattern, replacer);
|
|
1540
|
+
});
|
|
1541
|
+
|
|
1542
|
+
return text
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1419
1546
|
function shuffle(listInput) {
|
|
1420
1547
|
const list = cloneList(listInput);
|
|
1421
1548
|
let counter = list.length;
|
|
@@ -1646,45 +1773,6 @@ function union(x) {
|
|
|
1646
1773
|
}
|
|
1647
1774
|
}
|
|
1648
1775
|
|
|
1649
|
-
class _Set {
|
|
1650
|
-
constructor() {
|
|
1651
|
-
this.set = new Set();
|
|
1652
|
-
this.items = {};
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
checkUniqueness(item) {
|
|
1656
|
-
const type$1 = type(item);
|
|
1657
|
-
if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
|
|
1658
|
-
if (type$1 in this.items) {
|
|
1659
|
-
return false
|
|
1660
|
-
}
|
|
1661
|
-
this.items[type$1] = true;
|
|
1662
|
-
|
|
1663
|
-
return true
|
|
1664
|
-
}
|
|
1665
|
-
if (!['Object', 'Array'].includes(type$1)) {
|
|
1666
|
-
const prevSize = this.set.size;
|
|
1667
|
-
this.set.add(item);
|
|
1668
|
-
|
|
1669
|
-
return this.set.size !== prevSize
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
if (!(type$1 in this.items)) {
|
|
1673
|
-
this.items[type$1] = [item];
|
|
1674
|
-
|
|
1675
|
-
return true
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
|
-
if (_indexOf(item, this.items[type$1]) === -1) {
|
|
1679
|
-
this.items[type$1].push(item);
|
|
1680
|
-
|
|
1681
|
-
return true
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
return false
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
1776
|
function uniq(list) {
|
|
1689
1777
|
const set = new _Set();
|
|
1690
1778
|
const willReturn = [];
|
|
@@ -1786,4 +1874,4 @@ function zipWith(fn, x) {
|
|
|
1786
1874
|
)
|
|
1787
1875
|
}
|
|
1788
1876
|
|
|
1789
|
-
export { _arity, _includes, _indexOf, _lastIndexOf, addProp, addPropToObjects, all, allPass, any, anyPass, append, ascend, assertType, checkObjectWithSpec, compact, complement, concat, convertToType, 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 };
|
|
1877
|
+
export { _arity, _includes, _indexOf, _lastIndexOf, addProp, addPropToObjects, all, allPass, any, anyPass, append, ascend, assertType, checkObjectWithSpec, compact, complement, concat, convertToType, count, countBy, createCompareFunction, createObjectFromKeys, defaultTo, descend, drop, dropLast, dropLastWhile, dropWhile, duplicateBy, eqBy, eqProps, equals, equalsFn, evolve, excludes, filter, filterAsync, filterObject, find, findIndex, findLast, findLastIndex, findNth, flatMap, flatten, flattenObject, flattenObjectHelper, groupBy, groupByFallback, head, includes, indexBy, indexOf, init, innerJoin, interpolate, intersection, intersperse, join, last, lastIndexOf, map, mapAsync, mapFn, mapKeys, mapObject, mapObjectAsync, mapParallelAsync, mapPropObject, match, maxBy, merge, mergeTypes, minBy, modifyItemAtIndex, modifyPath, modifyProp, none, objOf, objectIncludes, omit, partition, partitionObject, path, pathSatisfies, permutations, pick, pipe, pipeAsync, pluck, prepend, prop, propEq, propOr, propSatisfies, range, reduce, reject, rejectObject, replace, replaceAll, 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 };
|