radashi 12.3.4 → 12.5.0-beta.6d5c035

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/radashi.cjs CHANGED
@@ -54,6 +54,20 @@ function cluster(array, size = 2) {
54
54
  return clusters;
55
55
  }
56
56
 
57
+ // src/array/concat.ts
58
+ function concat(...values) {
59
+ const result = [];
60
+ const append = (value) => value != null && result.push(value);
61
+ for (const value of values) {
62
+ if (Array.isArray(value)) {
63
+ value.forEach(append);
64
+ } else {
65
+ append(value);
66
+ }
67
+ }
68
+ return result;
69
+ }
70
+
57
71
  // src/array/counting.ts
58
72
  function counting(array, identity) {
59
73
  if (!array) {
@@ -163,8 +177,8 @@ function list(startOrLength, end, valueOrMapper, step) {
163
177
  // src/array/mapify.ts
164
178
  function mapify(array, getKey, getValue = (item) => item) {
165
179
  const map2 = /* @__PURE__ */ new Map();
166
- for (const item of array) {
167
- map2.set(getKey(item, map2.size), getValue(item, map2.size));
180
+ for (const [index, item] of array.entries()) {
181
+ map2.set(getKey(item, index), getValue(item, index));
168
182
  }
169
183
  return map2;
170
184
  }
@@ -204,6 +218,20 @@ function objectify(array, getKey, getValue = (item) => item) {
204
218
  );
205
219
  }
206
220
 
221
+ // src/array/pluck.ts
222
+ function pluck(array, mappings) {
223
+ return array.map(
224
+ mappings ? (item) => mappings.map(
225
+ (mapping) => isFunction(mapping) ? mapping(item) : item[mapping]
226
+ ) : Object.values
227
+ );
228
+ }
229
+
230
+ // src/array/remove.ts
231
+ function remove(array, predicate) {
232
+ return array.filter((item) => !predicate(item));
233
+ }
234
+
207
235
  // src/array/replace.ts
208
236
  function replace(array, newItem, match) {
209
237
  if (!array) {
@@ -525,17 +553,16 @@ async function reduce(array, reducer, initialValue) {
525
553
  if (!array) {
526
554
  array = [];
527
555
  }
528
- const indices = array.keys();
556
+ let index = 0;
529
557
  let acc = initialValue;
530
558
  if (acc === void 0 && arguments.length < 3) {
531
559
  if (!array.length) {
532
560
  throw new TypeError("Reduce of empty array with no initial value");
533
561
  }
534
- acc = array[0];
535
- indices.next();
562
+ acc = array[index++];
536
563
  }
537
- for (const index of indices) {
538
- acc = await reducer(acc, array[index], index);
564
+ while (index < array.length) {
565
+ acc = await reducer(acc, array[index], index++);
539
566
  }
540
567
  return acc;
541
568
  }
@@ -593,6 +620,19 @@ function timeout(ms, error) {
593
620
  );
594
621
  }
595
622
 
623
+ // src/async/toResult.ts
624
+ async function toResult(promise) {
625
+ try {
626
+ const result = await promise;
627
+ return [void 0, result];
628
+ } catch (error) {
629
+ if (isError(error)) {
630
+ return [error, void 0];
631
+ }
632
+ throw error;
633
+ }
634
+ }
635
+
596
636
  // src/async/tryit.ts
597
637
  function tryit(func) {
598
638
  return (...args) => {
@@ -702,6 +742,21 @@ function memo(func, options = {}) {
702
742
  return memoize({}, func, options.key ?? null, options.ttl ?? null);
703
743
  }
704
744
 
745
+ // src/curry/memoLastCall.ts
746
+ function memoLastCall(fn) {
747
+ let lastArgs = null;
748
+ let lastResult = null;
749
+ return (...args) => {
750
+ if (lastArgs && lastArgs.length === args.length && lastArgs.every((arg, i) => Object.is(arg, args[i]))) {
751
+ return lastResult;
752
+ }
753
+ const result = fn(...args);
754
+ lastArgs = args;
755
+ lastResult = result;
756
+ return result;
757
+ };
758
+ }
759
+
705
760
  // src/curry/once.ts
706
761
  var once = /* @__PURE__ */ (() => {
707
762
  const onceSymbol = /* @__PURE__ */ Symbol();
@@ -849,9 +904,6 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
849
904
  const final = end ?? startOrLength;
850
905
  for (let i = start; i <= final; i += step) {
851
906
  yield mapper(i);
852
- if (i + step > final) {
853
- break;
854
- }
855
907
  }
856
908
  }
857
909
 
@@ -1008,7 +1060,7 @@ function crush(value) {
1008
1060
 
1009
1061
  // src/object/filterKey.ts
1010
1062
  function filterKey(obj, key, filter) {
1011
- return Object.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
1063
+ return Object.prototype.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
1012
1064
  }
1013
1065
 
1014
1066
  // src/object/get.ts
@@ -1575,6 +1627,20 @@ function trim(str, charsToTrim = " ") {
1575
1627
  // src/typed/isArray.ts
1576
1628
  var isArray = /* @__PURE__ */ (() => Array.isArray)();
1577
1629
 
1630
+ // src/typed/isAsyncIterable.ts
1631
+ var asyncIteratorSymbol = (
1632
+ /* c8 ignore next */
1633
+ Symbol.asyncIterator || Symbol.for("Symbol.asyncIterator")
1634
+ );
1635
+ function isAsyncIterable(value) {
1636
+ return !!value && typeof value === "object" && typeof value[asyncIteratorSymbol] === "function";
1637
+ }
1638
+
1639
+ // src/typed/isBigInt.ts
1640
+ function isBigInt(value) {
1641
+ return typeof value === "bigint";
1642
+ }
1643
+
1578
1644
  // src/typed/isBoolean.ts
1579
1645
  function isBoolean(value) {
1580
1646
  return typeof value === "boolean";
@@ -1592,24 +1658,12 @@ function isDate(value) {
1592
1658
 
1593
1659
  // src/typed/isEmpty.ts
1594
1660
  function isEmpty(value) {
1595
- if (value === true || value === false) {
1596
- return true;
1597
- }
1598
- if (value === null || value === void 0) {
1599
- return true;
1600
- }
1601
- if (isNumber(value)) {
1602
- return value === 0;
1661
+ if (typeof value !== "object" || value === null) {
1662
+ return !value || value === true;
1603
1663
  }
1604
1664
  if (isDate(value)) {
1605
1665
  return Number.isNaN(value.getTime());
1606
1666
  }
1607
- if (isFunction(value)) {
1608
- return false;
1609
- }
1610
- if (isSymbol(value)) {
1611
- return false;
1612
- }
1613
1667
  const length = value.length;
1614
1668
  if (isNumber(length)) {
1615
1669
  return length === 0;
@@ -1806,6 +1860,7 @@ exports.clone = clone;
1806
1860
  exports.cloneDeep = cloneDeep;
1807
1861
  exports.cluster = cluster;
1808
1862
  exports.compose = compose;
1863
+ exports.concat = concat;
1809
1864
  exports.construct = construct;
1810
1865
  exports.counting = counting;
1811
1866
  exports.crush = crush;
@@ -1827,6 +1882,8 @@ exports.inRange = inRange;
1827
1882
  exports.intersects = intersects;
1828
1883
  exports.invert = invert;
1829
1884
  exports.isArray = isArray;
1885
+ exports.isAsyncIterable = isAsyncIterable;
1886
+ exports.isBigInt = isBigInt;
1830
1887
  exports.isBoolean = isBoolean;
1831
1888
  exports.isClass = isClass;
1832
1889
  exports.isDate = isDate;
@@ -1870,6 +1927,7 @@ exports.mapValues = mapValues;
1870
1927
  exports.mapify = mapify;
1871
1928
  exports.max = max;
1872
1929
  exports.memo = memo;
1930
+ exports.memoLastCall = memoLastCall;
1873
1931
  exports.merge = merge;
1874
1932
  exports.min = min;
1875
1933
  exports.noop = noop;
@@ -1881,10 +1939,12 @@ exports.partial = partial;
1881
1939
  exports.partob = partob;
1882
1940
  exports.pascal = pascal;
1883
1941
  exports.pick = pick;
1942
+ exports.pluck = pluck;
1884
1943
  exports.proxied = proxied;
1885
1944
  exports.random = random;
1886
1945
  exports.range = range;
1887
1946
  exports.reduce = reduce;
1947
+ exports.remove = remove;
1888
1948
  exports.replace = replace;
1889
1949
  exports.replaceOrAppend = replaceOrAppend;
1890
1950
  exports.retry = retry;
@@ -1908,6 +1968,7 @@ exports.timeout = timeout;
1908
1968
  exports.title = title;
1909
1969
  exports.toFloat = toFloat;
1910
1970
  exports.toInt = toInt;
1971
+ exports.toResult = toResult;
1911
1972
  exports.toggle = toggle;
1912
1973
  exports.traverse = traverse;
1913
1974
  exports.trim = trim;