radashi 12.3.4 → 12.4.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/radashi.cjs CHANGED
@@ -204,6 +204,11 @@ function objectify(array, getKey, getValue = (item) => item) {
204
204
  );
205
205
  }
206
206
 
207
+ // src/array/remove.ts
208
+ function remove(array, predicate) {
209
+ return array.filter((item) => !predicate(item));
210
+ }
211
+
207
212
  // src/array/replace.ts
208
213
  function replace(array, newItem, match) {
209
214
  if (!array) {
@@ -525,17 +530,16 @@ async function reduce(array, reducer, initialValue) {
525
530
  if (!array) {
526
531
  array = [];
527
532
  }
528
- const indices = array.keys();
533
+ let index = 0;
529
534
  let acc = initialValue;
530
535
  if (acc === void 0 && arguments.length < 3) {
531
536
  if (!array.length) {
532
537
  throw new TypeError("Reduce of empty array with no initial value");
533
538
  }
534
- acc = array[0];
535
- indices.next();
539
+ acc = array[index++];
536
540
  }
537
- for (const index of indices) {
538
- acc = await reducer(acc, array[index], index);
541
+ while (index < array.length) {
542
+ acc = await reducer(acc, array[index], index++);
539
543
  }
540
544
  return acc;
541
545
  }
@@ -593,6 +597,19 @@ function timeout(ms, error) {
593
597
  );
594
598
  }
595
599
 
600
+ // src/async/toResult.ts
601
+ async function toResult(promise) {
602
+ try {
603
+ const result = await promise;
604
+ return [void 0, result];
605
+ } catch (error) {
606
+ if (isError(error)) {
607
+ return [error, void 0];
608
+ }
609
+ throw error;
610
+ }
611
+ }
612
+
596
613
  // src/async/tryit.ts
597
614
  function tryit(func) {
598
615
  return (...args) => {
@@ -702,6 +719,21 @@ function memo(func, options = {}) {
702
719
  return memoize({}, func, options.key ?? null, options.ttl ?? null);
703
720
  }
704
721
 
722
+ // src/curry/memoLastCall.ts
723
+ function memoLastCall(fn) {
724
+ let lastArgs = null;
725
+ let lastResult = null;
726
+ return (...args) => {
727
+ if (lastArgs && lastArgs.length === args.length && lastArgs.every((arg, i) => Object.is(arg, args[i]))) {
728
+ return lastResult;
729
+ }
730
+ const result = fn(...args);
731
+ lastArgs = args;
732
+ lastResult = result;
733
+ return result;
734
+ };
735
+ }
736
+
705
737
  // src/curry/once.ts
706
738
  var once = /* @__PURE__ */ (() => {
707
739
  const onceSymbol = /* @__PURE__ */ Symbol();
@@ -1575,6 +1607,20 @@ function trim(str, charsToTrim = " ") {
1575
1607
  // src/typed/isArray.ts
1576
1608
  var isArray = /* @__PURE__ */ (() => Array.isArray)();
1577
1609
 
1610
+ // src/typed/isAsyncIterable.ts
1611
+ var asyncIteratorSymbol = (
1612
+ /* c8 ignore next */
1613
+ Symbol.asyncIterator || Symbol.for("Symbol.asyncIterator")
1614
+ );
1615
+ function isAsyncIterable(value) {
1616
+ return !!value && typeof value === "object" && typeof value[asyncIteratorSymbol] === "function";
1617
+ }
1618
+
1619
+ // src/typed/isBigInt.ts
1620
+ function isBigInt(value) {
1621
+ return typeof value === "bigint";
1622
+ }
1623
+
1578
1624
  // src/typed/isBoolean.ts
1579
1625
  function isBoolean(value) {
1580
1626
  return typeof value === "boolean";
@@ -1592,24 +1638,12 @@ function isDate(value) {
1592
1638
 
1593
1639
  // src/typed/isEmpty.ts
1594
1640
  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;
1641
+ if (typeof value !== "object" || value === null) {
1642
+ return !value || value === true;
1603
1643
  }
1604
1644
  if (isDate(value)) {
1605
1645
  return Number.isNaN(value.getTime());
1606
1646
  }
1607
- if (isFunction(value)) {
1608
- return false;
1609
- }
1610
- if (isSymbol(value)) {
1611
- return false;
1612
- }
1613
1647
  const length = value.length;
1614
1648
  if (isNumber(length)) {
1615
1649
  return length === 0;
@@ -1827,6 +1861,8 @@ exports.inRange = inRange;
1827
1861
  exports.intersects = intersects;
1828
1862
  exports.invert = invert;
1829
1863
  exports.isArray = isArray;
1864
+ exports.isAsyncIterable = isAsyncIterable;
1865
+ exports.isBigInt = isBigInt;
1830
1866
  exports.isBoolean = isBoolean;
1831
1867
  exports.isClass = isClass;
1832
1868
  exports.isDate = isDate;
@@ -1870,6 +1906,7 @@ exports.mapValues = mapValues;
1870
1906
  exports.mapify = mapify;
1871
1907
  exports.max = max;
1872
1908
  exports.memo = memo;
1909
+ exports.memoLastCall = memoLastCall;
1873
1910
  exports.merge = merge;
1874
1911
  exports.min = min;
1875
1912
  exports.noop = noop;
@@ -1885,6 +1922,7 @@ exports.proxied = proxied;
1885
1922
  exports.random = random;
1886
1923
  exports.range = range;
1887
1924
  exports.reduce = reduce;
1925
+ exports.remove = remove;
1888
1926
  exports.replace = replace;
1889
1927
  exports.replaceOrAppend = replaceOrAppend;
1890
1928
  exports.retry = retry;
@@ -1908,6 +1946,7 @@ exports.timeout = timeout;
1908
1946
  exports.title = title;
1909
1947
  exports.toFloat = toFloat;
1910
1948
  exports.toInt = toInt;
1949
+ exports.toResult = toResult;
1911
1950
  exports.toggle = toggle;
1912
1951
  exports.traverse = traverse;
1913
1952
  exports.trim = trim;