radashi 12.6.2 → 12.7.1

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
@@ -71,13 +71,13 @@ function concat(...values) {
71
71
  }
72
72
 
73
73
  // src/array/counting.ts
74
- function counting(array, identity) {
74
+ function counting(array, identity2) {
75
75
  if (!array) {
76
76
  return {};
77
77
  }
78
78
  return array.reduce(
79
79
  (acc, item) => {
80
- const id = identity(item);
80
+ const id = identity2(item);
81
81
  acc[id] = (acc[id] ?? 0) + 1;
82
82
  return acc;
83
83
  },
@@ -86,7 +86,7 @@ function counting(array, identity) {
86
86
  }
87
87
 
88
88
  // src/array/diff.ts
89
- function diff(root, other, identity = (t) => t) {
89
+ function diff(root, other, identity2 = (t) => t) {
90
90
  if (!(root == null ? void 0 : root.length) && !(other == null ? void 0 : other.length)) {
91
91
  return [];
92
92
  }
@@ -98,12 +98,12 @@ function diff(root, other, identity = (t) => t) {
98
98
  }
99
99
  const bKeys = other.reduce(
100
100
  (acc, item) => {
101
- acc[identity(item)] = true;
101
+ acc[identity2(item)] = true;
102
102
  return acc;
103
103
  },
104
104
  {}
105
105
  );
106
- return root.filter((a) => !bKeys[identity(a)]);
106
+ return root.filter((a) => !bKeys[identity2(a)]);
107
107
  }
108
108
 
109
109
  // src/array/first.ts
@@ -144,17 +144,32 @@ function group(array, getGroupId) {
144
144
  }
145
145
 
146
146
  // src/array/intersects.ts
147
- function intersects(listA, listB, identity) {
147
+ function intersects(listA, listB, identity2) {
148
148
  if (!listA || !listB) {
149
149
  return false;
150
150
  }
151
- if (identity) {
152
- const known = new Set(listA.map(identity));
153
- return listB.some((item) => known.has(identity(item)));
151
+ if (identity2) {
152
+ const known = new Set(listA.map(identity2));
153
+ return listB.some((item) => known.has(identity2(item)));
154
154
  }
155
155
  return listB.some((item) => listA.includes(item));
156
156
  }
157
157
 
158
+ // src/array/isArrayEqual.ts
159
+ function isArrayEqual(array1, array2) {
160
+ if (array1 !== array2) {
161
+ if (array1.length !== array2.length) {
162
+ return false;
163
+ }
164
+ for (let i = 0; i < array1.length; i++) {
165
+ if (!Object.is(array1[i], array2[i])) {
166
+ return false;
167
+ }
168
+ }
169
+ }
170
+ return true;
171
+ }
172
+
158
173
  // src/array/iterate.ts
159
174
  function iterate(count, func, initValue) {
160
175
  let value = initValue;
@@ -210,8 +225,8 @@ function merge(prev, array, toKey) {
210
225
  // src/array/objectify.ts
211
226
  function objectify(array, getKey, getValue = (item) => item) {
212
227
  return array.reduce(
213
- (acc, item) => {
214
- acc[getKey(item)] = getValue(item);
228
+ (acc, item, i) => {
229
+ acc[getKey(item, i)] = getValue(item, i);
215
230
  return acc;
216
231
  },
217
232
  {}
@@ -319,7 +334,7 @@ function sift(array) {
319
334
  }
320
335
 
321
336
  // src/array/sort.ts
322
- function sort(array, getter, desc = false) {
337
+ function sort(array, getter = identity, desc = false) {
323
338
  if (!array) {
324
339
  return [];
325
340
  }
@@ -852,6 +867,11 @@ function castMapping(mapping) {
852
867
  return isFunction(mapping) ? mapping : mapping != null ? (input) => input[mapping] : (input) => input;
853
868
  }
854
869
 
870
+ // src/function/identity.ts
871
+ function identity(value) {
872
+ return value;
873
+ }
874
+
855
875
  // src/function/noop.ts
856
876
  function noop() {
857
877
  }
@@ -1099,6 +1119,25 @@ function get(value, path, defaultValue) {
1099
1119
  return current;
1100
1120
  }
1101
1121
 
1122
+ // src/object/getOrInsert.ts
1123
+ function getOrInsert(map2, key, value) {
1124
+ if (map2.has(key)) {
1125
+ return map2.get(key);
1126
+ }
1127
+ map2.set(key, value);
1128
+ return value;
1129
+ }
1130
+
1131
+ // src/object/getOrInsertComputed.ts
1132
+ function getOrInsertComputed(map2, key, compute) {
1133
+ if (map2.has(key)) {
1134
+ return map2.get(key);
1135
+ }
1136
+ const newValue = compute();
1137
+ map2.set(key, newValue);
1138
+ return newValue;
1139
+ }
1140
+
1102
1141
  // src/object/invert.ts
1103
1142
  function invert(obj) {
1104
1143
  if (!obj) {
@@ -1427,21 +1466,7 @@ var QuantityParser = class {
1427
1466
  };
1428
1467
 
1429
1468
  // src/oop/DurationParser.ts
1430
- var _DurationParser = class _DurationParser extends QuantityParser {
1431
- constructor(options) {
1432
- super({
1433
- units: {
1434
- ..._DurationParser.units,
1435
- ...options == null ? void 0 : options.units
1436
- },
1437
- short: {
1438
- ..._DurationParser.shortUnits,
1439
- ...options == null ? void 0 : options.short
1440
- }
1441
- });
1442
- }
1443
- };
1444
- _DurationParser.units = {
1469
+ var DURATION_UNITS = {
1445
1470
  week: 6048e5,
1446
1471
  day: 864e5,
1447
1472
  hour: 36e5,
@@ -1449,7 +1474,7 @@ _DurationParser.units = {
1449
1474
  second: 1e3,
1450
1475
  millisecond: 1
1451
1476
  };
1452
- _DurationParser.shortUnits = {
1477
+ var DURATION_SHORT_UNITS = {
1453
1478
  w: "week",
1454
1479
  d: "day",
1455
1480
  h: "hour",
@@ -1457,7 +1482,26 @@ _DurationParser.shortUnits = {
1457
1482
  s: "second",
1458
1483
  ms: "millisecond"
1459
1484
  };
1460
- var DurationParser = _DurationParser;
1485
+ var DurationParser = class _DurationParser extends QuantityParser {
1486
+ constructor(options) {
1487
+ super({
1488
+ units: {
1489
+ ..._DurationParser.units,
1490
+ ...options == null ? void 0 : options.units
1491
+ },
1492
+ short: {
1493
+ ..._DurationParser.shortUnits,
1494
+ ...options == null ? void 0 : options.short
1495
+ }
1496
+ });
1497
+ }
1498
+ static get units() {
1499
+ return DURATION_UNITS;
1500
+ }
1501
+ static get shortUnits() {
1502
+ return DURATION_SHORT_UNITS;
1503
+ }
1504
+ };
1461
1505
 
1462
1506
  // src/oop/Semaphore.ts
1463
1507
  var SemaphorePermit = class {
@@ -1567,6 +1611,11 @@ var TimeoutError = class extends Error {
1567
1611
  }
1568
1612
  };
1569
1613
 
1614
+ // src/random/absoluteJitter.ts
1615
+ function absoluteJitter(base, offset) {
1616
+ return base + offset * (2 * Math.random() - 1);
1617
+ }
1618
+
1570
1619
  // src/random/draw.ts
1571
1620
  function draw(array) {
1572
1621
  const max2 = array.length;
@@ -1577,6 +1626,11 @@ function draw(array) {
1577
1626
  return array[index];
1578
1627
  }
1579
1628
 
1629
+ // src/random/proportionalJitter.ts
1630
+ function proportionalJitter(base, factor) {
1631
+ return base * (1 - factor * (2 * Math.random() - 1));
1632
+ }
1633
+
1580
1634
  // src/random/random.ts
1581
1635
  function random(min2, max2) {
1582
1636
  return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
@@ -1973,6 +2027,19 @@ function isMap(value) {
1973
2027
  return isTagged(value, "[object Map]");
1974
2028
  }
1975
2029
 
2030
+ // src/typed/isMapEqual.ts
2031
+ function isMapEqual(x, y) {
2032
+ if (x.size !== y.size) {
2033
+ return false;
2034
+ }
2035
+ for (const [key, value] of x) {
2036
+ if (!isEqual(value, y.get(key))) {
2037
+ return false;
2038
+ }
2039
+ }
2040
+ return true;
2041
+ }
2042
+
1976
2043
  // src/typed/isNullish.ts
1977
2044
  function isNullish(value) {
1978
2045
  return value === null || value === void 0;
@@ -2037,6 +2104,19 @@ function isSet(value) {
2037
2104
  return isTagged(value, "[object Set]");
2038
2105
  }
2039
2106
 
2107
+ // src/typed/isSetEqual.ts
2108
+ function isSetEqual(x, y) {
2109
+ if (x.size !== y.size) {
2110
+ return false;
2111
+ }
2112
+ for (const item of x) {
2113
+ if (!y.has(item)) {
2114
+ return false;
2115
+ }
2116
+ }
2117
+ return true;
2118
+ }
2119
+
2040
2120
  // src/typed/isString.ts
2041
2121
  function isString(value) {
2042
2122
  return typeof value === "string";
@@ -2075,6 +2155,7 @@ exports.QuantityParser = QuantityParser;
2075
2155
  exports.Semaphore = Semaphore;
2076
2156
  exports.SemaphorePermit = SemaphorePermit;
2077
2157
  exports.TimeoutError = TimeoutError;
2158
+ exports.absoluteJitter = absoluteJitter;
2078
2159
  exports.all = all;
2079
2160
  exports.alphabetical = alphabetical;
2080
2161
  exports.always = always;
@@ -2112,12 +2193,16 @@ exports.flat = flat;
2112
2193
  exports.flip = flip;
2113
2194
  exports.fork = fork;
2114
2195
  exports.get = get;
2196
+ exports.getOrInsert = getOrInsert;
2197
+ exports.getOrInsertComputed = getOrInsertComputed;
2115
2198
  exports.group = group;
2116
2199
  exports.guard = guard;
2200
+ exports.identity = identity;
2117
2201
  exports.inRange = inRange;
2118
2202
  exports.intersects = intersects;
2119
2203
  exports.invert = invert;
2120
2204
  exports.isArray = isArray;
2205
+ exports.isArrayEqual = isArrayEqual;
2121
2206
  exports.isAsyncIterable = isAsyncIterable;
2122
2207
  exports.isBigInt = isBigInt;
2123
2208
  exports.isBoolean = isBoolean;
@@ -2133,6 +2218,7 @@ exports.isInt = isInt;
2133
2218
  exports.isIntString = isIntString;
2134
2219
  exports.isIterable = isIterable;
2135
2220
  exports.isMap = isMap;
2221
+ exports.isMapEqual = isMapEqual;
2136
2222
  exports.isNullish = isNullish;
2137
2223
  exports.isNumber = isNumber;
2138
2224
  exports.isObject = isObject;
@@ -2144,6 +2230,7 @@ exports.isResult = isResult;
2144
2230
  exports.isResultErr = isResultErr;
2145
2231
  exports.isResultOk = isResultOk;
2146
2232
  exports.isSet = isSet;
2233
+ exports.isSetEqual = isSetEqual;
2147
2234
  exports.isString = isString;
2148
2235
  exports.isSymbol = isSymbol;
2149
2236
  exports.isTagged = isTagged;
@@ -2180,6 +2267,7 @@ exports.pascal = pascal;
2180
2267
  exports.pick = pick;
2181
2268
  exports.pluck = pluck;
2182
2269
  exports.promiseChain = promiseChain;
2270
+ exports.proportionalJitter = proportionalJitter;
2183
2271
  exports.proxied = proxied;
2184
2272
  exports.queueByKey = queueByKey;
2185
2273
  exports.random = random;
@@ -241,6 +241,24 @@ declare function group<T, Key extends string | number | symbol>(array: readonly
241
241
  */
242
242
  declare function intersects<T, K>(listA: readonly T[], listB: readonly T[], identity?: (t: T) => K): boolean;
243
243
 
244
+ /**
245
+ * Checks if two arrays are equal in length and content using
246
+ * `Object.is` comparison.
247
+ *
248
+ * @see https://radashi.js.org/reference/array/isArrayEqual
249
+ * @example
250
+ * ```ts
251
+ * _.isArrayEqual([1, 2, 3], [1, 2, 3]) // => true
252
+ * _.isArrayEqual([1, 2, 3], [1, 2, 4]) // => false
253
+ * _.isArrayEqual([1, 2], [1, 2, 3]) // => false
254
+ * _.isArrayEqual([], []) // => true
255
+ * _.isArrayEqual([NaN], [NaN]) // => true (Object.is handles NaN)
256
+ * _.isArrayEqual([0], [-0]) // => false (Object.is handles +0 and -0)
257
+ * ```
258
+ * @version 12.7.0
259
+ */
260
+ declare function isArrayEqual<T>(array1: T[], array2: T[]): boolean;
261
+
244
262
  /**
245
263
  * Like a reduce but does not require an array. Only need a number and
246
264
  * will iterate the function as many times as specified.
@@ -353,7 +371,7 @@ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item:
353
371
  * ```
354
372
  * @version 12.1.0
355
373
  */
356
- declare function objectify<T, Key extends string | number | symbol, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Record<Key, Value>;
374
+ declare function objectify<T, Key extends string | number | symbol, Value = T>(array: readonly T[], getKey: (item: T, index: number) => Key, getValue?: (item: T, index: number) => Value): Record<Key, Value>;
357
375
 
358
376
  /**
359
377
  * Extracts values from an array of objects based on specified
@@ -539,7 +557,7 @@ declare function sift<T>(array: readonly (T | Falsy)[]): T[];
539
557
  * ```
540
558
  * @version 12.1.0
541
559
  */
542
- declare function sort<T>(array: readonly T[], getter: (item: T) => number, desc?: boolean): T[];
560
+ declare function sort<T>(array: readonly T[], getter?: (item: T) => number, desc?: boolean): T[];
543
561
 
544
562
  /**
545
563
  * Either adds or removes an item from an array, based on whether it
@@ -2221,6 +2239,21 @@ type MappedOutput<TMapping, TInput = any> = TMapping extends (data: TInput) => i
2221
2239
  */
2222
2240
  type MappingFunction<TMapping extends Mapping | null | undefined> = <TInput extends MappedInput<TMapping>>(input: TInput) => MappedOutput<TMapping, TInput>;
2223
2241
 
2242
+ /**
2243
+ * A function that returns the value passed to it.
2244
+ *
2245
+ * @see https://radashi.js.org/reference/function/identity
2246
+ * @example
2247
+ * ```ts
2248
+ * identity() // => undefined
2249
+ * identity(1) // => 1
2250
+ * identity("a") // => "a"
2251
+ * ```
2252
+ * @version 12.7.0
2253
+ */
2254
+ declare function identity(): undefined;
2255
+ declare function identity<T>(value: T): T;
2256
+
2224
2257
  /**
2225
2258
  * A callback that does nothing and returns undefined.
2226
2259
  *
@@ -2319,6 +2352,7 @@ declare function lerp(from: number, to: number, amount: number): number;
2319
2352
  */
2320
2353
  declare function max(array: readonly [number, ...number[]]): number;
2321
2354
  declare function max(array: readonly number[]): number | null;
2355
+ declare function max<T>(array: readonly [T, ...T[]], getter: (item: T) => number): T;
2322
2356
  declare function max<T>(array: readonly T[], getter: (item: T) => number): T | null;
2323
2357
 
2324
2358
  /**
@@ -2334,6 +2368,7 @@ declare function max<T>(array: readonly T[], getter: (item: T) => number): T | n
2334
2368
  */
2335
2369
  declare function min(array: readonly [number, ...number[]]): number;
2336
2370
  declare function min(array: readonly number[]): number | null;
2371
+ declare function min<T>(array: readonly [T, ...T[]], getter: (item: T) => number): T;
2337
2372
  declare function min<T>(array: readonly T[], getter: (item: T) => number): T | null;
2338
2373
 
2339
2374
  /**
@@ -2720,6 +2755,40 @@ declare function filterKey(obj: object, key: keyof any, filter: KeyFilter | null
2720
2755
  */
2721
2756
  declare function get<TDefault = unknown>(value: any, path: string, defaultValue?: TDefault): TDefault;
2722
2757
 
2758
+ /**
2759
+ * Returns a map entry or stores and returns the provided value when missing.
2760
+ *
2761
+ * @see https://radashi.js.org/reference/object/getOrInsert
2762
+ * @example
2763
+ * ```ts
2764
+ * const counts = new Map<string, number>()
2765
+ *
2766
+ * getOrInsert(counts, 'clicks', 1)
2767
+ * getOrInsert(counts, 'clicks', 5)
2768
+ * // => 1
2769
+ * ```
2770
+ * @version 12.7.0
2771
+ */
2772
+ declare function getOrInsert<K, V>(map: Map<K, V>, key: K, value: V): V;
2773
+ declare function getOrInsert<K extends object, V>(map: Map<K, V> | WeakMap<K, V>, key: K, value: V): V;
2774
+
2775
+ /**
2776
+ * Returns a map entry or stores the computed value when the key is missing.
2777
+ *
2778
+ * @see https://radashi.js.org/reference/object/getOrInsertComputed
2779
+ * @example
2780
+ * ```ts
2781
+ * const counts = new Map<string, number>()
2782
+ *
2783
+ * getOrInsertComputed(counts, 'clicks', () => 1)
2784
+ * getOrInsertComputed(counts, 'clicks', () => 5)
2785
+ * // => 1
2786
+ * ```
2787
+ * @version 12.7.0
2788
+ */
2789
+ declare function getOrInsertComputed<K, V>(map: Map<K, V>, key: K, factory: () => V): V;
2790
+ declare function getOrInsertComputed<K extends object, V>(map: Map<K, V> | WeakMap<K, V>, key: K, compute: () => V): V;
2791
+
2723
2792
  /**
2724
2793
  * Returns a new object whose keys are the values of the given object
2725
2794
  * and its values are the keys of the given object.
@@ -3098,6 +3167,22 @@ type DurationShortUnit = keyof typeof DurationParser.shortUnits;
3098
3167
  * A human-readable duration string.
3099
3168
  */
3100
3169
  type DurationString<TUnit extends string = never, TShortUnit extends string = never> = QuantityString<DurationUnit | TUnit, DurationShortUnit | TShortUnit>;
3170
+ declare const DURATION_UNITS: {
3171
+ readonly week: 604800000;
3172
+ readonly day: 86400000;
3173
+ readonly hour: 3600000;
3174
+ readonly minute: 60000;
3175
+ readonly second: 1000;
3176
+ readonly millisecond: 1;
3177
+ };
3178
+ declare const DURATION_SHORT_UNITS: {
3179
+ readonly w: "week";
3180
+ readonly d: "day";
3181
+ readonly h: "hour";
3182
+ readonly m: "minute";
3183
+ readonly s: "second";
3184
+ readonly ms: "millisecond";
3185
+ };
3101
3186
  /**
3102
3187
  * Parses a duration string into its numeric value.
3103
3188
  *
@@ -3110,22 +3195,8 @@ type DurationString<TUnit extends string = never, TShortUnit extends string = ne
3110
3195
  */
3111
3196
  declare class DurationParser<TUnit extends string = never, TShortUnit extends string = never> extends QuantityParser<DurationUnit | TUnit, DurationShortUnit | TShortUnit> {
3112
3197
  constructor(options?: DurationParser.Options<TUnit, TShortUnit>);
3113
- static units: {
3114
- readonly week: 604800000;
3115
- readonly day: 86400000;
3116
- readonly hour: 3600000;
3117
- readonly minute: 60000;
3118
- readonly second: 1000;
3119
- readonly millisecond: 1;
3120
- };
3121
- static shortUnits: {
3122
- readonly w: "week";
3123
- readonly d: "day";
3124
- readonly h: "hour";
3125
- readonly m: "minute";
3126
- readonly s: "second";
3127
- readonly ms: "millisecond";
3128
- };
3198
+ static get units(): typeof DURATION_UNITS;
3199
+ static get shortUnits(): typeof DURATION_SHORT_UNITS;
3129
3200
  }
3130
3201
  declare namespace DurationParser {
3131
3202
  /**
@@ -3212,6 +3283,20 @@ declare class TimeoutError extends Error {
3212
3283
  constructor(message?: string);
3213
3284
  }
3214
3285
 
3286
+ /**
3287
+ * Returns a value randomly jittered by an absolute offset.
3288
+ *
3289
+ * @see https://radashi.js.org/reference/random/absoluteJitter
3290
+ * @example
3291
+ * ```ts
3292
+ * const result = absoluteJitter(100, 5)
3293
+ * result >= 95 && result <= 105
3294
+ * // => true
3295
+ * ```
3296
+ * @version 12.7.0
3297
+ */
3298
+ declare function absoluteJitter(base: number, offset: number): number;
3299
+
3215
3300
  /**
3216
3301
  * “Draw” a random item from an array. The item is not removed from
3217
3302
  * the array. Returns `null` if the array is empty.
@@ -3230,6 +3315,20 @@ declare class TimeoutError extends Error {
3230
3315
  */
3231
3316
  declare function draw<const T extends readonly any[]>(array: T): T extends readonly [any, ...any[]] ? T[number] : T[number] | null;
3232
3317
 
3318
+ /**
3319
+ * Returns a value randomly jittered by a proportion of the base value.
3320
+ *
3321
+ * @see https://radashi.js.org/reference/random/proportionalJitter
3322
+ * @example
3323
+ * ```ts
3324
+ * const result = proportionalJitter(100, 0.25)
3325
+ * result >= 75 && result <= 125
3326
+ * // => true
3327
+ * ```
3328
+ * @version 12.7.0
3329
+ */
3330
+ declare function proportionalJitter(base: number, factor: number): number;
3331
+
3233
3332
  /**
3234
3333
  * Generates a random integer between min and max. Both min and max
3235
3334
  * are inclusive.
@@ -3812,6 +3911,15 @@ type ExtractMap<T> = T extends any ? [StrictExtract<T, ReadonlyMap<unknown, unkn
3812
3911
  ReadonlyMap<unknown, unknown>
3813
3912
  ] ? Extract<T, ReadonlyMap<unknown, unknown>> : [StrictExtract<T, Map<unknown, unknown>>] extends [Map<unknown, unknown>] ? Extract<T, Map<unknown, unknown>> : Map<unknown, unknown> extends T ? Map<unknown, unknown> : never : never;
3814
3913
 
3914
+ /**
3915
+ * Check if two maps are equal. Items are checked for deep equality
3916
+ * using the `isEqual` function.
3917
+ *
3918
+ * @see https://radashi.js.org/reference/typed/isMapEqual
3919
+ * @version 12.7.0
3920
+ */
3921
+ declare function isMapEqual(x: Map<any, any>, y: Map<any, any>): boolean;
3922
+
3815
3923
  /**
3816
3924
  * Return true if the given value is null or undefined.
3817
3925
  *
@@ -4009,6 +4117,16 @@ declare function isSet<Input>(value: Input): value is ExtractSet<Input>;
4009
4117
  */
4010
4118
  type ExtractSet<T> = T extends any ? [StrictExtract<T, ReadonlySet<unknown>>] extends [ReadonlySet<unknown>] ? Extract<T, ReadonlySet<unknown>> : [StrictExtract<T, Set<unknown>>] extends [Set<unknown>] ? Extract<T, Set<unknown>> : Set<unknown> extends T ? Set<unknown> : never : never;
4011
4119
 
4120
+ /**
4121
+ * Check if two sets are equal.
4122
+ *
4123
+ * Note: This does NOT check for deep equality of the items.
4124
+ *
4125
+ * @see https://radashi.js.org/reference/typed/isSetEqual
4126
+ * @version 12.7.0
4127
+ */
4128
+ declare function isSetEqual(x: Set<any>, y: Set<any>): boolean;
4129
+
4012
4130
  /**
4013
4131
  * Checks if the given value is a string.
4014
4132
  *
@@ -4097,4 +4215,4 @@ declare function isWeakMap<K extends WeakKey = WeakKey, V = unknown>(value: unkn
4097
4215
  */
4098
4216
  declare function isWeakSet<T extends WeakKey = WeakKey>(value: unknown): value is WeakSet<T>;
4099
4217
 
4100
- export { AggregateErrorOrPolyfill as AggregateError, Any, type Assign, type Awaitable, type BoxedPrimitive, type BuiltInType, type CastArray, type CastArrayIfExists, type Class, type CloningStrategy, type Comparable, type ComparableProperty, type Comparator, type ComparatorMapping, type CompatibleProperty, type Concat, type Crush, type CustomClass, type CustomClassRegistry, type DebounceFunction, type DebounceOptions, DefaultCloningStrategy, DurationParser, type DurationShortUnit, type DurationString, type DurationUnit, type Err, type ExtractArray, type ExtractClass, type ExtractMap, type ExtractNotAny, type ExtractSet, type Falsy, FastCloningStrategy, type FilteredKeys, type Flip, type GuardReturnType, type Intersect, type IsExactType, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MappedInput, type MappedOutput, type Mapping, type MappingFunction, type MemoOptions, type NoInfer$1 as NoInfer, type Ok, type OnceFunction, type OptionalKeys, type OptionalMapping, type ParallelOptions, type Primitive, type PromiseWithResolvers, QuantityParser, type QuantityString, type RequiredKeys, type Result, type ResultPromise, type RetryOptions, Semaphore, type SemaphoreAcquireOptions, SemaphorePermit, type Series, type Simplify, type StrictExtract, type SwitchAny, type SwitchNever, type ThrottledFunction, TimeoutError, type ToEmpty, type ToEmptyAble, type TraverseContext, type TraverseOptions, type TraverseVisitor, type TryitResult, type TypedArray, type UppercaseKeys, all, alphabetical, always, assert, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, concat, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, escapeHTML, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isAsyncIterable, isBigInt, isBoolean, isClass, isDangerousKey, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, parseDuration, parseQuantity, partial, partob, pascal, pick, pluck, promiseChain, proxied, queueByKey, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
4218
+ export { AggregateErrorOrPolyfill as AggregateError, Any, type Assign, type Awaitable, type BoxedPrimitive, type BuiltInType, type CastArray, type CastArrayIfExists, type Class, type CloningStrategy, type Comparable, type ComparableProperty, type Comparator, type ComparatorMapping, type CompatibleProperty, type Concat, type Crush, type CustomClass, type CustomClassRegistry, type DebounceFunction, type DebounceOptions, DefaultCloningStrategy, DurationParser, type DurationShortUnit, type DurationString, type DurationUnit, type Err, type ExtractArray, type ExtractClass, type ExtractMap, type ExtractNotAny, type ExtractSet, type Falsy, FastCloningStrategy, type FilteredKeys, type Flip, type GuardReturnType, type Intersect, type IsExactType, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MappedInput, type MappedOutput, type Mapping, type MappingFunction, type MemoOptions, type NoInfer$1 as NoInfer, type Ok, type OnceFunction, type OptionalKeys, type OptionalMapping, type ParallelOptions, type Primitive, type PromiseWithResolvers, QuantityParser, type QuantityString, type RequiredKeys, type Result, type ResultPromise, type RetryOptions, Semaphore, type SemaphoreAcquireOptions, SemaphorePermit, type Series, type Simplify, type StrictExtract, type SwitchAny, type SwitchNever, type ThrottledFunction, TimeoutError, type ToEmpty, type ToEmptyAble, type TraverseContext, type TraverseOptions, type TraverseVisitor, type TryitResult, type TypedArray, type UppercaseKeys, absoluteJitter, all, alphabetical, always, assert, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, concat, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, escapeHTML, filterKey, first, flat, flip, fork, get, getOrInsert, getOrInsertComputed, group, guard, identity, inRange, intersects, invert, isArray, isArrayEqual, isAsyncIterable, isBigInt, isBoolean, isClass, isDangerousKey, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isMapEqual, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isSetEqual, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, parseDuration, parseQuantity, partial, partob, pascal, pick, pluck, promiseChain, proportionalJitter, proxied, queueByKey, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
package/dist/radashi.d.ts CHANGED
@@ -241,6 +241,24 @@ declare function group<T, Key extends string | number | symbol>(array: readonly
241
241
  */
242
242
  declare function intersects<T, K>(listA: readonly T[], listB: readonly T[], identity?: (t: T) => K): boolean;
243
243
 
244
+ /**
245
+ * Checks if two arrays are equal in length and content using
246
+ * `Object.is` comparison.
247
+ *
248
+ * @see https://radashi.js.org/reference/array/isArrayEqual
249
+ * @example
250
+ * ```ts
251
+ * _.isArrayEqual([1, 2, 3], [1, 2, 3]) // => true
252
+ * _.isArrayEqual([1, 2, 3], [1, 2, 4]) // => false
253
+ * _.isArrayEqual([1, 2], [1, 2, 3]) // => false
254
+ * _.isArrayEqual([], []) // => true
255
+ * _.isArrayEqual([NaN], [NaN]) // => true (Object.is handles NaN)
256
+ * _.isArrayEqual([0], [-0]) // => false (Object.is handles +0 and -0)
257
+ * ```
258
+ * @version 12.7.0
259
+ */
260
+ declare function isArrayEqual<T>(array1: T[], array2: T[]): boolean;
261
+
244
262
  /**
245
263
  * Like a reduce but does not require an array. Only need a number and
246
264
  * will iterate the function as many times as specified.
@@ -353,7 +371,7 @@ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item:
353
371
  * ```
354
372
  * @version 12.1.0
355
373
  */
356
- declare function objectify<T, Key extends string | number | symbol, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Record<Key, Value>;
374
+ declare function objectify<T, Key extends string | number | symbol, Value = T>(array: readonly T[], getKey: (item: T, index: number) => Key, getValue?: (item: T, index: number) => Value): Record<Key, Value>;
357
375
 
358
376
  /**
359
377
  * Extracts values from an array of objects based on specified
@@ -539,7 +557,7 @@ declare function sift<T>(array: readonly (T | Falsy)[]): T[];
539
557
  * ```
540
558
  * @version 12.1.0
541
559
  */
542
- declare function sort<T>(array: readonly T[], getter: (item: T) => number, desc?: boolean): T[];
560
+ declare function sort<T>(array: readonly T[], getter?: (item: T) => number, desc?: boolean): T[];
543
561
 
544
562
  /**
545
563
  * Either adds or removes an item from an array, based on whether it
@@ -2221,6 +2239,21 @@ type MappedOutput<TMapping, TInput = any> = TMapping extends (data: TInput) => i
2221
2239
  */
2222
2240
  type MappingFunction<TMapping extends Mapping | null | undefined> = <TInput extends MappedInput<TMapping>>(input: TInput) => MappedOutput<TMapping, TInput>;
2223
2241
 
2242
+ /**
2243
+ * A function that returns the value passed to it.
2244
+ *
2245
+ * @see https://radashi.js.org/reference/function/identity
2246
+ * @example
2247
+ * ```ts
2248
+ * identity() // => undefined
2249
+ * identity(1) // => 1
2250
+ * identity("a") // => "a"
2251
+ * ```
2252
+ * @version 12.7.0
2253
+ */
2254
+ declare function identity(): undefined;
2255
+ declare function identity<T>(value: T): T;
2256
+
2224
2257
  /**
2225
2258
  * A callback that does nothing and returns undefined.
2226
2259
  *
@@ -2319,6 +2352,7 @@ declare function lerp(from: number, to: number, amount: number): number;
2319
2352
  */
2320
2353
  declare function max(array: readonly [number, ...number[]]): number;
2321
2354
  declare function max(array: readonly number[]): number | null;
2355
+ declare function max<T>(array: readonly [T, ...T[]], getter: (item: T) => number): T;
2322
2356
  declare function max<T>(array: readonly T[], getter: (item: T) => number): T | null;
2323
2357
 
2324
2358
  /**
@@ -2334,6 +2368,7 @@ declare function max<T>(array: readonly T[], getter: (item: T) => number): T | n
2334
2368
  */
2335
2369
  declare function min(array: readonly [number, ...number[]]): number;
2336
2370
  declare function min(array: readonly number[]): number | null;
2371
+ declare function min<T>(array: readonly [T, ...T[]], getter: (item: T) => number): T;
2337
2372
  declare function min<T>(array: readonly T[], getter: (item: T) => number): T | null;
2338
2373
 
2339
2374
  /**
@@ -2720,6 +2755,40 @@ declare function filterKey(obj: object, key: keyof any, filter: KeyFilter | null
2720
2755
  */
2721
2756
  declare function get<TDefault = unknown>(value: any, path: string, defaultValue?: TDefault): TDefault;
2722
2757
 
2758
+ /**
2759
+ * Returns a map entry or stores and returns the provided value when missing.
2760
+ *
2761
+ * @see https://radashi.js.org/reference/object/getOrInsert
2762
+ * @example
2763
+ * ```ts
2764
+ * const counts = new Map<string, number>()
2765
+ *
2766
+ * getOrInsert(counts, 'clicks', 1)
2767
+ * getOrInsert(counts, 'clicks', 5)
2768
+ * // => 1
2769
+ * ```
2770
+ * @version 12.7.0
2771
+ */
2772
+ declare function getOrInsert<K, V>(map: Map<K, V>, key: K, value: V): V;
2773
+ declare function getOrInsert<K extends object, V>(map: Map<K, V> | WeakMap<K, V>, key: K, value: V): V;
2774
+
2775
+ /**
2776
+ * Returns a map entry or stores the computed value when the key is missing.
2777
+ *
2778
+ * @see https://radashi.js.org/reference/object/getOrInsertComputed
2779
+ * @example
2780
+ * ```ts
2781
+ * const counts = new Map<string, number>()
2782
+ *
2783
+ * getOrInsertComputed(counts, 'clicks', () => 1)
2784
+ * getOrInsertComputed(counts, 'clicks', () => 5)
2785
+ * // => 1
2786
+ * ```
2787
+ * @version 12.7.0
2788
+ */
2789
+ declare function getOrInsertComputed<K, V>(map: Map<K, V>, key: K, factory: () => V): V;
2790
+ declare function getOrInsertComputed<K extends object, V>(map: Map<K, V> | WeakMap<K, V>, key: K, compute: () => V): V;
2791
+
2723
2792
  /**
2724
2793
  * Returns a new object whose keys are the values of the given object
2725
2794
  * and its values are the keys of the given object.
@@ -3098,6 +3167,22 @@ type DurationShortUnit = keyof typeof DurationParser.shortUnits;
3098
3167
  * A human-readable duration string.
3099
3168
  */
3100
3169
  type DurationString<TUnit extends string = never, TShortUnit extends string = never> = QuantityString<DurationUnit | TUnit, DurationShortUnit | TShortUnit>;
3170
+ declare const DURATION_UNITS: {
3171
+ readonly week: 604800000;
3172
+ readonly day: 86400000;
3173
+ readonly hour: 3600000;
3174
+ readonly minute: 60000;
3175
+ readonly second: 1000;
3176
+ readonly millisecond: 1;
3177
+ };
3178
+ declare const DURATION_SHORT_UNITS: {
3179
+ readonly w: "week";
3180
+ readonly d: "day";
3181
+ readonly h: "hour";
3182
+ readonly m: "minute";
3183
+ readonly s: "second";
3184
+ readonly ms: "millisecond";
3185
+ };
3101
3186
  /**
3102
3187
  * Parses a duration string into its numeric value.
3103
3188
  *
@@ -3110,22 +3195,8 @@ type DurationString<TUnit extends string = never, TShortUnit extends string = ne
3110
3195
  */
3111
3196
  declare class DurationParser<TUnit extends string = never, TShortUnit extends string = never> extends QuantityParser<DurationUnit | TUnit, DurationShortUnit | TShortUnit> {
3112
3197
  constructor(options?: DurationParser.Options<TUnit, TShortUnit>);
3113
- static units: {
3114
- readonly week: 604800000;
3115
- readonly day: 86400000;
3116
- readonly hour: 3600000;
3117
- readonly minute: 60000;
3118
- readonly second: 1000;
3119
- readonly millisecond: 1;
3120
- };
3121
- static shortUnits: {
3122
- readonly w: "week";
3123
- readonly d: "day";
3124
- readonly h: "hour";
3125
- readonly m: "minute";
3126
- readonly s: "second";
3127
- readonly ms: "millisecond";
3128
- };
3198
+ static get units(): typeof DURATION_UNITS;
3199
+ static get shortUnits(): typeof DURATION_SHORT_UNITS;
3129
3200
  }
3130
3201
  declare namespace DurationParser {
3131
3202
  /**
@@ -3212,6 +3283,20 @@ declare class TimeoutError extends Error {
3212
3283
  constructor(message?: string);
3213
3284
  }
3214
3285
 
3286
+ /**
3287
+ * Returns a value randomly jittered by an absolute offset.
3288
+ *
3289
+ * @see https://radashi.js.org/reference/random/absoluteJitter
3290
+ * @example
3291
+ * ```ts
3292
+ * const result = absoluteJitter(100, 5)
3293
+ * result >= 95 && result <= 105
3294
+ * // => true
3295
+ * ```
3296
+ * @version 12.7.0
3297
+ */
3298
+ declare function absoluteJitter(base: number, offset: number): number;
3299
+
3215
3300
  /**
3216
3301
  * “Draw” a random item from an array. The item is not removed from
3217
3302
  * the array. Returns `null` if the array is empty.
@@ -3230,6 +3315,20 @@ declare class TimeoutError extends Error {
3230
3315
  */
3231
3316
  declare function draw<const T extends readonly any[]>(array: T): T extends readonly [any, ...any[]] ? T[number] : T[number] | null;
3232
3317
 
3318
+ /**
3319
+ * Returns a value randomly jittered by a proportion of the base value.
3320
+ *
3321
+ * @see https://radashi.js.org/reference/random/proportionalJitter
3322
+ * @example
3323
+ * ```ts
3324
+ * const result = proportionalJitter(100, 0.25)
3325
+ * result >= 75 && result <= 125
3326
+ * // => true
3327
+ * ```
3328
+ * @version 12.7.0
3329
+ */
3330
+ declare function proportionalJitter(base: number, factor: number): number;
3331
+
3233
3332
  /**
3234
3333
  * Generates a random integer between min and max. Both min and max
3235
3334
  * are inclusive.
@@ -3812,6 +3911,15 @@ type ExtractMap<T> = T extends any ? [StrictExtract<T, ReadonlyMap<unknown, unkn
3812
3911
  ReadonlyMap<unknown, unknown>
3813
3912
  ] ? Extract<T, ReadonlyMap<unknown, unknown>> : [StrictExtract<T, Map<unknown, unknown>>] extends [Map<unknown, unknown>] ? Extract<T, Map<unknown, unknown>> : Map<unknown, unknown> extends T ? Map<unknown, unknown> : never : never;
3814
3913
 
3914
+ /**
3915
+ * Check if two maps are equal. Items are checked for deep equality
3916
+ * using the `isEqual` function.
3917
+ *
3918
+ * @see https://radashi.js.org/reference/typed/isMapEqual
3919
+ * @version 12.7.0
3920
+ */
3921
+ declare function isMapEqual(x: Map<any, any>, y: Map<any, any>): boolean;
3922
+
3815
3923
  /**
3816
3924
  * Return true if the given value is null or undefined.
3817
3925
  *
@@ -4009,6 +4117,16 @@ declare function isSet<Input>(value: Input): value is ExtractSet<Input>;
4009
4117
  */
4010
4118
  type ExtractSet<T> = T extends any ? [StrictExtract<T, ReadonlySet<unknown>>] extends [ReadonlySet<unknown>] ? Extract<T, ReadonlySet<unknown>> : [StrictExtract<T, Set<unknown>>] extends [Set<unknown>] ? Extract<T, Set<unknown>> : Set<unknown> extends T ? Set<unknown> : never : never;
4011
4119
 
4120
+ /**
4121
+ * Check if two sets are equal.
4122
+ *
4123
+ * Note: This does NOT check for deep equality of the items.
4124
+ *
4125
+ * @see https://radashi.js.org/reference/typed/isSetEqual
4126
+ * @version 12.7.0
4127
+ */
4128
+ declare function isSetEqual(x: Set<any>, y: Set<any>): boolean;
4129
+
4012
4130
  /**
4013
4131
  * Checks if the given value is a string.
4014
4132
  *
@@ -4097,4 +4215,4 @@ declare function isWeakMap<K extends WeakKey = WeakKey, V = unknown>(value: unkn
4097
4215
  */
4098
4216
  declare function isWeakSet<T extends WeakKey = WeakKey>(value: unknown): value is WeakSet<T>;
4099
4217
 
4100
- export { AggregateErrorOrPolyfill as AggregateError, Any, type Assign, type Awaitable, type BoxedPrimitive, type BuiltInType, type CastArray, type CastArrayIfExists, type Class, type CloningStrategy, type Comparable, type ComparableProperty, type Comparator, type ComparatorMapping, type CompatibleProperty, type Concat, type Crush, type CustomClass, type CustomClassRegistry, type DebounceFunction, type DebounceOptions, DefaultCloningStrategy, DurationParser, type DurationShortUnit, type DurationString, type DurationUnit, type Err, type ExtractArray, type ExtractClass, type ExtractMap, type ExtractNotAny, type ExtractSet, type Falsy, FastCloningStrategy, type FilteredKeys, type Flip, type GuardReturnType, type Intersect, type IsExactType, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MappedInput, type MappedOutput, type Mapping, type MappingFunction, type MemoOptions, type NoInfer$1 as NoInfer, type Ok, type OnceFunction, type OptionalKeys, type OptionalMapping, type ParallelOptions, type Primitive, type PromiseWithResolvers, QuantityParser, type QuantityString, type RequiredKeys, type Result, type ResultPromise, type RetryOptions, Semaphore, type SemaphoreAcquireOptions, SemaphorePermit, type Series, type Simplify, type StrictExtract, type SwitchAny, type SwitchNever, type ThrottledFunction, TimeoutError, type ToEmpty, type ToEmptyAble, type TraverseContext, type TraverseOptions, type TraverseVisitor, type TryitResult, type TypedArray, type UppercaseKeys, all, alphabetical, always, assert, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, concat, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, escapeHTML, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isAsyncIterable, isBigInt, isBoolean, isClass, isDangerousKey, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, parseDuration, parseQuantity, partial, partob, pascal, pick, pluck, promiseChain, proxied, queueByKey, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
4218
+ export { AggregateErrorOrPolyfill as AggregateError, Any, type Assign, type Awaitable, type BoxedPrimitive, type BuiltInType, type CastArray, type CastArrayIfExists, type Class, type CloningStrategy, type Comparable, type ComparableProperty, type Comparator, type ComparatorMapping, type CompatibleProperty, type Concat, type Crush, type CustomClass, type CustomClassRegistry, type DebounceFunction, type DebounceOptions, DefaultCloningStrategy, DurationParser, type DurationShortUnit, type DurationString, type DurationUnit, type Err, type ExtractArray, type ExtractClass, type ExtractMap, type ExtractNotAny, type ExtractSet, type Falsy, FastCloningStrategy, type FilteredKeys, type Flip, type GuardReturnType, type Intersect, type IsExactType, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MappedInput, type MappedOutput, type Mapping, type MappingFunction, type MemoOptions, type NoInfer$1 as NoInfer, type Ok, type OnceFunction, type OptionalKeys, type OptionalMapping, type ParallelOptions, type Primitive, type PromiseWithResolvers, QuantityParser, type QuantityString, type RequiredKeys, type Result, type ResultPromise, type RetryOptions, Semaphore, type SemaphoreAcquireOptions, SemaphorePermit, type Series, type Simplify, type StrictExtract, type SwitchAny, type SwitchNever, type ThrottledFunction, TimeoutError, type ToEmpty, type ToEmptyAble, type TraverseContext, type TraverseOptions, type TraverseVisitor, type TryitResult, type TypedArray, type UppercaseKeys, absoluteJitter, all, alphabetical, always, assert, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, concat, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, escapeHTML, filterKey, first, flat, flip, fork, get, getOrInsert, getOrInsertComputed, group, guard, identity, inRange, intersects, invert, isArray, isArrayEqual, isAsyncIterable, isBigInt, isBoolean, isClass, isDangerousKey, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isMapEqual, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isSetEqual, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, parseDuration, parseQuantity, partial, partob, pascal, pick, pluck, promiseChain, proportionalJitter, proxied, queueByKey, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
package/dist/radashi.js CHANGED
@@ -69,13 +69,13 @@ function concat(...values) {
69
69
  }
70
70
 
71
71
  // src/array/counting.ts
72
- function counting(array, identity) {
72
+ function counting(array, identity2) {
73
73
  if (!array) {
74
74
  return {};
75
75
  }
76
76
  return array.reduce(
77
77
  (acc, item) => {
78
- const id = identity(item);
78
+ const id = identity2(item);
79
79
  acc[id] = (acc[id] ?? 0) + 1;
80
80
  return acc;
81
81
  },
@@ -84,7 +84,7 @@ function counting(array, identity) {
84
84
  }
85
85
 
86
86
  // src/array/diff.ts
87
- function diff(root, other, identity = (t) => t) {
87
+ function diff(root, other, identity2 = (t) => t) {
88
88
  if (!(root == null ? void 0 : root.length) && !(other == null ? void 0 : other.length)) {
89
89
  return [];
90
90
  }
@@ -96,12 +96,12 @@ function diff(root, other, identity = (t) => t) {
96
96
  }
97
97
  const bKeys = other.reduce(
98
98
  (acc, item) => {
99
- acc[identity(item)] = true;
99
+ acc[identity2(item)] = true;
100
100
  return acc;
101
101
  },
102
102
  {}
103
103
  );
104
- return root.filter((a) => !bKeys[identity(a)]);
104
+ return root.filter((a) => !bKeys[identity2(a)]);
105
105
  }
106
106
 
107
107
  // src/array/first.ts
@@ -142,17 +142,32 @@ function group(array, getGroupId) {
142
142
  }
143
143
 
144
144
  // src/array/intersects.ts
145
- function intersects(listA, listB, identity) {
145
+ function intersects(listA, listB, identity2) {
146
146
  if (!listA || !listB) {
147
147
  return false;
148
148
  }
149
- if (identity) {
150
- const known = new Set(listA.map(identity));
151
- return listB.some((item) => known.has(identity(item)));
149
+ if (identity2) {
150
+ const known = new Set(listA.map(identity2));
151
+ return listB.some((item) => known.has(identity2(item)));
152
152
  }
153
153
  return listB.some((item) => listA.includes(item));
154
154
  }
155
155
 
156
+ // src/array/isArrayEqual.ts
157
+ function isArrayEqual(array1, array2) {
158
+ if (array1 !== array2) {
159
+ if (array1.length !== array2.length) {
160
+ return false;
161
+ }
162
+ for (let i = 0; i < array1.length; i++) {
163
+ if (!Object.is(array1[i], array2[i])) {
164
+ return false;
165
+ }
166
+ }
167
+ }
168
+ return true;
169
+ }
170
+
156
171
  // src/array/iterate.ts
157
172
  function iterate(count, func, initValue) {
158
173
  let value = initValue;
@@ -208,8 +223,8 @@ function merge(prev, array, toKey) {
208
223
  // src/array/objectify.ts
209
224
  function objectify(array, getKey, getValue = (item) => item) {
210
225
  return array.reduce(
211
- (acc, item) => {
212
- acc[getKey(item)] = getValue(item);
226
+ (acc, item, i) => {
227
+ acc[getKey(item, i)] = getValue(item, i);
213
228
  return acc;
214
229
  },
215
230
  {}
@@ -317,7 +332,7 @@ function sift(array) {
317
332
  }
318
333
 
319
334
  // src/array/sort.ts
320
- function sort(array, getter, desc = false) {
335
+ function sort(array, getter = identity, desc = false) {
321
336
  if (!array) {
322
337
  return [];
323
338
  }
@@ -850,6 +865,11 @@ function castMapping(mapping) {
850
865
  return isFunction(mapping) ? mapping : mapping != null ? (input) => input[mapping] : (input) => input;
851
866
  }
852
867
 
868
+ // src/function/identity.ts
869
+ function identity(value) {
870
+ return value;
871
+ }
872
+
853
873
  // src/function/noop.ts
854
874
  function noop() {
855
875
  }
@@ -1097,6 +1117,25 @@ function get(value, path, defaultValue) {
1097
1117
  return current;
1098
1118
  }
1099
1119
 
1120
+ // src/object/getOrInsert.ts
1121
+ function getOrInsert(map2, key, value) {
1122
+ if (map2.has(key)) {
1123
+ return map2.get(key);
1124
+ }
1125
+ map2.set(key, value);
1126
+ return value;
1127
+ }
1128
+
1129
+ // src/object/getOrInsertComputed.ts
1130
+ function getOrInsertComputed(map2, key, compute) {
1131
+ if (map2.has(key)) {
1132
+ return map2.get(key);
1133
+ }
1134
+ const newValue = compute();
1135
+ map2.set(key, newValue);
1136
+ return newValue;
1137
+ }
1138
+
1100
1139
  // src/object/invert.ts
1101
1140
  function invert(obj) {
1102
1141
  if (!obj) {
@@ -1425,21 +1464,7 @@ var QuantityParser = class {
1425
1464
  };
1426
1465
 
1427
1466
  // src/oop/DurationParser.ts
1428
- var _DurationParser = class _DurationParser extends QuantityParser {
1429
- constructor(options) {
1430
- super({
1431
- units: {
1432
- ..._DurationParser.units,
1433
- ...options == null ? void 0 : options.units
1434
- },
1435
- short: {
1436
- ..._DurationParser.shortUnits,
1437
- ...options == null ? void 0 : options.short
1438
- }
1439
- });
1440
- }
1441
- };
1442
- _DurationParser.units = {
1467
+ var DURATION_UNITS = {
1443
1468
  week: 6048e5,
1444
1469
  day: 864e5,
1445
1470
  hour: 36e5,
@@ -1447,7 +1472,7 @@ _DurationParser.units = {
1447
1472
  second: 1e3,
1448
1473
  millisecond: 1
1449
1474
  };
1450
- _DurationParser.shortUnits = {
1475
+ var DURATION_SHORT_UNITS = {
1451
1476
  w: "week",
1452
1477
  d: "day",
1453
1478
  h: "hour",
@@ -1455,7 +1480,26 @@ _DurationParser.shortUnits = {
1455
1480
  s: "second",
1456
1481
  ms: "millisecond"
1457
1482
  };
1458
- var DurationParser = _DurationParser;
1483
+ var DurationParser = class _DurationParser extends QuantityParser {
1484
+ constructor(options) {
1485
+ super({
1486
+ units: {
1487
+ ..._DurationParser.units,
1488
+ ...options == null ? void 0 : options.units
1489
+ },
1490
+ short: {
1491
+ ..._DurationParser.shortUnits,
1492
+ ...options == null ? void 0 : options.short
1493
+ }
1494
+ });
1495
+ }
1496
+ static get units() {
1497
+ return DURATION_UNITS;
1498
+ }
1499
+ static get shortUnits() {
1500
+ return DURATION_SHORT_UNITS;
1501
+ }
1502
+ };
1459
1503
 
1460
1504
  // src/oop/Semaphore.ts
1461
1505
  var SemaphorePermit = class {
@@ -1565,6 +1609,11 @@ var TimeoutError = class extends Error {
1565
1609
  }
1566
1610
  };
1567
1611
 
1612
+ // src/random/absoluteJitter.ts
1613
+ function absoluteJitter(base, offset) {
1614
+ return base + offset * (2 * Math.random() - 1);
1615
+ }
1616
+
1568
1617
  // src/random/draw.ts
1569
1618
  function draw(array) {
1570
1619
  const max2 = array.length;
@@ -1575,6 +1624,11 @@ function draw(array) {
1575
1624
  return array[index];
1576
1625
  }
1577
1626
 
1627
+ // src/random/proportionalJitter.ts
1628
+ function proportionalJitter(base, factor) {
1629
+ return base * (1 - factor * (2 * Math.random() - 1));
1630
+ }
1631
+
1578
1632
  // src/random/random.ts
1579
1633
  function random(min2, max2) {
1580
1634
  return Math.floor(Math.random() * (max2 - min2 + 1) + min2);
@@ -1971,6 +2025,19 @@ function isMap(value) {
1971
2025
  return isTagged(value, "[object Map]");
1972
2026
  }
1973
2027
 
2028
+ // src/typed/isMapEqual.ts
2029
+ function isMapEqual(x, y) {
2030
+ if (x.size !== y.size) {
2031
+ return false;
2032
+ }
2033
+ for (const [key, value] of x) {
2034
+ if (!isEqual(value, y.get(key))) {
2035
+ return false;
2036
+ }
2037
+ }
2038
+ return true;
2039
+ }
2040
+
1974
2041
  // src/typed/isNullish.ts
1975
2042
  function isNullish(value) {
1976
2043
  return value === null || value === void 0;
@@ -2035,6 +2102,19 @@ function isSet(value) {
2035
2102
  return isTagged(value, "[object Set]");
2036
2103
  }
2037
2104
 
2105
+ // src/typed/isSetEqual.ts
2106
+ function isSetEqual(x, y) {
2107
+ if (x.size !== y.size) {
2108
+ return false;
2109
+ }
2110
+ for (const item of x) {
2111
+ if (!y.has(item)) {
2112
+ return false;
2113
+ }
2114
+ }
2115
+ return true;
2116
+ }
2117
+
2038
2118
  // src/typed/isString.ts
2039
2119
  function isString(value) {
2040
2120
  return typeof value === "string";
@@ -2065,4 +2145,4 @@ function isWeakSet(value) {
2065
2145
  return isTagged(value, "[object WeakSet]");
2066
2146
  }
2067
2147
 
2068
- export { AggregateErrorOrPolyfill as AggregateError, DefaultCloningStrategy, DurationParser, FastCloningStrategy, QuantityParser, Semaphore, SemaphorePermit, TimeoutError, all, alphabetical, always, assert, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, concat, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, escapeHTML, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isAsyncIterable, isBigInt, isBoolean, isClass, isDangerousKey, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, parseDuration, parseQuantity, partial, partob, pascal, pick, pluck, promiseChain, proxied, queueByKey, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
2148
+ export { AggregateErrorOrPolyfill as AggregateError, DefaultCloningStrategy, DurationParser, FastCloningStrategy, QuantityParser, Semaphore, SemaphorePermit, TimeoutError, absoluteJitter, all, alphabetical, always, assert, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, concat, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, escapeHTML, filterKey, first, flat, flip, fork, get, getOrInsert, getOrInsertComputed, group, guard, identity, inRange, intersects, invert, isArray, isArrayEqual, isAsyncIterable, isBigInt, isBoolean, isClass, isDangerousKey, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isMapEqual, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isSetEqual, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, parseDuration, parseQuantity, partial, partob, pascal, pick, pluck, promiseChain, proportionalJitter, proxied, queueByKey, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radashi",
3
- "version": "12.6.2",
3
+ "version": "12.7.1",
4
4
  "type": "module",
5
5
  "description": "The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.",
6
6
  "repository": {
@@ -42,6 +42,7 @@
42
42
  "test": "vitest run --coverage",
43
43
  "test-branch": "node scripts/run test-branch",
44
44
  "test-single": "node scripts/run test-single",
45
+ "tree-shake-check": "node scripts/run tree-shake",
45
46
  "update-browserslist": "node scripts/run update-browserslist"
46
47
  },
47
48
  "devDependencies": {