rambda 10.2.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/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 a of list) {
940
- willReturn.push(await fn(a, i++));
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);
@@ -1446,6 +1534,17 @@ function replace(pattern, replacer) {
1446
1534
  return str => str.replace(pattern, replacer)
1447
1535
  }
1448
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
+
1449
1548
  function shuffle(listInput) {
1450
1549
  const list = cloneList(listInput);
1451
1550
  let counter = list.length;
@@ -1676,45 +1775,6 @@ function union(x) {
1676
1775
  }
1677
1776
  }
1678
1777
 
1679
- class _Set {
1680
- constructor() {
1681
- this.set = new Set();
1682
- this.items = {};
1683
- }
1684
-
1685
- checkUniqueness(item) {
1686
- const type$1 = type(item);
1687
- if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
1688
- if (type$1 in this.items) {
1689
- return false
1690
- }
1691
- this.items[type$1] = true;
1692
-
1693
- return true
1694
- }
1695
- if (!['Object', 'Array'].includes(type$1)) {
1696
- const prevSize = this.set.size;
1697
- this.set.add(item);
1698
-
1699
- return this.set.size !== prevSize
1700
- }
1701
-
1702
- if (!(type$1 in this.items)) {
1703
- this.items[type$1] = [item];
1704
-
1705
- return true
1706
- }
1707
-
1708
- if (_indexOf(item, this.items[type$1]) === -1) {
1709
- this.items[type$1].push(item);
1710
-
1711
- return true
1712
- }
1713
-
1714
- return false
1715
- }
1716
- }
1717
-
1718
1778
  function uniq(list) {
1719
1779
  const set = new _Set();
1720
1780
  const willReturn = [];
@@ -1844,6 +1904,7 @@ exports.drop = drop;
1844
1904
  exports.dropLast = dropLast;
1845
1905
  exports.dropLastWhile = dropLastWhile;
1846
1906
  exports.dropWhile = dropWhile;
1907
+ exports.duplicateBy = duplicateBy;
1847
1908
  exports.eqBy = eqBy;
1848
1909
  exports.eqProps = eqProps;
1849
1910
  exports.equals = equals;
@@ -1851,6 +1912,7 @@ exports.equalsFn = equalsFn;
1851
1912
  exports.evolve = evolve;
1852
1913
  exports.excludes = excludes;
1853
1914
  exports.filter = filter;
1915
+ exports.filterAsync = filterAsync;
1854
1916
  exports.filterObject = filterObject;
1855
1917
  exports.find = find;
1856
1918
  exports.findIndex = findIndex;
@@ -1865,6 +1927,7 @@ exports.groupBy = groupBy;
1865
1927
  exports.groupByFallback = groupByFallback;
1866
1928
  exports.head = head;
1867
1929
  exports.includes = includes;
1930
+ exports.indexBy = indexBy;
1868
1931
  exports.indexOf = indexOf;
1869
1932
  exports.init = init;
1870
1933
  exports.innerJoin = innerJoin;
@@ -1881,6 +1944,7 @@ exports.mapKeys = mapKeys;
1881
1944
  exports.mapObject = mapObject;
1882
1945
  exports.mapObjectAsync = mapObjectAsync;
1883
1946
  exports.mapParallelAsync = mapParallelAsync;
1947
+ exports.mapPropObject = mapPropObject;
1884
1948
  exports.match = match;
1885
1949
  exports.maxBy = maxBy;
1886
1950
  exports.merge = merge;
@@ -1912,6 +1976,7 @@ exports.reduce = reduce;
1912
1976
  exports.reject = reject;
1913
1977
  exports.rejectObject = rejectObject;
1914
1978
  exports.replace = replace;
1979
+ exports.replaceAll = replaceAll;
1915
1980
  exports.shuffle = shuffle;
1916
1981
  exports.sort = sort;
1917
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 a of list) {
938
- willReturn.push(await fn(a, i++));
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);
@@ -1444,6 +1532,17 @@ function replace(pattern, replacer) {
1444
1532
  return str => str.replace(pattern, replacer)
1445
1533
  }
1446
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
+
1447
1546
  function shuffle(listInput) {
1448
1547
  const list = cloneList(listInput);
1449
1548
  let counter = list.length;
@@ -1674,45 +1773,6 @@ function union(x) {
1674
1773
  }
1675
1774
  }
1676
1775
 
1677
- class _Set {
1678
- constructor() {
1679
- this.set = new Set();
1680
- this.items = {};
1681
- }
1682
-
1683
- checkUniqueness(item) {
1684
- const type$1 = type(item);
1685
- if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
1686
- if (type$1 in this.items) {
1687
- return false
1688
- }
1689
- this.items[type$1] = true;
1690
-
1691
- return true
1692
- }
1693
- if (!['Object', 'Array'].includes(type$1)) {
1694
- const prevSize = this.set.size;
1695
- this.set.add(item);
1696
-
1697
- return this.set.size !== prevSize
1698
- }
1699
-
1700
- if (!(type$1 in this.items)) {
1701
- this.items[type$1] = [item];
1702
-
1703
- return true
1704
- }
1705
-
1706
- if (_indexOf(item, this.items[type$1]) === -1) {
1707
- this.items[type$1].push(item);
1708
-
1709
- return true
1710
- }
1711
-
1712
- return false
1713
- }
1714
- }
1715
-
1716
1776
  function uniq(list) {
1717
1777
  const set = new _Set();
1718
1778
  const willReturn = [];
@@ -1814,4 +1874,4 @@ function zipWith(fn, x) {
1814
1874
  )
1815
1875
  }
1816
1876
 
1817
- 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, 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, 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 };
@@ -539,6 +539,53 @@
539
539
  return b => equalsFn(a, b)
540
540
  }
541
541
 
542
+ class _Set {
543
+ constructor() {
544
+ this.set = new Set();
545
+ this.items = {};
546
+ }
547
+
548
+ checkUniqueness(item) {
549
+ const type$1 = type(item);
550
+ if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
551
+ if (type$1 in this.items) {
552
+ return false
553
+ }
554
+ this.items[type$1] = true;
555
+
556
+ return true
557
+ }
558
+ if (!['Object', 'Array'].includes(type$1)) {
559
+ const prevSize = this.set.size;
560
+ this.set.add(item);
561
+
562
+ return this.set.size !== prevSize
563
+ }
564
+
565
+ if (!(type$1 in this.items)) {
566
+ this.items[type$1] = [item];
567
+
568
+ return true
569
+ }
570
+
571
+ if (_indexOf(item, this.items[type$1]) === -1) {
572
+ this.items[type$1].push(item);
573
+
574
+ return true
575
+ }
576
+
577
+ return false
578
+ }
579
+ }
580
+
581
+ function duplicateBy(fn) {
582
+ return list => {
583
+ const set = new _Set();
584
+
585
+ return list.filter(item => !set.checkUniqueness(fn(item)))
586
+ }
587
+ }
588
+
542
589
  function eqBy(fn, a) {
543
590
  return b => equalsFn(fn(a), fn(b))
544
591
  }
@@ -590,6 +637,21 @@
590
637
  return iterable => !includes(valueToFind)(iterable)
591
638
  }
592
639
 
640
+ function filterAsync(predicate) {
641
+ return async list => {
642
+ const willReturn = [];
643
+ let index = 0;
644
+ for (const x of list) {
645
+ if (await predicate(x, index)) {
646
+ willReturn.push(list[index]);
647
+ }
648
+ index++;
649
+ }
650
+
651
+ return willReturn
652
+ }
653
+ }
654
+
593
655
  function filterObject(predicate) {
594
656
  return obj => {
595
657
  const willReturn = {};
@@ -802,6 +864,21 @@
802
864
  return listOrString[0]
803
865
  }
804
866
 
867
+ function indexBy(property){
868
+ return list => {
869
+ const toReturn = {};
870
+ for (let i = 0; i < list.length; i++){
871
+ const item = list[ i ];
872
+ const key = item[property];
873
+ if(key !== undefined){
874
+ toReturn[ key ] = item;
875
+ }
876
+ }
877
+
878
+ return toReturn
879
+ }
880
+ }
881
+
805
882
  function indexOf(valueToFind) {
806
883
  return list => _indexOf(valueToFind, list)
807
884
  }
@@ -940,8 +1017,8 @@
940
1017
  return async list => {
941
1018
  const willReturn = [];
942
1019
  let i = 0;
943
- for (const a of list) {
944
- willReturn.push(await fn(a, i++));
1020
+ for (const x of list) {
1021
+ willReturn.push(await fn(x, i++));
945
1022
  }
946
1023
 
947
1024
  return willReturn
@@ -975,6 +1052,17 @@
975
1052
  return async list => Promise.all(list.map((x, i) => fn(x, i)))
976
1053
  }
977
1054
 
1055
+ function mapPropObject(fn, prop) {
1056
+ return obj => {
1057
+ if (!Array.isArray(obj[prop])) return obj
1058
+
1059
+ return {
1060
+ ...obj,
1061
+ [prop]: obj[prop].map(fn)
1062
+ }
1063
+ }
1064
+ }
1065
+
978
1066
  function match(pattern) {
979
1067
  return input => {
980
1068
  const willReturn = input.match(pattern);
@@ -1450,6 +1538,17 @@
1450
1538
  return str => str.replace(pattern, replacer)
1451
1539
  }
1452
1540
 
1541
+ function replaceAll(patterns, replacer) {
1542
+ return input => {
1543
+ let text = input;
1544
+ patterns.forEach(singlePattern => {
1545
+ text = text.replace(singlePattern, replacer);
1546
+ });
1547
+
1548
+ return text
1549
+ }
1550
+ }
1551
+
1453
1552
  function shuffle(listInput) {
1454
1553
  const list = cloneList(listInput);
1455
1554
  let counter = list.length;
@@ -1680,45 +1779,6 @@
1680
1779
  }
1681
1780
  }
1682
1781
 
1683
- class _Set {
1684
- constructor() {
1685
- this.set = new Set();
1686
- this.items = {};
1687
- }
1688
-
1689
- checkUniqueness(item) {
1690
- const type$1 = type(item);
1691
- if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
1692
- if (type$1 in this.items) {
1693
- return false
1694
- }
1695
- this.items[type$1] = true;
1696
-
1697
- return true
1698
- }
1699
- if (!['Object', 'Array'].includes(type$1)) {
1700
- const prevSize = this.set.size;
1701
- this.set.add(item);
1702
-
1703
- return this.set.size !== prevSize
1704
- }
1705
-
1706
- if (!(type$1 in this.items)) {
1707
- this.items[type$1] = [item];
1708
-
1709
- return true
1710
- }
1711
-
1712
- if (_indexOf(item, this.items[type$1]) === -1) {
1713
- this.items[type$1].push(item);
1714
-
1715
- return true
1716
- }
1717
-
1718
- return false
1719
- }
1720
- }
1721
-
1722
1782
  function uniq(list) {
1723
1783
  const set = new _Set();
1724
1784
  const willReturn = [];
@@ -1848,6 +1908,7 @@
1848
1908
  exports.dropLast = dropLast;
1849
1909
  exports.dropLastWhile = dropLastWhile;
1850
1910
  exports.dropWhile = dropWhile;
1911
+ exports.duplicateBy = duplicateBy;
1851
1912
  exports.eqBy = eqBy;
1852
1913
  exports.eqProps = eqProps;
1853
1914
  exports.equals = equals;
@@ -1855,6 +1916,7 @@
1855
1916
  exports.evolve = evolve;
1856
1917
  exports.excludes = excludes;
1857
1918
  exports.filter = filter;
1919
+ exports.filterAsync = filterAsync;
1858
1920
  exports.filterObject = filterObject;
1859
1921
  exports.find = find;
1860
1922
  exports.findIndex = findIndex;
@@ -1869,6 +1931,7 @@
1869
1931
  exports.groupByFallback = groupByFallback;
1870
1932
  exports.head = head;
1871
1933
  exports.includes = includes;
1934
+ exports.indexBy = indexBy;
1872
1935
  exports.indexOf = indexOf;
1873
1936
  exports.init = init;
1874
1937
  exports.innerJoin = innerJoin;
@@ -1885,6 +1948,7 @@
1885
1948
  exports.mapObject = mapObject;
1886
1949
  exports.mapObjectAsync = mapObjectAsync;
1887
1950
  exports.mapParallelAsync = mapParallelAsync;
1951
+ exports.mapPropObject = mapPropObject;
1888
1952
  exports.match = match;
1889
1953
  exports.maxBy = maxBy;
1890
1954
  exports.merge = merge;
@@ -1916,6 +1980,7 @@
1916
1980
  exports.reject = reject;
1917
1981
  exports.rejectObject = rejectObject;
1918
1982
  exports.replace = replace;
1983
+ exports.replaceAll = replaceAll;
1919
1984
  exports.shuffle = shuffle;
1920
1985
  exports.sort = sort;
1921
1986
  exports.sortBy = sortBy;