radashi 12.2.0-beta.af936c4 → 12.2.0-beta.c59abfd
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 +1 -1
- package/README.md +81 -29
- package/dist/radashi.cjs +109 -79
- package/dist/radashi.d.cts +61 -16
- package/dist/radashi.d.ts +61 -16
- package/dist/radashi.js +106 -79
- package/package.json +11 -4
package/LICENSE.md
CHANGED
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
|
-
|
|
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
|
+
|
|
11
15
|
|
|
12
|
-
|
|
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
|
-
-
|
|
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
|
-
|
|
20
|
+
Radashi is an actively maintained fork of Radash, the fastest growing Lodash alternative with 100K+ weekly downloads.
|
|
19
21
|
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
@@ -43,6 +43,7 @@ __export(mod_exports, {
|
|
|
43
43
|
filterKey: () => filterKey,
|
|
44
44
|
first: () => first,
|
|
45
45
|
flat: () => flat,
|
|
46
|
+
flip: () => flip,
|
|
46
47
|
fork: () => fork,
|
|
47
48
|
get: () => get,
|
|
48
49
|
group: () => group,
|
|
@@ -75,6 +76,7 @@ __export(mod_exports, {
|
|
|
75
76
|
mapEntries: () => mapEntries,
|
|
76
77
|
mapKeys: () => mapKeys,
|
|
77
78
|
mapValues: () => mapValues,
|
|
79
|
+
mapify: () => mapify,
|
|
78
80
|
max: () => max,
|
|
79
81
|
memo: () => memo,
|
|
80
82
|
merge: () => merge,
|
|
@@ -117,6 +119,7 @@ __export(mod_exports, {
|
|
|
117
119
|
tryit: () => tryit,
|
|
118
120
|
uid: () => uid,
|
|
119
121
|
unique: () => unique,
|
|
122
|
+
unzip: () => unzip,
|
|
120
123
|
upperize: () => upperize,
|
|
121
124
|
zip: () => zip,
|
|
122
125
|
zipToObject: () => zipToObject
|
|
@@ -124,13 +127,13 @@ __export(mod_exports, {
|
|
|
124
127
|
module.exports = __toCommonJS(mod_exports);
|
|
125
128
|
|
|
126
129
|
// src/array/alphabetical.ts
|
|
127
|
-
function alphabetical(array, getter,
|
|
130
|
+
function alphabetical(array, getter, direction = "asc") {
|
|
128
131
|
if (!array) {
|
|
129
132
|
return [];
|
|
130
133
|
}
|
|
131
134
|
const asc = (a, b) => `${getter(a)}`.localeCompare(getter(b));
|
|
132
135
|
const dsc = (a, b) => `${getter(b)}`.localeCompare(getter(a));
|
|
133
|
-
return array.slice().sort(
|
|
136
|
+
return array.slice().sort(direction === "desc" ? dsc : asc);
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
// src/array/boil.ts
|
|
@@ -142,11 +145,12 @@ function boil(array, compareFunc) {
|
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
// src/array/cluster.ts
|
|
145
|
-
function cluster(
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
148
|
+
function cluster(array, size = 2) {
|
|
149
|
+
const clusters = [];
|
|
150
|
+
for (let i = 0; i < array.length; i += size) {
|
|
151
|
+
clusters.push(array.slice(i, i + size));
|
|
152
|
+
}
|
|
153
|
+
return clusters;
|
|
150
154
|
}
|
|
151
155
|
|
|
152
156
|
// src/array/counting.ts
|
|
@@ -255,41 +259,52 @@ function list(startOrLength, end, valueOrMapper, step) {
|
|
|
255
259
|
return Array.from(range(startOrLength, end, valueOrMapper, step));
|
|
256
260
|
}
|
|
257
261
|
|
|
262
|
+
// src/array/mapify.ts
|
|
263
|
+
function mapify(array, getKey, getValue = (item) => item) {
|
|
264
|
+
const map2 = /* @__PURE__ */ new Map();
|
|
265
|
+
for (const item of array) {
|
|
266
|
+
map2.set(getKey(item), getValue(item));
|
|
267
|
+
}
|
|
268
|
+
return map2;
|
|
269
|
+
}
|
|
270
|
+
|
|
258
271
|
// src/array/max.ts
|
|
259
272
|
function max(array, getter) {
|
|
273
|
+
if (!array || (array.length ?? 0) === 0) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
260
276
|
const get2 = getter ?? ((v) => v);
|
|
261
|
-
return
|
|
277
|
+
return array.reduce((a, b) => get2(a) > get2(b) ? a : b);
|
|
262
278
|
}
|
|
263
279
|
|
|
264
280
|
// src/array/merge.ts
|
|
265
|
-
function merge(
|
|
266
|
-
if (!
|
|
281
|
+
function merge(prev, array, toKey) {
|
|
282
|
+
if (!array && !prev) {
|
|
267
283
|
return [];
|
|
268
284
|
}
|
|
269
|
-
if (!
|
|
270
|
-
return [...
|
|
285
|
+
if (!array) {
|
|
286
|
+
return [...prev];
|
|
271
287
|
}
|
|
272
|
-
if (!
|
|
288
|
+
if (!prev) {
|
|
273
289
|
return [];
|
|
274
290
|
}
|
|
275
|
-
if (!
|
|
276
|
-
return [...
|
|
291
|
+
if (!toKey) {
|
|
292
|
+
return [...prev];
|
|
277
293
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
acc.push(r);
|
|
284
|
-
}
|
|
285
|
-
return acc;
|
|
286
|
-
}, []);
|
|
294
|
+
const keys2 = array.map(toKey);
|
|
295
|
+
return prev.map((prevItem) => {
|
|
296
|
+
const index = keys2.indexOf(toKey(prevItem));
|
|
297
|
+
return index > -1 ? array[index] : prevItem;
|
|
298
|
+
});
|
|
287
299
|
}
|
|
288
300
|
|
|
289
301
|
// src/array/min.ts
|
|
290
302
|
function min(array, getter) {
|
|
303
|
+
if (!array || (array.length ?? 0) === 0) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
291
306
|
const get2 = getter ?? ((v) => v);
|
|
292
|
-
return
|
|
307
|
+
return array.reduce((a, b) => get2(a) < get2(b) ? a : b);
|
|
293
308
|
}
|
|
294
309
|
|
|
295
310
|
// src/array/objectify.ts
|
|
@@ -317,48 +332,43 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
|
|
|
317
332
|
}
|
|
318
333
|
|
|
319
334
|
// src/array/replace.ts
|
|
320
|
-
function replace(
|
|
321
|
-
if (!
|
|
335
|
+
function replace(array, newItem, match) {
|
|
336
|
+
if (!array) {
|
|
322
337
|
return [];
|
|
323
338
|
}
|
|
324
339
|
if (newItem === void 0) {
|
|
325
|
-
return [...
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (match(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
newItem,
|
|
333
|
-
...list2.slice(idx + 1, list2.length)
|
|
334
|
-
];
|
|
340
|
+
return [...array];
|
|
341
|
+
}
|
|
342
|
+
const out = array.slice();
|
|
343
|
+
for (let index = 0; index < array.length; index++) {
|
|
344
|
+
if (match(array[index], index)) {
|
|
345
|
+
out[index] = newItem;
|
|
346
|
+
break;
|
|
335
347
|
}
|
|
336
348
|
}
|
|
337
|
-
return
|
|
349
|
+
return out;
|
|
338
350
|
}
|
|
339
351
|
|
|
340
352
|
// src/array/replaceOrAppend.ts
|
|
341
|
-
function replaceOrAppend(
|
|
342
|
-
if (!
|
|
353
|
+
function replaceOrAppend(array, newItem, match) {
|
|
354
|
+
if (!array && !newItem) {
|
|
343
355
|
return [];
|
|
344
356
|
}
|
|
345
357
|
if (!newItem) {
|
|
346
|
-
return [...
|
|
358
|
+
return [...array];
|
|
347
359
|
}
|
|
348
|
-
if (!
|
|
360
|
+
if (!array) {
|
|
349
361
|
return [newItem];
|
|
350
362
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
if (match(
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
newItem,
|
|
357
|
-
...list2.slice(idx + 1, list2.length)
|
|
358
|
-
];
|
|
363
|
+
const out = array.slice();
|
|
364
|
+
for (let index = 0; index < array.length; index++) {
|
|
365
|
+
if (match(array[index], index)) {
|
|
366
|
+
out[index] = newItem;
|
|
367
|
+
return out;
|
|
359
368
|
}
|
|
360
369
|
}
|
|
361
|
-
|
|
370
|
+
out.push(newItem);
|
|
371
|
+
return out;
|
|
362
372
|
}
|
|
363
373
|
|
|
364
374
|
// src/array/select.ts
|
|
@@ -403,8 +413,8 @@ function shift(arr, n) {
|
|
|
403
413
|
}
|
|
404
414
|
|
|
405
415
|
// src/array/sift.ts
|
|
406
|
-
function sift(
|
|
407
|
-
return (
|
|
416
|
+
function sift(array) {
|
|
417
|
+
return (array == null ? void 0 : array.filter((x) => !!x)) ?? [];
|
|
408
418
|
}
|
|
409
419
|
|
|
410
420
|
// src/array/sort.ts
|
|
@@ -423,26 +433,26 @@ function sum(array, fn) {
|
|
|
423
433
|
}
|
|
424
434
|
|
|
425
435
|
// src/array/toggle.ts
|
|
426
|
-
function toggle(
|
|
427
|
-
if (!
|
|
436
|
+
function toggle(array, item, toKey, options) {
|
|
437
|
+
if (!array && !item) {
|
|
428
438
|
return [];
|
|
429
439
|
}
|
|
430
|
-
if (!
|
|
440
|
+
if (!array) {
|
|
431
441
|
return [item];
|
|
432
442
|
}
|
|
433
443
|
if (!item) {
|
|
434
|
-
return [...
|
|
444
|
+
return [...array];
|
|
435
445
|
}
|
|
436
446
|
const matcher = toKey ? (x, idx) => toKey(x, idx) === toKey(item, idx) : (x) => x === item;
|
|
437
|
-
const existing =
|
|
447
|
+
const existing = array.find(matcher);
|
|
438
448
|
if (existing) {
|
|
439
|
-
return
|
|
449
|
+
return array.filter((x, idx) => !matcher(x, idx));
|
|
440
450
|
}
|
|
441
451
|
const strategy = (options == null ? void 0 : options.strategy) ?? "append";
|
|
442
452
|
if (strategy === "append") {
|
|
443
|
-
return [...
|
|
453
|
+
return [...array, item];
|
|
444
454
|
}
|
|
445
|
-
return [item, ...
|
|
455
|
+
return [item, ...array];
|
|
446
456
|
}
|
|
447
457
|
|
|
448
458
|
// src/array/unique.ts
|
|
@@ -461,12 +471,25 @@ function unique(array, toKey) {
|
|
|
461
471
|
return [...new Set(array)];
|
|
462
472
|
}
|
|
463
473
|
|
|
464
|
-
// src/array/
|
|
465
|
-
function
|
|
474
|
+
// src/array/unzip.ts
|
|
475
|
+
function unzip(arrays) {
|
|
466
476
|
if (!arrays || !arrays.length) {
|
|
467
477
|
return [];
|
|
468
478
|
}
|
|
469
|
-
|
|
479
|
+
const out = new Array(
|
|
480
|
+
arrays.reduce((max2, arr) => Math.max(max2, arr.length), 0)
|
|
481
|
+
);
|
|
482
|
+
let index = 0;
|
|
483
|
+
const get2 = (array) => array[index];
|
|
484
|
+
for (; index < out.length; index++) {
|
|
485
|
+
out[index] = Array.from(arrays, get2);
|
|
486
|
+
}
|
|
487
|
+
return out;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// src/array/zip.ts
|
|
491
|
+
function zip(...arrays) {
|
|
492
|
+
return unzip(arrays);
|
|
470
493
|
}
|
|
471
494
|
|
|
472
495
|
// src/array/zipToObject.ts
|
|
@@ -717,6 +740,11 @@ function debounce({ delay }, func) {
|
|
|
717
740
|
return debounced;
|
|
718
741
|
}
|
|
719
742
|
|
|
743
|
+
// src/curry/flip.ts
|
|
744
|
+
function flip(fn) {
|
|
745
|
+
return (arg2, arg1, ...args) => fn(arg1, arg2, ...args);
|
|
746
|
+
}
|
|
747
|
+
|
|
720
748
|
// src/curry/memo.ts
|
|
721
749
|
function memoize(cache, func, keyFunc, ttl) {
|
|
722
750
|
return function callWithMemo(...args) {
|
|
@@ -809,22 +837,14 @@ function round(value, precision, toInteger = Math.round) {
|
|
|
809
837
|
|
|
810
838
|
// src/number/toFloat.ts
|
|
811
839
|
function toFloat(value, defaultValue) {
|
|
812
|
-
const
|
|
813
|
-
|
|
814
|
-
return def;
|
|
815
|
-
}
|
|
816
|
-
const result = Number.parseFloat(value);
|
|
817
|
-
return Number.isNaN(result) ? def : result;
|
|
840
|
+
const parsedValue = isSymbol(value) ? Number.NaN : Number.parseFloat(value);
|
|
841
|
+
return Number.isNaN(parsedValue) ? defaultValue !== void 0 ? defaultValue : 0 : parsedValue;
|
|
818
842
|
}
|
|
819
843
|
|
|
820
844
|
// src/number/toInt.ts
|
|
821
845
|
function toInt(value, defaultValue) {
|
|
822
|
-
const
|
|
823
|
-
|
|
824
|
-
return def;
|
|
825
|
-
}
|
|
826
|
-
const result = Number.parseInt(value);
|
|
827
|
-
return Number.isNaN(result) ? def : result;
|
|
846
|
+
const parsedValue = isSymbol(value) ? Number.NaN : Number.parseInt(value);
|
|
847
|
+
return Number.isNaN(parsedValue) ? defaultValue !== void 0 ? defaultValue : 0 : parsedValue;
|
|
828
848
|
}
|
|
829
849
|
|
|
830
850
|
// src/object/assign.ts
|
|
@@ -1097,8 +1117,15 @@ function random(min2, max2) {
|
|
|
1097
1117
|
}
|
|
1098
1118
|
|
|
1099
1119
|
// src/random/shuffle.ts
|
|
1100
|
-
function shuffle(array) {
|
|
1101
|
-
|
|
1120
|
+
function shuffle(array, random2 = random) {
|
|
1121
|
+
const newArray = array.slice();
|
|
1122
|
+
for (let idx = 0, randomIdx, item; idx < array.length; idx++) {
|
|
1123
|
+
randomIdx = random2(0, array.length - 1);
|
|
1124
|
+
item = newArray[randomIdx];
|
|
1125
|
+
newArray[randomIdx] = newArray[idx];
|
|
1126
|
+
newArray[idx] = item;
|
|
1127
|
+
}
|
|
1128
|
+
return newArray;
|
|
1102
1129
|
}
|
|
1103
1130
|
|
|
1104
1131
|
// src/random/uid.ts
|
|
@@ -1395,7 +1422,7 @@ function isString(value) {
|
|
|
1395
1422
|
|
|
1396
1423
|
// src/typed/isSymbol.ts
|
|
1397
1424
|
function isSymbol(value) {
|
|
1398
|
-
return
|
|
1425
|
+
return typeof value === "symbol";
|
|
1399
1426
|
}
|
|
1400
1427
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1401
1428
|
0 && (module.exports = {
|
|
@@ -1422,6 +1449,7 @@ function isSymbol(value) {
|
|
|
1422
1449
|
filterKey,
|
|
1423
1450
|
first,
|
|
1424
1451
|
flat,
|
|
1452
|
+
flip,
|
|
1425
1453
|
fork,
|
|
1426
1454
|
get,
|
|
1427
1455
|
group,
|
|
@@ -1454,6 +1482,7 @@ function isSymbol(value) {
|
|
|
1454
1482
|
mapEntries,
|
|
1455
1483
|
mapKeys,
|
|
1456
1484
|
mapValues,
|
|
1485
|
+
mapify,
|
|
1457
1486
|
max,
|
|
1458
1487
|
memo,
|
|
1459
1488
|
merge,
|
|
@@ -1496,6 +1525,7 @@ function isSymbol(value) {
|
|
|
1496
1525
|
tryit,
|
|
1497
1526
|
uid,
|
|
1498
1527
|
unique,
|
|
1528
|
+
unzip,
|
|
1499
1529
|
upperize,
|
|
1500
1530
|
zip,
|
|
1501
1531
|
zipToObject
|
package/dist/radashi.d.cts
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,
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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
|
|
@@ -606,6 +621,9 @@ declare function debounce<TArgs extends any[]>({ delay }: {
|
|
|
606
621
|
delay: number;
|
|
607
622
|
}, func: (...args: TArgs) => any): DebounceFunction<TArgs>;
|
|
608
623
|
|
|
624
|
+
declare function flip<Args extends any[], Result>(fn: (...args: Args) => Result): (...args: Flip<Args>) => Result;
|
|
625
|
+
type Flip<T extends any[]> = T extends [infer A, infer B, ...infer R] ? [B, A, ...R] : never;
|
|
626
|
+
|
|
609
627
|
interface MemoOptions<TArgs extends any[]> {
|
|
610
628
|
key?: (...args: TArgs) => string;
|
|
611
629
|
ttl?: number;
|
|
@@ -726,9 +744,13 @@ declare function inRange(number: number, start: number, end: number): boolean;
|
|
|
726
744
|
*/
|
|
727
745
|
declare function round(value: number, precision?: number, toInteger?: (value: number) => number): number;
|
|
728
746
|
|
|
729
|
-
declare function toFloat
|
|
747
|
+
declare function toFloat(value: unknown): number;
|
|
748
|
+
declare function toFloat(value: unknown, defaultValue: number): number;
|
|
749
|
+
declare function toFloat<T>(value: unknown, defaultValue: T): number | Exclude<T, undefined>;
|
|
730
750
|
|
|
731
|
-
declare function toInt
|
|
751
|
+
declare function toInt(value: unknown): number;
|
|
752
|
+
declare function toInt(value: unknown, defaultValue: number): number;
|
|
753
|
+
declare function toInt<T>(value: unknown, defaultValue: T): number | Exclude<T, undefined>;
|
|
732
754
|
|
|
733
755
|
/**
|
|
734
756
|
* Merges two objects together recursivly into a new object applying
|
|
@@ -897,7 +919,7 @@ declare function draw<T>(array: readonly T[]): T | null;
|
|
|
897
919
|
*/
|
|
898
920
|
declare function random(min: number, max: number): number;
|
|
899
921
|
|
|
900
|
-
declare function shuffle<T>(array: readonly T[]): T[];
|
|
922
|
+
declare function shuffle<T>(array: readonly T[], random?: (min: number, max: number) => number): T[];
|
|
901
923
|
|
|
902
924
|
declare function uid(length: number, specials?: string): string;
|
|
903
925
|
|
|
@@ -995,7 +1017,7 @@ declare function title(str: string | null | undefined): string;
|
|
|
995
1017
|
*/
|
|
996
1018
|
declare function trim(str: string | null | undefined, charsToTrim?: string): string;
|
|
997
1019
|
|
|
998
|
-
declare const isArray: (value:
|
|
1020
|
+
declare const isArray: <Input>(value: Input) => value is readonly any[] extends ExtractNotAny<Input, readonly any[]> ? Extract<Input, readonly any[]> : any[] extends ExtractNotAny<Input, any[]> ? Extract<Input, any[]> : unknown[] extends Input ? unknown[] : never;
|
|
999
1021
|
|
|
1000
1022
|
declare function isDate(value: any): value is Date;
|
|
1001
1023
|
|
|
@@ -1039,4 +1061,27 @@ declare function isString(value: any): value is string;
|
|
|
1039
1061
|
|
|
1040
1062
|
declare function isSymbol(value: any): value is symbol;
|
|
1041
1063
|
|
|
1042
|
-
|
|
1064
|
+
/**
|
|
1065
|
+
* The `Any` class does not exist at runtime. It's used in type
|
|
1066
|
+
* definitions to detect an `any` type.
|
|
1067
|
+
*
|
|
1068
|
+
* ```ts
|
|
1069
|
+
* type IsAny<T> = [T] extends [Any] ? 'is any' : 'is not any'
|
|
1070
|
+
* ```
|
|
1071
|
+
*/
|
|
1072
|
+
declare class Any {
|
|
1073
|
+
private any;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Extracts `T` if `T` is not `any`, otherwise `never`.
|
|
1077
|
+
*
|
|
1078
|
+
* ```ts
|
|
1079
|
+
* type A = ExtractNotAny<any, string>
|
|
1080
|
+
* // ^? never
|
|
1081
|
+
* type B = ExtractNotAny<string | number, string>
|
|
1082
|
+
* // ^? string
|
|
1083
|
+
* ```
|
|
1084
|
+
*/
|
|
1085
|
+
type ExtractNotAny<T, U> = Extract<[T] extends [Any] ? never : T, U>;
|
|
1086
|
+
|
|
1087
|
+
export { AggregateError, Any, type DebounceFunction, type ExtractNotAny, type Flip, 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, flip, 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,
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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>(
|
|
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
|
|
@@ -606,6 +621,9 @@ declare function debounce<TArgs extends any[]>({ delay }: {
|
|
|
606
621
|
delay: number;
|
|
607
622
|
}, func: (...args: TArgs) => any): DebounceFunction<TArgs>;
|
|
608
623
|
|
|
624
|
+
declare function flip<Args extends any[], Result>(fn: (...args: Args) => Result): (...args: Flip<Args>) => Result;
|
|
625
|
+
type Flip<T extends any[]> = T extends [infer A, infer B, ...infer R] ? [B, A, ...R] : never;
|
|
626
|
+
|
|
609
627
|
interface MemoOptions<TArgs extends any[]> {
|
|
610
628
|
key?: (...args: TArgs) => string;
|
|
611
629
|
ttl?: number;
|
|
@@ -726,9 +744,13 @@ declare function inRange(number: number, start: number, end: number): boolean;
|
|
|
726
744
|
*/
|
|
727
745
|
declare function round(value: number, precision?: number, toInteger?: (value: number) => number): number;
|
|
728
746
|
|
|
729
|
-
declare function toFloat
|
|
747
|
+
declare function toFloat(value: unknown): number;
|
|
748
|
+
declare function toFloat(value: unknown, defaultValue: number): number;
|
|
749
|
+
declare function toFloat<T>(value: unknown, defaultValue: T): number | Exclude<T, undefined>;
|
|
730
750
|
|
|
731
|
-
declare function toInt
|
|
751
|
+
declare function toInt(value: unknown): number;
|
|
752
|
+
declare function toInt(value: unknown, defaultValue: number): number;
|
|
753
|
+
declare function toInt<T>(value: unknown, defaultValue: T): number | Exclude<T, undefined>;
|
|
732
754
|
|
|
733
755
|
/**
|
|
734
756
|
* Merges two objects together recursivly into a new object applying
|
|
@@ -897,7 +919,7 @@ declare function draw<T>(array: readonly T[]): T | null;
|
|
|
897
919
|
*/
|
|
898
920
|
declare function random(min: number, max: number): number;
|
|
899
921
|
|
|
900
|
-
declare function shuffle<T>(array: readonly T[]): T[];
|
|
922
|
+
declare function shuffle<T>(array: readonly T[], random?: (min: number, max: number) => number): T[];
|
|
901
923
|
|
|
902
924
|
declare function uid(length: number, specials?: string): string;
|
|
903
925
|
|
|
@@ -995,7 +1017,7 @@ declare function title(str: string | null | undefined): string;
|
|
|
995
1017
|
*/
|
|
996
1018
|
declare function trim(str: string | null | undefined, charsToTrim?: string): string;
|
|
997
1019
|
|
|
998
|
-
declare const isArray: (value:
|
|
1020
|
+
declare const isArray: <Input>(value: Input) => value is readonly any[] extends ExtractNotAny<Input, readonly any[]> ? Extract<Input, readonly any[]> : any[] extends ExtractNotAny<Input, any[]> ? Extract<Input, any[]> : unknown[] extends Input ? unknown[] : never;
|
|
999
1021
|
|
|
1000
1022
|
declare function isDate(value: any): value is Date;
|
|
1001
1023
|
|
|
@@ -1039,4 +1061,27 @@ declare function isString(value: any): value is string;
|
|
|
1039
1061
|
|
|
1040
1062
|
declare function isSymbol(value: any): value is symbol;
|
|
1041
1063
|
|
|
1042
|
-
|
|
1064
|
+
/**
|
|
1065
|
+
* The `Any` class does not exist at runtime. It's used in type
|
|
1066
|
+
* definitions to detect an `any` type.
|
|
1067
|
+
*
|
|
1068
|
+
* ```ts
|
|
1069
|
+
* type IsAny<T> = [T] extends [Any] ? 'is any' : 'is not any'
|
|
1070
|
+
* ```
|
|
1071
|
+
*/
|
|
1072
|
+
declare class Any {
|
|
1073
|
+
private any;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Extracts `T` if `T` is not `any`, otherwise `never`.
|
|
1077
|
+
*
|
|
1078
|
+
* ```ts
|
|
1079
|
+
* type A = ExtractNotAny<any, string>
|
|
1080
|
+
* // ^? never
|
|
1081
|
+
* type B = ExtractNotAny<string | number, string>
|
|
1082
|
+
* // ^? string
|
|
1083
|
+
* ```
|
|
1084
|
+
*/
|
|
1085
|
+
type ExtractNotAny<T, U> = Extract<[T] extends [Any] ? never : T, U>;
|
|
1086
|
+
|
|
1087
|
+
export { AggregateError, Any, type DebounceFunction, type ExtractNotAny, type Flip, 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, flip, 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,
|
|
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(
|
|
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(
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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(
|
|
141
|
-
if (!
|
|
153
|
+
function merge(prev, array, toKey) {
|
|
154
|
+
if (!array && !prev) {
|
|
142
155
|
return [];
|
|
143
156
|
}
|
|
144
|
-
if (!
|
|
145
|
-
return [...
|
|
157
|
+
if (!array) {
|
|
158
|
+
return [...prev];
|
|
146
159
|
}
|
|
147
|
-
if (!
|
|
160
|
+
if (!prev) {
|
|
148
161
|
return [];
|
|
149
162
|
}
|
|
150
|
-
if (!
|
|
151
|
-
return [...
|
|
163
|
+
if (!toKey) {
|
|
164
|
+
return [...prev];
|
|
152
165
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
|
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(
|
|
196
|
-
if (!
|
|
207
|
+
function replace(array, newItem, match) {
|
|
208
|
+
if (!array) {
|
|
197
209
|
return [];
|
|
198
210
|
}
|
|
199
211
|
if (newItem === void 0) {
|
|
200
|
-
return [...
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (match(
|
|
205
|
-
|
|
206
|
-
|
|
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
|
|
221
|
+
return out;
|
|
213
222
|
}
|
|
214
223
|
|
|
215
224
|
// src/array/replaceOrAppend.ts
|
|
216
|
-
function replaceOrAppend(
|
|
217
|
-
if (!
|
|
225
|
+
function replaceOrAppend(array, newItem, match) {
|
|
226
|
+
if (!array && !newItem) {
|
|
218
227
|
return [];
|
|
219
228
|
}
|
|
220
229
|
if (!newItem) {
|
|
221
|
-
return [...
|
|
230
|
+
return [...array];
|
|
222
231
|
}
|
|
223
|
-
if (!
|
|
232
|
+
if (!array) {
|
|
224
233
|
return [newItem];
|
|
225
234
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (match(
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
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(
|
|
282
|
-
return (
|
|
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(
|
|
302
|
-
if (!
|
|
308
|
+
function toggle(array, item, toKey, options) {
|
|
309
|
+
if (!array && !item) {
|
|
303
310
|
return [];
|
|
304
311
|
}
|
|
305
|
-
if (!
|
|
312
|
+
if (!array) {
|
|
306
313
|
return [item];
|
|
307
314
|
}
|
|
308
315
|
if (!item) {
|
|
309
|
-
return [...
|
|
316
|
+
return [...array];
|
|
310
317
|
}
|
|
311
318
|
const matcher = toKey ? (x, idx) => toKey(x, idx) === toKey(item, idx) : (x) => x === item;
|
|
312
|
-
const existing =
|
|
319
|
+
const existing = array.find(matcher);
|
|
313
320
|
if (existing) {
|
|
314
|
-
return
|
|
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 [...
|
|
325
|
+
return [...array, item];
|
|
319
326
|
}
|
|
320
|
-
return [item, ...
|
|
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/
|
|
340
|
-
function
|
|
346
|
+
// src/array/unzip.ts
|
|
347
|
+
function unzip(arrays) {
|
|
341
348
|
if (!arrays || !arrays.length) {
|
|
342
349
|
return [];
|
|
343
350
|
}
|
|
344
|
-
|
|
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
|
|
@@ -592,6 +612,11 @@ function debounce({ delay }, func) {
|
|
|
592
612
|
return debounced;
|
|
593
613
|
}
|
|
594
614
|
|
|
615
|
+
// src/curry/flip.ts
|
|
616
|
+
function flip(fn) {
|
|
617
|
+
return (arg2, arg1, ...args) => fn(arg1, arg2, ...args);
|
|
618
|
+
}
|
|
619
|
+
|
|
595
620
|
// src/curry/memo.ts
|
|
596
621
|
function memoize(cache, func, keyFunc, ttl) {
|
|
597
622
|
return function callWithMemo(...args) {
|
|
@@ -684,22 +709,14 @@ function round(value, precision, toInteger = Math.round) {
|
|
|
684
709
|
|
|
685
710
|
// src/number/toFloat.ts
|
|
686
711
|
function toFloat(value, defaultValue) {
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
return def;
|
|
690
|
-
}
|
|
691
|
-
const result = Number.parseFloat(value);
|
|
692
|
-
return Number.isNaN(result) ? def : result;
|
|
712
|
+
const parsedValue = isSymbol(value) ? Number.NaN : Number.parseFloat(value);
|
|
713
|
+
return Number.isNaN(parsedValue) ? defaultValue !== void 0 ? defaultValue : 0 : parsedValue;
|
|
693
714
|
}
|
|
694
715
|
|
|
695
716
|
// src/number/toInt.ts
|
|
696
717
|
function toInt(value, defaultValue) {
|
|
697
|
-
const
|
|
698
|
-
|
|
699
|
-
return def;
|
|
700
|
-
}
|
|
701
|
-
const result = Number.parseInt(value);
|
|
702
|
-
return Number.isNaN(result) ? def : result;
|
|
718
|
+
const parsedValue = isSymbol(value) ? Number.NaN : Number.parseInt(value);
|
|
719
|
+
return Number.isNaN(parsedValue) ? defaultValue !== void 0 ? defaultValue : 0 : parsedValue;
|
|
703
720
|
}
|
|
704
721
|
|
|
705
722
|
// src/object/assign.ts
|
|
@@ -972,8 +989,15 @@ function random(min2, max2) {
|
|
|
972
989
|
}
|
|
973
990
|
|
|
974
991
|
// src/random/shuffle.ts
|
|
975
|
-
function shuffle(array) {
|
|
976
|
-
|
|
992
|
+
function shuffle(array, random2 = random) {
|
|
993
|
+
const newArray = array.slice();
|
|
994
|
+
for (let idx = 0, randomIdx, item; idx < array.length; idx++) {
|
|
995
|
+
randomIdx = random2(0, array.length - 1);
|
|
996
|
+
item = newArray[randomIdx];
|
|
997
|
+
newArray[randomIdx] = newArray[idx];
|
|
998
|
+
newArray[idx] = item;
|
|
999
|
+
}
|
|
1000
|
+
return newArray;
|
|
977
1001
|
}
|
|
978
1002
|
|
|
979
1003
|
// src/random/uid.ts
|
|
@@ -1270,7 +1294,7 @@ function isString(value) {
|
|
|
1270
1294
|
|
|
1271
1295
|
// src/typed/isSymbol.ts
|
|
1272
1296
|
function isSymbol(value) {
|
|
1273
|
-
return
|
|
1297
|
+
return typeof value === "symbol";
|
|
1274
1298
|
}
|
|
1275
1299
|
export {
|
|
1276
1300
|
AggregateError,
|
|
@@ -1296,6 +1320,7 @@ export {
|
|
|
1296
1320
|
filterKey,
|
|
1297
1321
|
first,
|
|
1298
1322
|
flat,
|
|
1323
|
+
flip,
|
|
1299
1324
|
fork,
|
|
1300
1325
|
get,
|
|
1301
1326
|
group,
|
|
@@ -1328,6 +1353,7 @@ export {
|
|
|
1328
1353
|
mapEntries,
|
|
1329
1354
|
mapKeys,
|
|
1330
1355
|
mapValues,
|
|
1356
|
+
mapify,
|
|
1331
1357
|
max,
|
|
1332
1358
|
memo,
|
|
1333
1359
|
merge,
|
|
@@ -1370,6 +1396,7 @@ export {
|
|
|
1370
1396
|
tryit,
|
|
1371
1397
|
uid,
|
|
1372
1398
|
unique,
|
|
1399
|
+
unzip,
|
|
1373
1400
|
upperize,
|
|
1374
1401
|
zip,
|
|
1375
1402
|
zipToObject
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "radashi",
|
|
3
|
-
"version": "12.2.0-beta.
|
|
3
|
+
"version": "12.2.0-beta.c59abfd",
|
|
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": "
|
|
16
|
-
"
|
|
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"
|