radashi 12.2.0-beta.313bfb4 → 12.2.0-beta.31d0c0a

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
@@ -1,151 +1,4 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all2) => {
7
- for (var name in all2)
8
- __defProp(target, name, { get: all2[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/mod.ts
21
- var mod_exports = {};
22
- __export(mod_exports, {
23
- AggregateError: () => AggregateErrorOrPolyfill,
24
- DefaultCloningStrategy: () => DefaultCloningStrategy,
25
- FastCloningStrategy: () => FastCloningStrategy,
26
- all: () => all,
27
- alphabetical: () => alphabetical,
28
- always: () => always,
29
- assign: () => assign,
30
- boil: () => boil,
31
- callable: () => callable,
32
- camel: () => camel,
33
- capitalize: () => capitalize,
34
- castArray: () => castArray,
35
- castArrayIfExists: () => castArrayIfExists,
36
- castComparator: () => castComparator,
37
- castMapping: () => castMapping,
38
- chain: () => chain,
39
- clamp: () => clamp,
40
- clone: () => clone,
41
- cloneDeep: () => cloneDeep,
42
- cluster: () => cluster,
43
- compose: () => compose,
44
- construct: () => construct,
45
- counting: () => counting,
46
- crush: () => crush,
47
- dash: () => dash,
48
- debounce: () => debounce,
49
- defer: () => defer,
50
- diff: () => diff,
51
- draw: () => draw,
52
- filterKey: () => filterKey,
53
- first: () => first,
54
- flat: () => flat,
55
- flip: () => flip,
56
- fork: () => fork,
57
- get: () => get,
58
- group: () => group,
59
- guard: () => guard,
60
- inRange: () => inRange,
61
- intersects: () => intersects,
62
- invert: () => invert,
63
- isArray: () => isArray,
64
- isBoolean: () => isBoolean,
65
- isDate: () => isDate,
66
- isEmpty: () => isEmpty,
67
- isEqual: () => isEqual,
68
- isFloat: () => isFloat,
69
- isFunction: () => isFunction,
70
- isInt: () => isInt,
71
- isIntString: () => isIntString,
72
- isIterable: () => isIterable,
73
- isMap: () => isMap,
74
- isNumber: () => isNumber,
75
- isObject: () => isObject,
76
- isPlainObject: () => isPlainObject,
77
- isPrimitive: () => isPrimitive,
78
- isPromise: () => isPromise,
79
- isRegExp: () => isRegExp,
80
- isSet: () => isSet,
81
- isString: () => isString,
82
- isSymbol: () => isSymbol,
83
- isTagged: () => isTagged,
84
- isWeakMap: () => isWeakMap,
85
- isWeakSet: () => isWeakSet,
86
- iterate: () => iterate,
87
- keys: () => keys,
88
- last: () => last,
89
- lerp: () => lerp,
90
- list: () => list,
91
- listify: () => listify,
92
- lowerize: () => lowerize,
93
- map: () => map,
94
- mapEntries: () => mapEntries,
95
- mapKeys: () => mapKeys,
96
- mapValues: () => mapValues,
97
- mapify: () => mapify,
98
- max: () => max,
99
- memo: () => memo,
100
- merge: () => merge,
101
- min: () => min,
102
- noop: () => noop,
103
- objectify: () => objectify,
104
- omit: () => omit,
105
- once: () => once,
106
- parallel: () => parallel,
107
- partial: () => partial,
108
- partob: () => partob,
109
- pascal: () => pascal,
110
- pick: () => pick,
111
- proxied: () => proxied,
112
- random: () => random,
113
- range: () => range,
114
- reduce: () => reduce,
115
- replace: () => replace,
116
- replaceOrAppend: () => replaceOrAppend,
117
- retry: () => retry,
118
- round: () => round,
119
- select: () => select,
120
- selectFirst: () => selectFirst,
121
- series: () => series,
122
- set: () => set,
123
- shake: () => shake,
124
- shift: () => shift,
125
- shuffle: () => shuffle,
126
- sift: () => sift,
127
- sleep: () => sleep,
128
- snake: () => snake,
129
- sort: () => sort,
130
- sum: () => sum,
131
- template: () => template,
132
- throttle: () => throttle,
133
- title: () => title,
134
- toFloat: () => toFloat,
135
- toInt: () => toInt,
136
- toggle: () => toggle,
137
- traverse: () => traverse,
138
- trim: () => trim,
139
- try: () => tryit,
140
- tryit: () => tryit,
141
- uid: () => uid,
142
- unique: () => unique,
143
- unzip: () => unzip,
144
- upperize: () => upperize,
145
- zip: () => zip,
146
- zipToObject: () => zipToObject
147
- });
148
- module.exports = __toCommonJS(mod_exports);
1
+ 'use strict';
149
2
 
150
3
  // src/array/alphabetical.ts
151
4
  function alphabetical(array, getter, direction = "asc") {
@@ -403,11 +256,11 @@ function selectFirst(array, mapper, condition) {
403
256
  // src/array/shift.ts
404
257
  function shift(arr, n) {
405
258
  if (arr.length === 0) {
406
- return arr;
259
+ return [...arr];
407
260
  }
408
261
  const shiftNumber = n % arr.length;
409
262
  if (shiftNumber === 0) {
410
- return arr;
263
+ return [...arr];
411
264
  }
412
265
  return [...arr.slice(-shiftNumber, arr.length), ...arr.slice(0, -shiftNumber)];
413
266
  }
@@ -435,7 +288,13 @@ function toggle(array, item, toKey, options) {
435
288
  if (item === void 0) {
436
289
  return [...array];
437
290
  }
438
- const matcher = toKey ? (x, idx) => toKey(x, idx) === toKey(item, idx) : (x) => x === item;
291
+ let matcher;
292
+ if (toKey) {
293
+ const key = toKey(item, -1);
294
+ matcher = (x, idx) => toKey(x, idx) === key;
295
+ } else {
296
+ matcher = (x) => x === item;
297
+ }
439
298
  const existing = array.find(matcher);
440
299
  if (existing !== void 0) {
441
300
  return array.filter((x, idx) => !matcher(x, idx));
@@ -496,7 +355,7 @@ function zipToObject(keys2, values) {
496
355
  }
497
356
 
498
357
  // src/async/AggregateError.ts
499
- var AggregateErrorOrPolyfill = (
358
+ var AggregateErrorOrPolyfill = /* @__PURE__ */ (() => (
500
359
  // eslint-disable-next-line compat/compat
501
360
  globalThis.AggregateError ?? class AggregateError extends Error {
502
361
  errors;
@@ -510,7 +369,7 @@ var AggregateErrorOrPolyfill = (
510
369
  this.errors = errors;
511
370
  }
512
371
  }
513
- );
372
+ ))();
514
373
 
515
374
  // src/async/all.ts
516
375
  async function all(promises) {
@@ -681,12 +540,22 @@ function tryit(func) {
681
540
  };
682
541
  }
683
542
 
543
+ // src/async/withResolvers.ts
544
+ function withResolvers() {
545
+ let resolve;
546
+ let reject;
547
+ const promise = new Promise((res, rej) => {
548
+ resolve = res;
549
+ reject = rej;
550
+ });
551
+ return { resolve, reject, promise };
552
+ }
553
+
684
554
  // src/curry/callable.ts
685
555
  function callable(obj, fn) {
686
556
  return new Proxy(Object.assign(fn.bind(null), obj), {
687
557
  get: (target, key) => target[key],
688
558
  set: (target, key, value) => {
689
- ;
690
559
  target[key] = value;
691
560
  return true;
692
561
  },
@@ -707,7 +576,7 @@ function compose(...funcs) {
707
576
  }
708
577
 
709
578
  // src/curry/debounce.ts
710
- function debounce({ delay }, func) {
579
+ function debounce({ delay, leading }, func) {
711
580
  let timer = void 0;
712
581
  let active = true;
713
582
  const debounced = (...args) => {
@@ -717,6 +586,10 @@ function debounce({ delay }, func) {
717
586
  active && func(...args);
718
587
  timer = void 0;
719
588
  }, delay);
589
+ if (leading) {
590
+ func(...args);
591
+ leading = false;
592
+ }
720
593
  } else {
721
594
  func(...args);
722
595
  }
@@ -762,20 +635,23 @@ function memo(func, options = {}) {
762
635
  }
763
636
 
764
637
  // src/curry/once.ts
765
- var onceSymbol = Symbol();
766
- var once = (fn) => {
767
- const onceFn = function(...args) {
768
- if (onceFn[onceSymbol] === onceSymbol) {
769
- onceFn[onceSymbol] = fn.apply(this, args);
770
- }
771
- return onceFn[onceSymbol];
638
+ var onceSymbol = /* @__PURE__ */ Symbol();
639
+ var once = /* @__PURE__ */ (() => {
640
+ const once2 = (fn) => {
641
+ const onceFn = function(...args) {
642
+ if (onceFn[onceSymbol] === onceSymbol) {
643
+ onceFn[onceSymbol] = fn.apply(this, args);
644
+ }
645
+ return onceFn[onceSymbol];
646
+ };
647
+ onceFn[onceSymbol] = onceSymbol;
648
+ return onceFn;
772
649
  };
773
- onceFn[onceSymbol] = onceSymbol;
774
- return onceFn;
775
- };
776
- once.reset = (fn) => {
777
- fn[onceSymbol] = onceSymbol;
778
- };
650
+ once2.reset = (fn) => {
651
+ fn[onceSymbol] = onceSymbol;
652
+ };
653
+ return once2;
654
+ })();
779
655
 
780
656
  // src/curry/partial.ts
781
657
  function partial(fn, ...args) {
@@ -798,22 +674,30 @@ function proxied(handler) {
798
674
  }
799
675
 
800
676
  // src/curry/throttle.ts
801
- function throttle({ interval }, func) {
802
- let ready = true;
803
- let timer = void 0;
677
+ function throttle({ interval, trailing }, func) {
678
+ let timer;
679
+ let lastCalled = 0;
680
+ let trailingArgs;
804
681
  const throttled = (...args) => {
805
- if (!ready) {
806
- return;
682
+ if (!isThrottled()) {
683
+ trigger(...args);
684
+ } else if (trailing) {
685
+ trailingArgs = args;
807
686
  }
808
- func(...args);
809
- ready = false;
810
- timer = setTimeout(() => {
811
- ready = true;
812
- timer = void 0;
813
- }, interval);
814
687
  };
815
- throttled.isThrottled = () => {
816
- return timer !== void 0;
688
+ const isThrottled = () => Date.now() - lastCalled < interval;
689
+ throttled.isThrottled = isThrottled;
690
+ const trigger = throttled.trigger = (...args) => {
691
+ func(...args);
692
+ lastCalled = Date.now();
693
+ if (trailing) {
694
+ trailingArgs = void 0;
695
+ clearTimeout(timer);
696
+ timer = setTimeout(
697
+ () => trailingArgs && trigger(...trailingArgs),
698
+ interval
699
+ );
700
+ }
817
701
  };
818
702
  return throttled;
819
703
  }
@@ -1275,7 +1159,6 @@ function traverse(root, visitor, options, outerContext) {
1275
1159
  let ok = true;
1276
1160
  const visit = (value, key) => {
1277
1161
  if (context.parent.constructor === Map) {
1278
- ;
1279
1162
  [key, value] = value;
1280
1163
  }
1281
1164
  context.path.push(key);
@@ -1498,6 +1381,54 @@ function pascal(str) {
1498
1381
  return parts.map((str2) => str2.charAt(0).toUpperCase() + str2.slice(1)).join("");
1499
1382
  }
1500
1383
 
1384
+ // src/string/similarity.ts
1385
+ function similarity(str1, str2) {
1386
+ if (str1 === str2) {
1387
+ return 0;
1388
+ }
1389
+ let start = 0;
1390
+ let end1 = str1.length - 1;
1391
+ let end2 = str2.length - 1;
1392
+ while (start <= end1 && start <= end2 && str1[start] === str2[start]) {
1393
+ start++;
1394
+ }
1395
+ while (end1 >= start && end2 >= start && str1[end1] === str2[end2]) {
1396
+ end1--;
1397
+ end2--;
1398
+ }
1399
+ const length1 = end1 - start + 1;
1400
+ const length2 = end2 - start + 1;
1401
+ if (length1 === 0) {
1402
+ return length2;
1403
+ }
1404
+ if (length2 === 0) {
1405
+ return length1;
1406
+ }
1407
+ const numRows = length1 + 1;
1408
+ const numColumns = length2 + 1;
1409
+ const distances = new Array(numRows * numColumns).fill(0);
1410
+ for (let x = 1; x < numColumns; x++) {
1411
+ distances[x] = x;
1412
+ }
1413
+ for (let y = 1; y < numRows; y++) {
1414
+ distances[y * numColumns] = y;
1415
+ }
1416
+ for (let x = 1; x < numColumns; x++) {
1417
+ for (let y = 1; y < numRows; y++) {
1418
+ const i = y * numColumns + x;
1419
+ distances[i] = Math.min(
1420
+ // Cost of a deletion.
1421
+ distances[i - numColumns] + 1,
1422
+ // Cost of an insertion.
1423
+ distances[i - 1] + 1,
1424
+ // Cost of a substitution.
1425
+ distances[i - numColumns - 1] + (str1[start + y - 1] === str2[start + x - 1] ? 0 : 1)
1426
+ );
1427
+ }
1428
+ }
1429
+ return distances[length1 * numColumns + length2];
1430
+ }
1431
+
1501
1432
  // src/string/snake.ts
1502
1433
  function snake(str, options) {
1503
1434
  const parts = (str == null ? void 0 : str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase())) ?? [];
@@ -1544,7 +1475,7 @@ function trim(str, charsToTrim = " ") {
1544
1475
  }
1545
1476
 
1546
1477
  // src/typed/isArray.ts
1547
- var isArray = Array.isArray;
1478
+ var isArray = /* @__PURE__ */ (() => Array.isArray)();
1548
1479
 
1549
1480
  // src/typed/isBoolean.ts
1550
1481
  function isBoolean(value) {
@@ -1629,7 +1560,7 @@ function isFunction(value) {
1629
1560
  }
1630
1561
 
1631
1562
  // src/typed/isInt.ts
1632
- var isInt = Number.isInteger;
1563
+ var isInt = /* @__PURE__ */ (() => Number.isInteger)();
1633
1564
 
1634
1565
  // src/typed/isIntString.ts
1635
1566
  function isIntString(value) {
@@ -1718,130 +1649,130 @@ function isWeakMap(value) {
1718
1649
  function isWeakSet(value) {
1719
1650
  return isTagged(value, "[object WeakSet]");
1720
1651
  }
1721
- // Annotate the CommonJS export names for ESM import in node:
1722
- 0 && (module.exports = {
1723
- AggregateError,
1724
- DefaultCloningStrategy,
1725
- FastCloningStrategy,
1726
- all,
1727
- alphabetical,
1728
- always,
1729
- assign,
1730
- boil,
1731
- callable,
1732
- camel,
1733
- capitalize,
1734
- castArray,
1735
- castArrayIfExists,
1736
- castComparator,
1737
- castMapping,
1738
- chain,
1739
- clamp,
1740
- clone,
1741
- cloneDeep,
1742
- cluster,
1743
- compose,
1744
- construct,
1745
- counting,
1746
- crush,
1747
- dash,
1748
- debounce,
1749
- defer,
1750
- diff,
1751
- draw,
1752
- filterKey,
1753
- first,
1754
- flat,
1755
- flip,
1756
- fork,
1757
- get,
1758
- group,
1759
- guard,
1760
- inRange,
1761
- intersects,
1762
- invert,
1763
- isArray,
1764
- isBoolean,
1765
- isDate,
1766
- isEmpty,
1767
- isEqual,
1768
- isFloat,
1769
- isFunction,
1770
- isInt,
1771
- isIntString,
1772
- isIterable,
1773
- isMap,
1774
- isNumber,
1775
- isObject,
1776
- isPlainObject,
1777
- isPrimitive,
1778
- isPromise,
1779
- isRegExp,
1780
- isSet,
1781
- isString,
1782
- isSymbol,
1783
- isTagged,
1784
- isWeakMap,
1785
- isWeakSet,
1786
- iterate,
1787
- keys,
1788
- last,
1789
- lerp,
1790
- list,
1791
- listify,
1792
- lowerize,
1793
- map,
1794
- mapEntries,
1795
- mapKeys,
1796
- mapValues,
1797
- mapify,
1798
- max,
1799
- memo,
1800
- merge,
1801
- min,
1802
- noop,
1803
- objectify,
1804
- omit,
1805
- once,
1806
- parallel,
1807
- partial,
1808
- partob,
1809
- pascal,
1810
- pick,
1811
- proxied,
1812
- random,
1813
- range,
1814
- reduce,
1815
- replace,
1816
- replaceOrAppend,
1817
- retry,
1818
- round,
1819
- select,
1820
- selectFirst,
1821
- series,
1822
- set,
1823
- shake,
1824
- shift,
1825
- shuffle,
1826
- sift,
1827
- sleep,
1828
- snake,
1829
- sort,
1830
- sum,
1831
- template,
1832
- throttle,
1833
- title,
1834
- toFloat,
1835
- toInt,
1836
- toggle,
1837
- traverse,
1838
- trim,
1839
- try: null,
1840
- tryit,
1841
- uid,
1842
- unique,
1843
- unzip,
1844
- upperize,
1845
- zip,
1846
- zipToObject
1847
- });
1652
+
1653
+ exports.AggregateError = AggregateErrorOrPolyfill;
1654
+ exports.DefaultCloningStrategy = DefaultCloningStrategy;
1655
+ exports.FastCloningStrategy = FastCloningStrategy;
1656
+ exports.all = all;
1657
+ exports.alphabetical = alphabetical;
1658
+ exports.always = always;
1659
+ exports.assign = assign;
1660
+ exports.boil = boil;
1661
+ exports.callable = callable;
1662
+ exports.camel = camel;
1663
+ exports.capitalize = capitalize;
1664
+ exports.castArray = castArray;
1665
+ exports.castArrayIfExists = castArrayIfExists;
1666
+ exports.castComparator = castComparator;
1667
+ exports.castMapping = castMapping;
1668
+ exports.chain = chain;
1669
+ exports.clamp = clamp;
1670
+ exports.clone = clone;
1671
+ exports.cloneDeep = cloneDeep;
1672
+ exports.cluster = cluster;
1673
+ exports.compose = compose;
1674
+ exports.construct = construct;
1675
+ exports.counting = counting;
1676
+ exports.crush = crush;
1677
+ exports.dash = dash;
1678
+ exports.debounce = debounce;
1679
+ exports.defer = defer;
1680
+ exports.diff = diff;
1681
+ exports.draw = draw;
1682
+ exports.filterKey = filterKey;
1683
+ exports.first = first;
1684
+ exports.flat = flat;
1685
+ exports.flip = flip;
1686
+ exports.fork = fork;
1687
+ exports.get = get;
1688
+ exports.group = group;
1689
+ exports.guard = guard;
1690
+ exports.inRange = inRange;
1691
+ exports.intersects = intersects;
1692
+ exports.invert = invert;
1693
+ exports.isArray = isArray;
1694
+ exports.isBoolean = isBoolean;
1695
+ exports.isDate = isDate;
1696
+ exports.isEmpty = isEmpty;
1697
+ exports.isEqual = isEqual;
1698
+ exports.isFloat = isFloat;
1699
+ exports.isFunction = isFunction;
1700
+ exports.isInt = isInt;
1701
+ exports.isIntString = isIntString;
1702
+ exports.isIterable = isIterable;
1703
+ exports.isMap = isMap;
1704
+ exports.isNumber = isNumber;
1705
+ exports.isObject = isObject;
1706
+ exports.isPlainObject = isPlainObject;
1707
+ exports.isPrimitive = isPrimitive;
1708
+ exports.isPromise = isPromise;
1709
+ exports.isRegExp = isRegExp;
1710
+ exports.isSet = isSet;
1711
+ exports.isString = isString;
1712
+ exports.isSymbol = isSymbol;
1713
+ exports.isTagged = isTagged;
1714
+ exports.isWeakMap = isWeakMap;
1715
+ exports.isWeakSet = isWeakSet;
1716
+ exports.iterate = iterate;
1717
+ exports.keys = keys;
1718
+ exports.last = last;
1719
+ exports.lerp = lerp;
1720
+ exports.list = list;
1721
+ exports.listify = listify;
1722
+ exports.lowerize = lowerize;
1723
+ exports.map = map;
1724
+ exports.mapEntries = mapEntries;
1725
+ exports.mapKeys = mapKeys;
1726
+ exports.mapValues = mapValues;
1727
+ exports.mapify = mapify;
1728
+ exports.max = max;
1729
+ exports.memo = memo;
1730
+ exports.merge = merge;
1731
+ exports.min = min;
1732
+ exports.noop = noop;
1733
+ exports.objectify = objectify;
1734
+ exports.omit = omit;
1735
+ exports.once = once;
1736
+ exports.parallel = parallel;
1737
+ exports.partial = partial;
1738
+ exports.partob = partob;
1739
+ exports.pascal = pascal;
1740
+ exports.pick = pick;
1741
+ exports.proxied = proxied;
1742
+ exports.random = random;
1743
+ exports.range = range;
1744
+ exports.reduce = reduce;
1745
+ exports.replace = replace;
1746
+ exports.replaceOrAppend = replaceOrAppend;
1747
+ exports.retry = retry;
1748
+ exports.round = round;
1749
+ exports.select = select;
1750
+ exports.selectFirst = selectFirst;
1751
+ exports.series = series;
1752
+ exports.set = set;
1753
+ exports.shake = shake;
1754
+ exports.shift = shift;
1755
+ exports.shuffle = shuffle;
1756
+ exports.sift = sift;
1757
+ exports.similarity = similarity;
1758
+ exports.sleep = sleep;
1759
+ exports.snake = snake;
1760
+ exports.sort = sort;
1761
+ exports.sum = sum;
1762
+ exports.template = template;
1763
+ exports.throttle = throttle;
1764
+ exports.title = title;
1765
+ exports.toFloat = toFloat;
1766
+ exports.toInt = toInt;
1767
+ exports.toggle = toggle;
1768
+ exports.traverse = traverse;
1769
+ exports.trim = trim;
1770
+ exports.try = tryit;
1771
+ exports.tryit = tryit;
1772
+ exports.uid = uid;
1773
+ exports.unique = unique;
1774
+ exports.unzip = unzip;
1775
+ exports.upperize = upperize;
1776
+ exports.withResolvers = withResolvers;
1777
+ exports.zip = zip;
1778
+ exports.zipToObject = zipToObject;