radashi 12.2.0-beta.af936c4 → 12.2.0-beta.dc9ade1

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Alec Larson
3
+ Copyright (c) 2024 Alec Larson
4
4
  Copyright (c) 2022 radash
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
package/README.md CHANGED
@@ -4,25 +4,93 @@
4
4
  <p align="center">
5
5
  <img src="https://github.com/radashi-org/radashi/raw/main/.github/img/banner.png" alt="Radashi" width="100%" />
6
6
  </p>
7
+ <a href="https://github.com/radashi-org/radashi/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/radashi" alt="License" /></a>
8
+ <a href="https://github.com/radashi-org/radashi/actions/workflows/publish-beta.yml"><img src="https://img.shields.io/github/actions/workflow/status/radashi-org/radashi/publish-beta.yml?logo=github" alt="Build Status" /></a>
9
+ <a href="https://app.codecov.io/gh/radashi-org/radashi/tree/main/src"><img src="https://img.shields.io/codecov/c/github/radashi-org/radashi?logo=codecov" alt="Codecov" /></a>
10
+ <a href="https://biomejs.dev/"><img src="https://img.shields.io/badge/code_style-biome.js-blue?logo=biome" alt="Code Style: Biome.js" /></a>
11
+ <a href="https://github.com/radashi-org/radashi/discussions"><img src="https://img.shields.io/github/discussions/radashi-org/radashi?logo=github" alt="GitHub Discussions" /></a>
7
12
  </div>
8
13
 
9
- - **What is this?**
10
- Radashi, pronounced /raw-dash-ee/, is a modern, zero-dependency JavaScript utility toolkit built with TypeScript for type-safe, readable, and maintainable code. Radashi omits functions that have become obsolete in Lodash and introduces innovative tools for improved error handling, asynchronous operations, and data manipulation. With a focus on readability and maintainability, Radashi ensures that its source code is easy to understand and use, making it simple for developers to copy individual functions directly from GitHub if needed. Radashi is the go-to toolkit for cleaner, more efficient code in today's JavaScript ecosystem.
14
+ &nbsp;
11
15
 
12
- - **Is this related to Radash?**
13
- Yes! This is a fork of the renowned [`radash`](https://github.com/sodiray/radash) library by Ray Epps [@sodiray](https://github.com/sodiray).
16
+ **Ditch the bloat of Lodash. Stop reinventing the wheel.**
14
17
 
15
- - **Why use this over Radash?**
16
- This fork aims to be a more consistently maintained version, with bug fixes and improvements. We're open to adding many maintainers to the Radashi team, to keep responsiveness high.
18
+ Radashi (pronounced /ruh-DAH-shee/) is a TypeScript utility toolkit, packed with lightweight functions that are readable, performant, and robust.
17
19
 
18
- We are a **community first** fork, which means putting the community's needs first. As such, your feedback is very welcome and we value your perspective. Specifically, we want you to [contribute your viewpoint](https://github.com/orgs/radashi-org/discussions/categories/rfcs?discussions_q=is%3Aopen+category%3ARFCs) to discussions in our RFCs category.
20
+ Radashi is an actively maintained fork of Radash, the fastest growing Lodash alternative with 100K+ weekly downloads.
19
21
 
20
- - **Is there official documentation?**
21
- Currently, there is no documentation beyond this page. There is work being done, which is tracked by [#40](https://github.com/radashi-org/radashi/issues/40). Until then, you can refer to the original `radash` documentation.
22
+ _“What makes Radashi so great?”_
22
23
 
23
- <a href="https://radash-docs.vercel.app">
24
- <img src="https://github.com/radashi-org/radashi/raw/main/.github/img/docs-button.png" alt="Radash documentation" width="250px" />
25
- </a>
24
+ - **unique** and **well-designed** functions
25
+ - **tree-shakeable** (use only what you need!)
26
+ - **dependency-free**
27
+ - **community-first** (your opinions matter)
28
+ - **future-proof** (written with modern ES6+ syntax)
29
+ - **actively maintained** (with a growing team of passionate maintainers)
30
+ - **type-safe** (the best type definitions possible)
31
+ - **full test coverage**
32
+ - **performance tracking** (we track perf regressions with continuous benchmarking)
33
+ - **well-documented**
34
+ - **nightly releases** (`radashi@beta`)
35
+ - **changelog** (easily see what's new in each release)
36
+
37
+ <img src="https://github.com/radashi-org/radashi/raw/main/.github/img/rule.png" width="100%" />
38
+
39
+ ## Documentation
40
+
41
+ An official website is in the works (tracked by [#40](https://github.com/radashi-org/radashi/issues/40)). Until then, you can refer to the original `radash` documentation and the [CHANGELOG.md](https://github.com/radashi-org/radashi/blob/main/CHANGELOG.md) file.
42
+
43
+ <a href="https://radash-docs.vercel.app">
44
+ <img src="https://github.com/radashi-org/radashi/raw/main/.github/img/docs-button.png" alt="Radash documentation" width="250px" />
45
+ </a>
46
+
47
+ <img src="https://github.com/radashi-org/radashi/raw/main/.github/img/rule.png" width="100%" />
48
+
49
+ ## Install
50
+
51
+ ```sh
52
+ pnpm add radashi
53
+ ```
54
+
55
+ ```sh
56
+ yarn add radashi
57
+ ```
58
+
59
+ ```sh
60
+ npm install radashi
61
+ ```
62
+
63
+ ### Beta version
64
+
65
+ The `radashi@beta` version is a nightly release containing everything in the main branch at the time (5:00AM UTC).
66
+
67
+ ```sh
68
+ pnpm add radashi@beta
69
+ ```
70
+
71
+ Its changes are documented [here](https://github.com/radashi-org/radashi/blob/main/CHANGELOG.md#radashibeta). If there's no `radashi@beta` section in the changelog, it means no pull requests have been merged since the last stable release.
72
+
73
+ ### JSR.io
74
+
75
+ Radashi is also published to the [JSR registry](https://jsr.io/docs/why), which gives Radashi [its own page](https://jsr.io/@radashi-org/radashi).
76
+
77
+ ```sh
78
+ jsr add @radashi-org/radashi
79
+ ```
80
+
81
+ ```sh
82
+ deno add @radashi-org/radashi
83
+ ```
84
+
85
+ <img src="https://github.com/radashi-org/radashi/raw/main/.github/img/rule.png" width="100%" />
86
+
87
+ ## FAQ
88
+
89
+ - **“I need XYZ, but Radashi doesn‘t have it.”**
90
+ If you have a need not met by our current set of functions, we want to hear about it. [Start a discussion](https://github.com/orgs/radashi-org/discussions/new?category=ideas) so we can explore the idea together!
91
+
92
+ - **What does “community first” mean exactly?**
93
+ It means putting the community's needs first, leaning towards adding support for popular use cases, as opposed to being strictly minimalist. As such, your feedback is very welcome and we value your perspective. Specifically, we want you to [contribute your viewpoint](https://github.com/orgs/radashi-org/discussions/categories/rfcs?discussions_q=is%3Aopen+category%3ARFCs) to discussions in our RFCs category.
26
94
 
27
95
  - **Are my contributions welcome?**
28
96
  Yes! Pull requests are encouraged, but please keep them small and focused. Sweeping changes are discouraged and won't be merged (unless the rationale's been thoroughly discussed).
@@ -47,7 +115,7 @@
47
115
  To ensure contributions are quickly rolled out, we have the following automatic processes:
48
116
 
49
117
  - **Beta releases**
50
- Whenever the `main` branch receives a fix or feature, a beta release is automatically published to NPM.
118
+ Whenever the `main` branch receives a fix or feature, a beta release is automatically published to NPM at 5:00AM UTC.
51
119
  Installing `radashi@beta` will always fetch the latest beta release. Beta releases are always audited by the Radashi team.
52
120
 
53
121
  - **Preview releases**
@@ -58,22 +126,6 @@
58
126
 
59
127
  <img src="https://github.com/radashi-org/radashi/raw/main/.github/img/rule.png" width="100%" />
60
128
 
61
- ## Install
62
-
63
- ```sh
64
- pnpm add radashi
65
- ```
66
-
67
- ```sh
68
- yarn add radashi
69
- ```
70
-
71
- ```sh
72
- npm install radashi
73
- ```
74
-
75
- <img src="https://github.com/radashi-org/radashi/raw/main/.github/img/rule.png" width="100%" />
76
-
77
129
  ## Contributing
78
130
 
79
131
  Contributions are welcome and appreciated! Check out the contributing guide before you dive in:
package/dist/radashi.cjs CHANGED
@@ -75,6 +75,7 @@ __export(mod_exports, {
75
75
  mapEntries: () => mapEntries,
76
76
  mapKeys: () => mapKeys,
77
77
  mapValues: () => mapValues,
78
+ mapify: () => mapify,
78
79
  max: () => max,
79
80
  memo: () => memo,
80
81
  merge: () => merge,
@@ -117,6 +118,7 @@ __export(mod_exports, {
117
118
  tryit: () => tryit,
118
119
  uid: () => uid,
119
120
  unique: () => unique,
121
+ unzip: () => unzip,
120
122
  upperize: () => upperize,
121
123
  zip: () => zip,
122
124
  zipToObject: () => zipToObject
@@ -124,13 +126,13 @@ __export(mod_exports, {
124
126
  module.exports = __toCommonJS(mod_exports);
125
127
 
126
128
  // src/array/alphabetical.ts
127
- function alphabetical(array, getter, dir = "asc") {
129
+ function alphabetical(array, getter, direction = "asc") {
128
130
  if (!array) {
129
131
  return [];
130
132
  }
131
133
  const asc = (a, b) => `${getter(a)}`.localeCompare(getter(b));
132
134
  const dsc = (a, b) => `${getter(b)}`.localeCompare(getter(a));
133
- return array.slice().sort(dir === "desc" ? dsc : asc);
135
+ return array.slice().sort(direction === "desc" ? dsc : asc);
134
136
  }
135
137
 
136
138
  // src/array/boil.ts
@@ -142,11 +144,12 @@ function boil(array, compareFunc) {
142
144
  }
143
145
 
144
146
  // src/array/cluster.ts
145
- function cluster(list2, size = 2) {
146
- const clusterCount = Math.ceil(list2.length / size);
147
- return new Array(clusterCount).fill(null).map((_c, i) => {
148
- return list2.slice(i * size, i * size + size);
149
- });
147
+ function cluster(array, size = 2) {
148
+ const clusters = [];
149
+ for (let i = 0; i < array.length; i += size) {
150
+ clusters.push(array.slice(i, i + size));
151
+ }
152
+ return clusters;
150
153
  }
151
154
 
152
155
  // src/array/counting.ts
@@ -255,41 +258,52 @@ function list(startOrLength, end, valueOrMapper, step) {
255
258
  return Array.from(range(startOrLength, end, valueOrMapper, step));
256
259
  }
257
260
 
261
+ // src/array/mapify.ts
262
+ function mapify(array, getKey, getValue = (item) => item) {
263
+ const map2 = /* @__PURE__ */ new Map();
264
+ for (const item of array) {
265
+ map2.set(getKey(item), getValue(item));
266
+ }
267
+ return map2;
268
+ }
269
+
258
270
  // src/array/max.ts
259
271
  function max(array, getter) {
272
+ if (!array || (array.length ?? 0) === 0) {
273
+ return null;
274
+ }
260
275
  const get2 = getter ?? ((v) => v);
261
- return boil(array, (a, b) => get2(a) > get2(b) ? a : b);
276
+ return array.reduce((a, b) => get2(a) > get2(b) ? a : b);
262
277
  }
263
278
 
264
279
  // src/array/merge.ts
265
- function merge(root, others, matcher) {
266
- if (!others && !root) {
280
+ function merge(prev, array, toKey) {
281
+ if (!array && !prev) {
267
282
  return [];
268
283
  }
269
- if (!others) {
270
- return [...root];
284
+ if (!array) {
285
+ return [...prev];
271
286
  }
272
- if (!root) {
287
+ if (!prev) {
273
288
  return [];
274
289
  }
275
- if (!matcher) {
276
- return [...root];
290
+ if (!toKey) {
291
+ return [...prev];
277
292
  }
278
- return root.reduce((acc, r) => {
279
- const matched = others.find((o) => matcher(r) === matcher(o));
280
- if (matched) {
281
- acc.push(matched);
282
- } else {
283
- acc.push(r);
284
- }
285
- return acc;
286
- }, []);
293
+ const keys2 = array.map(toKey);
294
+ return prev.map((prevItem) => {
295
+ const index = keys2.indexOf(toKey(prevItem));
296
+ return index > -1 ? array[index] : prevItem;
297
+ });
287
298
  }
288
299
 
289
300
  // src/array/min.ts
290
301
  function min(array, getter) {
302
+ if (!array || (array.length ?? 0) === 0) {
303
+ return null;
304
+ }
291
305
  const get2 = getter ?? ((v) => v);
292
- return boil(array, (a, b) => get2(a) < get2(b) ? a : b);
306
+ return array.reduce((a, b) => get2(a) < get2(b) ? a : b);
293
307
  }
294
308
 
295
309
  // src/array/objectify.ts
@@ -317,48 +331,43 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
317
331
  }
318
332
 
319
333
  // src/array/replace.ts
320
- function replace(list2, newItem, match) {
321
- if (!list2) {
334
+ function replace(array, newItem, match) {
335
+ if (!array) {
322
336
  return [];
323
337
  }
324
338
  if (newItem === void 0) {
325
- return [...list2];
326
- }
327
- for (let idx = 0; idx < list2.length; idx++) {
328
- const item = list2[idx];
329
- if (match(item, idx)) {
330
- return [
331
- ...list2.slice(0, idx),
332
- newItem,
333
- ...list2.slice(idx + 1, list2.length)
334
- ];
339
+ return [...array];
340
+ }
341
+ const out = array.slice();
342
+ for (let index = 0; index < array.length; index++) {
343
+ if (match(array[index], index)) {
344
+ out[index] = newItem;
345
+ break;
335
346
  }
336
347
  }
337
- return [...list2];
348
+ return out;
338
349
  }
339
350
 
340
351
  // src/array/replaceOrAppend.ts
341
- function replaceOrAppend(list2, newItem, match) {
342
- if (!list2 && !newItem) {
352
+ function replaceOrAppend(array, newItem, match) {
353
+ if (!array && !newItem) {
343
354
  return [];
344
355
  }
345
356
  if (!newItem) {
346
- return [...list2];
357
+ return [...array];
347
358
  }
348
- if (!list2) {
359
+ if (!array) {
349
360
  return [newItem];
350
361
  }
351
- for (let idx = 0; idx < list2.length; idx++) {
352
- const item = list2[idx];
353
- if (match(item, idx)) {
354
- return [
355
- ...list2.slice(0, idx),
356
- newItem,
357
- ...list2.slice(idx + 1, list2.length)
358
- ];
362
+ const out = array.slice();
363
+ for (let index = 0; index < array.length; index++) {
364
+ if (match(array[index], index)) {
365
+ out[index] = newItem;
366
+ return out;
359
367
  }
360
368
  }
361
- return [...list2, newItem];
369
+ out.push(newItem);
370
+ return out;
362
371
  }
363
372
 
364
373
  // src/array/select.ts
@@ -403,8 +412,8 @@ function shift(arr, n) {
403
412
  }
404
413
 
405
414
  // src/array/sift.ts
406
- function sift(list2) {
407
- return (list2 == null ? void 0 : list2.filter((x) => !!x)) ?? [];
415
+ function sift(array) {
416
+ return (array == null ? void 0 : array.filter((x) => !!x)) ?? [];
408
417
  }
409
418
 
410
419
  // src/array/sort.ts
@@ -423,26 +432,26 @@ function sum(array, fn) {
423
432
  }
424
433
 
425
434
  // src/array/toggle.ts
426
- function toggle(list2, item, toKey, options) {
427
- if (!list2 && !item) {
435
+ function toggle(array, item, toKey, options) {
436
+ if (!array && !item) {
428
437
  return [];
429
438
  }
430
- if (!list2) {
439
+ if (!array) {
431
440
  return [item];
432
441
  }
433
442
  if (!item) {
434
- return [...list2];
443
+ return [...array];
435
444
  }
436
445
  const matcher = toKey ? (x, idx) => toKey(x, idx) === toKey(item, idx) : (x) => x === item;
437
- const existing = list2.find(matcher);
446
+ const existing = array.find(matcher);
438
447
  if (existing) {
439
- return list2.filter((x, idx) => !matcher(x, idx));
448
+ return array.filter((x, idx) => !matcher(x, idx));
440
449
  }
441
450
  const strategy = (options == null ? void 0 : options.strategy) ?? "append";
442
451
  if (strategy === "append") {
443
- return [...list2, item];
452
+ return [...array, item];
444
453
  }
445
- return [item, ...list2];
454
+ return [item, ...array];
446
455
  }
447
456
 
448
457
  // src/array/unique.ts
@@ -461,12 +470,25 @@ function unique(array, toKey) {
461
470
  return [...new Set(array)];
462
471
  }
463
472
 
464
- // src/array/zip.ts
465
- function zip(...arrays) {
473
+ // src/array/unzip.ts
474
+ function unzip(arrays) {
466
475
  if (!arrays || !arrays.length) {
467
476
  return [];
468
477
  }
469
- return new Array(Math.max(...arrays.map(({ length }) => length))).fill([]).map((_, idx) => arrays.map((array) => array[idx]));
478
+ const out = new Array(
479
+ arrays.reduce((max2, arr) => Math.max(max2, arr.length), 0)
480
+ );
481
+ let index = 0;
482
+ const get2 = (array) => array[index];
483
+ for (; index < out.length; index++) {
484
+ out[index] = Array.from(arrays, get2);
485
+ }
486
+ return out;
487
+ }
488
+
489
+ // src/array/zip.ts
490
+ function zip(...arrays) {
491
+ return unzip(arrays);
470
492
  }
471
493
 
472
494
  // src/array/zipToObject.ts
@@ -1395,7 +1417,7 @@ function isString(value) {
1395
1417
 
1396
1418
  // src/typed/isSymbol.ts
1397
1419
  function isSymbol(value) {
1398
- return !!value && value.constructor === Symbol;
1420
+ return typeof value === "symbol";
1399
1421
  }
1400
1422
  // Annotate the CommonJS export names for ESM import in node:
1401
1423
  0 && (module.exports = {
@@ -1454,6 +1476,7 @@ function isSymbol(value) {
1454
1476
  mapEntries,
1455
1477
  mapKeys,
1456
1478
  mapValues,
1479
+ mapify,
1457
1480
  max,
1458
1481
  memo,
1459
1482
  merge,
@@ -1496,6 +1519,7 @@ function isSymbol(value) {
1496
1519
  tryit,
1497
1520
  uid,
1498
1521
  unique,
1522
+ unzip,
1499
1523
  upperize,
1500
1524
  zip,
1501
1525
  zipToObject
@@ -2,7 +2,7 @@
2
2
  * Sort an array without modifying it and return the newly sorted
3
3
  * value. Allows for a string sorting value.
4
4
  */
5
- declare function alphabetical<T>(array: readonly T[], getter: (item: T) => string, dir?: 'asc' | 'desc'): T[];
5
+ declare function alphabetical<T>(array: readonly T[], getter: (item: T) => string, direction?: 'asc' | 'desc'): T[];
6
6
 
7
7
  /**
8
8
  * Go through a list of items, starting with the first item, and
@@ -23,7 +23,7 @@ declare function boil<T>(array: readonly T[], compareFunc: (a: T, b: T) => T): T
23
23
  * // [[1, 2], [3, 4], [5, 6]]
24
24
  * ```
25
25
  */
26
- declare function cluster<T>(list: readonly T[], size?: number): T[][];
26
+ declare function cluster<T>(array: readonly T[], size?: number): T[][];
27
27
 
28
28
  /**
29
29
  * Counts the occurrences of each unique value returned by the `identity`
@@ -157,6 +157,8 @@ declare function last<T, U>(array: readonly T[], defaultValue: U): T | U;
157
157
  */
158
158
  declare function list<T = number>(startOrLength: number, end?: number, valueOrMapper?: T | ((i: number) => T), step?: number): T[];
159
159
 
160
+ declare function mapify<T, Key, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Map<Key, Value>;
161
+
160
162
  /**
161
163
  * Max gets the greatest value from a list
162
164
  *
@@ -183,7 +185,7 @@ declare function max<T>(array: readonly T[], getter: (item: T) => number): T | n
183
185
  * // [{id: 1, name: 'John'}, {id: 2}]
184
186
  * ```
185
187
  */
186
- declare function merge<T>(root: readonly T[], others: readonly T[], matcher: (item: T) => any): T[];
188
+ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item: T) => any): T[];
187
189
 
188
190
  /**
189
191
  * Min gets the smallest value from a list
@@ -241,7 +243,7 @@ declare function range<T = number>(startOrLength: number, end?: number, valueOrM
241
243
  * // [1, 4, 3]
242
244
  * ```
243
245
  */
244
- declare function replace<T>(list: readonly T[], newItem: T, match: (item: T, idx: number) => boolean): T[];
246
+ declare function replace<T>(array: readonly T[], newItem: T, match: (item: T, idx: number) => boolean): T[];
245
247
 
246
248
  /**
247
249
  * Replace the first occurrence of an item in an array where the
@@ -256,7 +258,7 @@ declare function replace<T>(list: readonly T[], newItem: T, match: (item: T, idx
256
258
  * // [1, 2, 3, 4]
257
259
  * ```
258
260
  */
259
- declare function replaceOrAppend<T>(list: readonly T[], newItem: T, match: (a: T, idx: number) => boolean): T[];
261
+ declare function replaceOrAppend<T>(array: readonly T[], newItem: T, match: (a: T, idx: number) => boolean): T[];
260
262
 
261
263
  /**
262
264
  * Select performs a filter and a mapper inside of a reduce, only
@@ -311,7 +313,7 @@ type Falsy = null | undefined | false | '' | 0 | 0n;
311
313
  * // => [1, 2, 3]
312
314
  * ```
313
315
  */
314
- declare function sift<T>(list: readonly (T | Falsy)[]): T[];
316
+ declare function sift<T>(array: readonly (T | Falsy)[]): T[];
315
317
 
316
318
  /**
317
319
  * Sort an array without modifying it and return the newly sorted
@@ -369,7 +371,7 @@ declare function sum<T extends object>(array: readonly T[], fn: (item: T) => num
369
371
  * // => [{ id: 3 }, { id: 1 }, { id: 2 }]
370
372
  * ```
371
373
  */
372
- declare function toggle<T>(list: readonly T[], item: T,
374
+ declare function toggle<T>(array: readonly T[], item: T,
373
375
  /**
374
376
  * Converts an item of type T item into a value that can be checked
375
377
  * for equality
@@ -390,6 +392,19 @@ toKey?: null | ((item: T, idx: number) => number | string | symbol), options?: {
390
392
  */
391
393
  declare function unique<T, K = T>(array: readonly T[], toKey?: (item: T) => K): T[];
392
394
 
395
+ /**
396
+ * Creates an array of ungrouped elements, where each resulting array
397
+ * contains all elements at a specific index from the input arrays.
398
+ * The first array contains all first elements, the second array
399
+ * contains all second elements, and so on.
400
+ *
401
+ * ```ts
402
+ * unzip([['a', 1, true], ['b', 2, false]])
403
+ * // [['a', 'b'], [1, 2], [true, false]]
404
+ * ```
405
+ */
406
+ declare function unzip<T>(arrays: readonly (readonly T[])[]): T[][];
407
+
393
408
  /**
394
409
  * Creates an array of grouped elements, the first of which contains
395
410
  * the first elements of the given arrays, the second of which
@@ -400,10 +415,10 @@ declare function unique<T, K = T>(array: readonly T[], toKey?: (item: T) => K):
400
415
  * // [['a', 1, true], ['b', 2, false]]
401
416
  * ```
402
417
  */
403
- declare function zip<T1, T2, T3, T4, T5>(array1: T1[], array2: T2[], array3: T3[], array4: T4[], array5: T5[]): [T1, T2, T3, T4, T5][];
404
- declare function zip<T1, T2, T3, T4>(array1: T1[], array2: T2[], array3: T3[], array4: T4[]): [T1, T2, T3, T4][];
405
- declare function zip<T1, T2, T3>(array1: T1[], array2: T2[], array3: T3[]): [T1, T2, T3][];
406
- declare function zip<T1, T2>(array1: T1[], array2: T2[]): [T1, T2][];
418
+ declare function zip<T1, T2, T3, T4, T5>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[], array5: readonly T5[]): [T1, T2, T3, T4, T5][];
419
+ declare function zip<T1, T2, T3, T4>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[]): [T1, T2, T3, T4][];
420
+ declare function zip<T1, T2, T3>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[]): [T1, T2, T3][];
421
+ declare function zip<T1, T2>(array1: readonly T1[], array2: readonly T2[]): [T1, T2][];
407
422
 
408
423
  /**
409
424
  * Creates an object mapping the specified keys to their corresponding
@@ -1039,4 +1054,4 @@ declare function isString(value: any): value is string;
1039
1054
 
1040
1055
  declare function isSymbol(value: any): value is symbol;
1041
1056
 
1042
- export { AggregateError, type DebounceFunction, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MemoOptions, type RetryOptions, type Series, type ThrottledFunction, type TryitResult, type UppercaseKeys, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, filterKey, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isIntString, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, upperize, zip, zipToObject };
1057
+ export { AggregateError, type DebounceFunction, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MemoOptions, type RetryOptions, type Series, type ThrottledFunction, type TryitResult, type UppercaseKeys, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, filterKey, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isIntString, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, unzip, upperize, zip, zipToObject };
package/dist/radashi.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Sort an array without modifying it and return the newly sorted
3
3
  * value. Allows for a string sorting value.
4
4
  */
5
- declare function alphabetical<T>(array: readonly T[], getter: (item: T) => string, dir?: 'asc' | 'desc'): T[];
5
+ declare function alphabetical<T>(array: readonly T[], getter: (item: T) => string, direction?: 'asc' | 'desc'): T[];
6
6
 
7
7
  /**
8
8
  * Go through a list of items, starting with the first item, and
@@ -23,7 +23,7 @@ declare function boil<T>(array: readonly T[], compareFunc: (a: T, b: T) => T): T
23
23
  * // [[1, 2], [3, 4], [5, 6]]
24
24
  * ```
25
25
  */
26
- declare function cluster<T>(list: readonly T[], size?: number): T[][];
26
+ declare function cluster<T>(array: readonly T[], size?: number): T[][];
27
27
 
28
28
  /**
29
29
  * Counts the occurrences of each unique value returned by the `identity`
@@ -157,6 +157,8 @@ declare function last<T, U>(array: readonly T[], defaultValue: U): T | U;
157
157
  */
158
158
  declare function list<T = number>(startOrLength: number, end?: number, valueOrMapper?: T | ((i: number) => T), step?: number): T[];
159
159
 
160
+ declare function mapify<T, Key, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Map<Key, Value>;
161
+
160
162
  /**
161
163
  * Max gets the greatest value from a list
162
164
  *
@@ -183,7 +185,7 @@ declare function max<T>(array: readonly T[], getter: (item: T) => number): T | n
183
185
  * // [{id: 1, name: 'John'}, {id: 2}]
184
186
  * ```
185
187
  */
186
- declare function merge<T>(root: readonly T[], others: readonly T[], matcher: (item: T) => any): T[];
188
+ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item: T) => any): T[];
187
189
 
188
190
  /**
189
191
  * Min gets the smallest value from a list
@@ -241,7 +243,7 @@ declare function range<T = number>(startOrLength: number, end?: number, valueOrM
241
243
  * // [1, 4, 3]
242
244
  * ```
243
245
  */
244
- declare function replace<T>(list: readonly T[], newItem: T, match: (item: T, idx: number) => boolean): T[];
246
+ declare function replace<T>(array: readonly T[], newItem: T, match: (item: T, idx: number) => boolean): T[];
245
247
 
246
248
  /**
247
249
  * Replace the first occurrence of an item in an array where the
@@ -256,7 +258,7 @@ declare function replace<T>(list: readonly T[], newItem: T, match: (item: T, idx
256
258
  * // [1, 2, 3, 4]
257
259
  * ```
258
260
  */
259
- declare function replaceOrAppend<T>(list: readonly T[], newItem: T, match: (a: T, idx: number) => boolean): T[];
261
+ declare function replaceOrAppend<T>(array: readonly T[], newItem: T, match: (a: T, idx: number) => boolean): T[];
260
262
 
261
263
  /**
262
264
  * Select performs a filter and a mapper inside of a reduce, only
@@ -311,7 +313,7 @@ type Falsy = null | undefined | false | '' | 0 | 0n;
311
313
  * // => [1, 2, 3]
312
314
  * ```
313
315
  */
314
- declare function sift<T>(list: readonly (T | Falsy)[]): T[];
316
+ declare function sift<T>(array: readonly (T | Falsy)[]): T[];
315
317
 
316
318
  /**
317
319
  * Sort an array without modifying it and return the newly sorted
@@ -369,7 +371,7 @@ declare function sum<T extends object>(array: readonly T[], fn: (item: T) => num
369
371
  * // => [{ id: 3 }, { id: 1 }, { id: 2 }]
370
372
  * ```
371
373
  */
372
- declare function toggle<T>(list: readonly T[], item: T,
374
+ declare function toggle<T>(array: readonly T[], item: T,
373
375
  /**
374
376
  * Converts an item of type T item into a value that can be checked
375
377
  * for equality
@@ -390,6 +392,19 @@ toKey?: null | ((item: T, idx: number) => number | string | symbol), options?: {
390
392
  */
391
393
  declare function unique<T, K = T>(array: readonly T[], toKey?: (item: T) => K): T[];
392
394
 
395
+ /**
396
+ * Creates an array of ungrouped elements, where each resulting array
397
+ * contains all elements at a specific index from the input arrays.
398
+ * The first array contains all first elements, the second array
399
+ * contains all second elements, and so on.
400
+ *
401
+ * ```ts
402
+ * unzip([['a', 1, true], ['b', 2, false]])
403
+ * // [['a', 'b'], [1, 2], [true, false]]
404
+ * ```
405
+ */
406
+ declare function unzip<T>(arrays: readonly (readonly T[])[]): T[][];
407
+
393
408
  /**
394
409
  * Creates an array of grouped elements, the first of which contains
395
410
  * the first elements of the given arrays, the second of which
@@ -400,10 +415,10 @@ declare function unique<T, K = T>(array: readonly T[], toKey?: (item: T) => K):
400
415
  * // [['a', 1, true], ['b', 2, false]]
401
416
  * ```
402
417
  */
403
- declare function zip<T1, T2, T3, T4, T5>(array1: T1[], array2: T2[], array3: T3[], array4: T4[], array5: T5[]): [T1, T2, T3, T4, T5][];
404
- declare function zip<T1, T2, T3, T4>(array1: T1[], array2: T2[], array3: T3[], array4: T4[]): [T1, T2, T3, T4][];
405
- declare function zip<T1, T2, T3>(array1: T1[], array2: T2[], array3: T3[]): [T1, T2, T3][];
406
- declare function zip<T1, T2>(array1: T1[], array2: T2[]): [T1, T2][];
418
+ declare function zip<T1, T2, T3, T4, T5>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[], array5: readonly T5[]): [T1, T2, T3, T4, T5][];
419
+ declare function zip<T1, T2, T3, T4>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[], array4: readonly T4[]): [T1, T2, T3, T4][];
420
+ declare function zip<T1, T2, T3>(array1: readonly T1[], array2: readonly T2[], array3: readonly T3[]): [T1, T2, T3][];
421
+ declare function zip<T1, T2>(array1: readonly T1[], array2: readonly T2[]): [T1, T2][];
407
422
 
408
423
  /**
409
424
  * Creates an object mapping the specified keys to their corresponding
@@ -1039,4 +1054,4 @@ declare function isString(value: any): value is string;
1039
1054
 
1040
1055
  declare function isSymbol(value: any): value is symbol;
1041
1056
 
1042
- export { AggregateError, type DebounceFunction, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MemoOptions, type RetryOptions, type Series, type ThrottledFunction, type TryitResult, type UppercaseKeys, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, filterKey, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isIntString, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, upperize, zip, zipToObject };
1057
+ export { AggregateError, type DebounceFunction, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MemoOptions, type RetryOptions, type Series, type ThrottledFunction, type TryitResult, type UppercaseKeys, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, filterKey, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isIntString, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, unzip, upperize, zip, zipToObject };
package/dist/radashi.js CHANGED
@@ -1,11 +1,11 @@
1
1
  // src/array/alphabetical.ts
2
- function alphabetical(array, getter, dir = "asc") {
2
+ function alphabetical(array, getter, direction = "asc") {
3
3
  if (!array) {
4
4
  return [];
5
5
  }
6
6
  const asc = (a, b) => `${getter(a)}`.localeCompare(getter(b));
7
7
  const dsc = (a, b) => `${getter(b)}`.localeCompare(getter(a));
8
- return array.slice().sort(dir === "desc" ? dsc : asc);
8
+ return array.slice().sort(direction === "desc" ? dsc : asc);
9
9
  }
10
10
 
11
11
  // src/array/boil.ts
@@ -17,11 +17,12 @@ function boil(array, compareFunc) {
17
17
  }
18
18
 
19
19
  // src/array/cluster.ts
20
- function cluster(list2, size = 2) {
21
- const clusterCount = Math.ceil(list2.length / size);
22
- return new Array(clusterCount).fill(null).map((_c, i) => {
23
- return list2.slice(i * size, i * size + size);
24
- });
20
+ function cluster(array, size = 2) {
21
+ const clusters = [];
22
+ for (let i = 0; i < array.length; i += size) {
23
+ clusters.push(array.slice(i, i + size));
24
+ }
25
+ return clusters;
25
26
  }
26
27
 
27
28
  // src/array/counting.ts
@@ -130,41 +131,52 @@ function list(startOrLength, end, valueOrMapper, step) {
130
131
  return Array.from(range(startOrLength, end, valueOrMapper, step));
131
132
  }
132
133
 
134
+ // src/array/mapify.ts
135
+ function mapify(array, getKey, getValue = (item) => item) {
136
+ const map2 = /* @__PURE__ */ new Map();
137
+ for (const item of array) {
138
+ map2.set(getKey(item), getValue(item));
139
+ }
140
+ return map2;
141
+ }
142
+
133
143
  // src/array/max.ts
134
144
  function max(array, getter) {
145
+ if (!array || (array.length ?? 0) === 0) {
146
+ return null;
147
+ }
135
148
  const get2 = getter ?? ((v) => v);
136
- return boil(array, (a, b) => get2(a) > get2(b) ? a : b);
149
+ return array.reduce((a, b) => get2(a) > get2(b) ? a : b);
137
150
  }
138
151
 
139
152
  // src/array/merge.ts
140
- function merge(root, others, matcher) {
141
- if (!others && !root) {
153
+ function merge(prev, array, toKey) {
154
+ if (!array && !prev) {
142
155
  return [];
143
156
  }
144
- if (!others) {
145
- return [...root];
157
+ if (!array) {
158
+ return [...prev];
146
159
  }
147
- if (!root) {
160
+ if (!prev) {
148
161
  return [];
149
162
  }
150
- if (!matcher) {
151
- return [...root];
163
+ if (!toKey) {
164
+ return [...prev];
152
165
  }
153
- return root.reduce((acc, r) => {
154
- const matched = others.find((o) => matcher(r) === matcher(o));
155
- if (matched) {
156
- acc.push(matched);
157
- } else {
158
- acc.push(r);
159
- }
160
- return acc;
161
- }, []);
166
+ const keys2 = array.map(toKey);
167
+ return prev.map((prevItem) => {
168
+ const index = keys2.indexOf(toKey(prevItem));
169
+ return index > -1 ? array[index] : prevItem;
170
+ });
162
171
  }
163
172
 
164
173
  // src/array/min.ts
165
174
  function min(array, getter) {
175
+ if (!array || (array.length ?? 0) === 0) {
176
+ return null;
177
+ }
166
178
  const get2 = getter ?? ((v) => v);
167
- return boil(array, (a, b) => get2(a) < get2(b) ? a : b);
179
+ return array.reduce((a, b) => get2(a) < get2(b) ? a : b);
168
180
  }
169
181
 
170
182
  // src/array/objectify.ts
@@ -192,48 +204,43 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
192
204
  }
193
205
 
194
206
  // src/array/replace.ts
195
- function replace(list2, newItem, match) {
196
- if (!list2) {
207
+ function replace(array, newItem, match) {
208
+ if (!array) {
197
209
  return [];
198
210
  }
199
211
  if (newItem === void 0) {
200
- return [...list2];
201
- }
202
- for (let idx = 0; idx < list2.length; idx++) {
203
- const item = list2[idx];
204
- if (match(item, idx)) {
205
- return [
206
- ...list2.slice(0, idx),
207
- newItem,
208
- ...list2.slice(idx + 1, list2.length)
209
- ];
212
+ return [...array];
213
+ }
214
+ const out = array.slice();
215
+ for (let index = 0; index < array.length; index++) {
216
+ if (match(array[index], index)) {
217
+ out[index] = newItem;
218
+ break;
210
219
  }
211
220
  }
212
- return [...list2];
221
+ return out;
213
222
  }
214
223
 
215
224
  // src/array/replaceOrAppend.ts
216
- function replaceOrAppend(list2, newItem, match) {
217
- if (!list2 && !newItem) {
225
+ function replaceOrAppend(array, newItem, match) {
226
+ if (!array && !newItem) {
218
227
  return [];
219
228
  }
220
229
  if (!newItem) {
221
- return [...list2];
230
+ return [...array];
222
231
  }
223
- if (!list2) {
232
+ if (!array) {
224
233
  return [newItem];
225
234
  }
226
- for (let idx = 0; idx < list2.length; idx++) {
227
- const item = list2[idx];
228
- if (match(item, idx)) {
229
- return [
230
- ...list2.slice(0, idx),
231
- newItem,
232
- ...list2.slice(idx + 1, list2.length)
233
- ];
235
+ const out = array.slice();
236
+ for (let index = 0; index < array.length; index++) {
237
+ if (match(array[index], index)) {
238
+ out[index] = newItem;
239
+ return out;
234
240
  }
235
241
  }
236
- return [...list2, newItem];
242
+ out.push(newItem);
243
+ return out;
237
244
  }
238
245
 
239
246
  // src/array/select.ts
@@ -278,8 +285,8 @@ function shift(arr, n) {
278
285
  }
279
286
 
280
287
  // src/array/sift.ts
281
- function sift(list2) {
282
- return (list2 == null ? void 0 : list2.filter((x) => !!x)) ?? [];
288
+ function sift(array) {
289
+ return (array == null ? void 0 : array.filter((x) => !!x)) ?? [];
283
290
  }
284
291
 
285
292
  // src/array/sort.ts
@@ -298,26 +305,26 @@ function sum(array, fn) {
298
305
  }
299
306
 
300
307
  // src/array/toggle.ts
301
- function toggle(list2, item, toKey, options) {
302
- if (!list2 && !item) {
308
+ function toggle(array, item, toKey, options) {
309
+ if (!array && !item) {
303
310
  return [];
304
311
  }
305
- if (!list2) {
312
+ if (!array) {
306
313
  return [item];
307
314
  }
308
315
  if (!item) {
309
- return [...list2];
316
+ return [...array];
310
317
  }
311
318
  const matcher = toKey ? (x, idx) => toKey(x, idx) === toKey(item, idx) : (x) => x === item;
312
- const existing = list2.find(matcher);
319
+ const existing = array.find(matcher);
313
320
  if (existing) {
314
- return list2.filter((x, idx) => !matcher(x, idx));
321
+ return array.filter((x, idx) => !matcher(x, idx));
315
322
  }
316
323
  const strategy = (options == null ? void 0 : options.strategy) ?? "append";
317
324
  if (strategy === "append") {
318
- return [...list2, item];
325
+ return [...array, item];
319
326
  }
320
- return [item, ...list2];
327
+ return [item, ...array];
321
328
  }
322
329
 
323
330
  // src/array/unique.ts
@@ -336,12 +343,25 @@ function unique(array, toKey) {
336
343
  return [...new Set(array)];
337
344
  }
338
345
 
339
- // src/array/zip.ts
340
- function zip(...arrays) {
346
+ // src/array/unzip.ts
347
+ function unzip(arrays) {
341
348
  if (!arrays || !arrays.length) {
342
349
  return [];
343
350
  }
344
- return new Array(Math.max(...arrays.map(({ length }) => length))).fill([]).map((_, idx) => arrays.map((array) => array[idx]));
351
+ const out = new Array(
352
+ arrays.reduce((max2, arr) => Math.max(max2, arr.length), 0)
353
+ );
354
+ let index = 0;
355
+ const get2 = (array) => array[index];
356
+ for (; index < out.length; index++) {
357
+ out[index] = Array.from(arrays, get2);
358
+ }
359
+ return out;
360
+ }
361
+
362
+ // src/array/zip.ts
363
+ function zip(...arrays) {
364
+ return unzip(arrays);
345
365
  }
346
366
 
347
367
  // src/array/zipToObject.ts
@@ -1270,7 +1290,7 @@ function isString(value) {
1270
1290
 
1271
1291
  // src/typed/isSymbol.ts
1272
1292
  function isSymbol(value) {
1273
- return !!value && value.constructor === Symbol;
1293
+ return typeof value === "symbol";
1274
1294
  }
1275
1295
  export {
1276
1296
  AggregateError,
@@ -1328,6 +1348,7 @@ export {
1328
1348
  mapEntries,
1329
1349
  mapKeys,
1330
1350
  mapValues,
1351
+ mapify,
1331
1352
  max,
1332
1353
  memo,
1333
1354
  merge,
@@ -1370,6 +1391,7 @@ export {
1370
1391
  tryit,
1371
1392
  uid,
1372
1393
  unique,
1394
+ unzip,
1373
1395
  upperize,
1374
1396
  zip,
1375
1397
  zipToObject
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radashi",
3
- "version": "12.2.0-beta.af936c4",
3
+ "version": "12.2.0-beta.dc9ade1",
4
4
  "description": "Functional utility library - modern, simple, typed, powerful",
5
5
  "sideEffects": false,
6
6
  "author": "Alec Larson",
@@ -12,16 +12,23 @@
12
12
  "scripts": {
13
13
  "dev": "tsup --clean --watch --sourcemap",
14
14
  "build": "tsup --clean",
15
- "lint": "tsc && biome check && pnpm -s dlx deno-bin@1.44.4 lint",
16
- "format": "biome check --fix --unsafe",
15
+ "lint": "concurrently -c=auto -g --kill-others-on-fail 'npm:lint:*'",
16
+ "lint:tsc": "concurrently -c=auto -g --kill-others-on-fail --names src,tests,benchmarks 'tsc' 'tsc -p tests' 'tsc -p benchmarks'",
17
+ "lint:biome": "biome check ./src ./tests ./benchmarks",
18
+ "lint:jsr": "pnpm -s dlx deno-bin@1.44.4 lint",
19
+ "format": "bash ./scripts/format.sh",
17
20
  "test": "vitest run --coverage",
21
+ "test-single": "bash ./scripts/test-single.sh",
18
22
  "bench": "vitest bench",
19
- "prepublishOnly": "tsc && biome check --fix && pnpm -s build"
23
+ "prepublishOnly": "tsc && biome check --fix && pnpm -s build",
24
+ "add-function": "bash ./scripts/add-function.sh"
20
25
  },
21
26
  "devDependencies": {
22
27
  "@biomejs/biome": "^1.8.3",
23
28
  "@codspeed/vitest-plugin": "^3.1.0",
24
29
  "@vitest/coverage-v8": "1.6.0",
30
+ "concurrently": "^8.2.2",
31
+ "prettier": "^3.3.2",
25
32
  "tsup": "^8.1.0",
26
33
  "typescript": "^5.5.2",
27
34
  "vitest": "1.6.0"