radashi 12.2.0-beta.45f2ac3 → 12.2.0-beta.68f53c8
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/README.md +4 -10
- package/dist/index.cjs +23 -10
- package/dist/index.d.cts +20 -4
- package/dist/index.d.ts +20 -4
- package/dist/index.js +22 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,9 +51,7 @@
|
|
|
51
51
|
- ⚠️ **Beware:** Preview releases are not audited by the Radashi team. Always look at their
|
|
52
52
|
changes in the PR to ensure no malicious code was introduced.
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
<img src="https://github.com/radashi-org/radashi/raw/main/img/rule.png" width="100%" />
|
|
54
|
+
<img src="https://github.com/radashi-org/radashi/raw/b80a0e4/img/rule.png" width="100%" />
|
|
57
55
|
|
|
58
56
|
## Install
|
|
59
57
|
|
|
@@ -69,9 +67,7 @@ yarn add radashi
|
|
|
69
67
|
npm install radashi
|
|
70
68
|
```
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
<img src="https://github.com/radashi-org/radashi/raw/main/img/rule.png" width="100%" />
|
|
70
|
+
<img src="https://github.com/radashi-org/radashi/raw/b80a0e4/img/rule.png" width="100%" />
|
|
75
71
|
|
|
76
72
|
## Contributing
|
|
77
73
|
|
|
@@ -81,9 +77,7 @@ Contributions are welcome and appreciated! Check out the contributing guide befo
|
|
|
81
77
|
<img src="https://github.com/radashi-org/radashi/raw/main/img/contributing-button.png" alt="Contributing to Radashi" width="250px" />
|
|
82
78
|
</a>
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<img src="https://github.com/radashi-org/radashi/raw/main/img/rule.png" width="100%" />
|
|
80
|
+
<img src="https://github.com/radashi-org/radashi/raw/b80a0e4/img/rule.png" width="100%" />
|
|
87
81
|
|
|
88
82
|
## Changelog
|
|
89
83
|
|
|
@@ -97,6 +91,6 @@ This section documents the changes between the original `radash` library and thi
|
|
|
97
91
|
|
|
98
92
|
<div align="center">
|
|
99
93
|
<p align="center">
|
|
100
|
-
<img src="https://github.com/radashi-org/radashi/raw/
|
|
94
|
+
<img src="https://github.com/radashi-org/radashi/raw/46c8897/img/footer.png" alt="Radashi" width="100%" />
|
|
101
95
|
</p>
|
|
102
96
|
</div>
|
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ __export(src_exports, {
|
|
|
40
40
|
defer: () => defer,
|
|
41
41
|
diff: () => diff,
|
|
42
42
|
draw: () => draw,
|
|
43
|
+
filterKey: () => filterKey,
|
|
43
44
|
first: () => first,
|
|
44
45
|
flat: () => flat,
|
|
45
46
|
fork: () => fork,
|
|
@@ -315,9 +316,10 @@ var replaceOrAppend = (list2, newItem, match) => {
|
|
|
315
316
|
// src/array/select.ts
|
|
316
317
|
var select = (array, mapper, condition) => {
|
|
317
318
|
if (!array) return [];
|
|
319
|
+
let mapped;
|
|
318
320
|
return array.reduce((acc, item, index) => {
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
+
if (condition) condition(item, index) && acc.push(mapper(item, index));
|
|
322
|
+
else (mapped = mapper(item, index)) != null && acc.push(mapped);
|
|
321
323
|
return acc;
|
|
322
324
|
}, []);
|
|
323
325
|
};
|
|
@@ -363,13 +365,18 @@ var toggle = (list2, item, toKey, options) => {
|
|
|
363
365
|
|
|
364
366
|
// src/array/unique.ts
|
|
365
367
|
var unique = (array, toKey) => {
|
|
366
|
-
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
368
|
+
if (toKey) {
|
|
369
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
370
|
+
return array.reduce((acc, item) => {
|
|
371
|
+
const key = toKey(item);
|
|
372
|
+
if (!keys2.has(key)) {
|
|
373
|
+
keys2.add(key);
|
|
374
|
+
acc.push(item);
|
|
375
|
+
}
|
|
376
|
+
return acc;
|
|
377
|
+
}, []);
|
|
378
|
+
}
|
|
379
|
+
return [...new Set(array)];
|
|
373
380
|
};
|
|
374
381
|
|
|
375
382
|
// src/array/zip.ts
|
|
@@ -748,6 +755,11 @@ var crush = (value) => {
|
|
|
748
755
|
);
|
|
749
756
|
};
|
|
750
757
|
|
|
758
|
+
// src/object/filterKey.ts
|
|
759
|
+
var filterKey = (obj, key, keys2) => {
|
|
760
|
+
return isArray(keys2) ? Object.hasOwnProperty.call(obj, key) && keys2.includes(key) : keys2(obj[key], key, obj);
|
|
761
|
+
};
|
|
762
|
+
|
|
751
763
|
// src/object/get.ts
|
|
752
764
|
var get = (value, path, defaultValue) => {
|
|
753
765
|
const segments = path.split(/[\.\[\]]/g);
|
|
@@ -1040,7 +1052,7 @@ var trim = (str, charsToTrim = " ") => {
|
|
|
1040
1052
|
};
|
|
1041
1053
|
|
|
1042
1054
|
// src/typed/isArray.ts
|
|
1043
|
-
var isArray = Array.isArray;
|
|
1055
|
+
var isArray = /* @__PURE__ */ (() => Array.isArray)();
|
|
1044
1056
|
|
|
1045
1057
|
// src/typed/isDate.ts
|
|
1046
1058
|
var isDate = (value) => {
|
|
@@ -1174,6 +1186,7 @@ var isSymbol = (value) => {
|
|
|
1174
1186
|
defer,
|
|
1175
1187
|
diff,
|
|
1176
1188
|
draw,
|
|
1189
|
+
filterKey,
|
|
1177
1190
|
first,
|
|
1178
1191
|
flat,
|
|
1179
1192
|
fork,
|
package/dist/index.d.cts
CHANGED
|
@@ -156,7 +156,7 @@ declare const replaceOrAppend: <T>(list: readonly T[], newItem: T, match: (a: T,
|
|
|
156
156
|
* @example
|
|
157
157
|
* select([1, 2, 3, 4], x => x*x, x > 2) == [9, 16]
|
|
158
158
|
*/
|
|
159
|
-
declare const select: <T, K>(array: readonly T[], mapper: (item: T, index: number) => K, condition
|
|
159
|
+
declare const select: <T, K>(array: readonly T[], mapper: (item: T, index: number) => K, condition?: ((item: T, index: number) => boolean) | undefined) => K[];
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* Shift array items by n steps If n > 0 items will shift n steps to
|
|
@@ -196,7 +196,7 @@ declare const toggle: <T>(list: readonly T[], item: T, toKey?: ((item: T, idx: n
|
|
|
196
196
|
* Accepts an optional identity function to convert each item in the
|
|
197
197
|
* list to a comparable identity value
|
|
198
198
|
*/
|
|
199
|
-
declare const unique: <T, K
|
|
199
|
+
declare const unique: <T, K = T>(array: readonly T[], toKey?: ((item: T) => K) | undefined) => T[];
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
202
|
* Creates an array of grouped elements, the first of which contains
|
|
@@ -511,6 +511,22 @@ declare const construct: <TObject extends object>(obj: TObject) => object;
|
|
|
511
511
|
*/
|
|
512
512
|
declare const crush: <TValue extends object>(value: TValue) => object;
|
|
513
513
|
|
|
514
|
+
type KeyOf<T extends object> = object extends T ? keyof any : keyof T;
|
|
515
|
+
type ValueOf<T extends object> = object extends T ? unknown : T[keyof T];
|
|
516
|
+
type KeyFilterFunction<T extends object = object> = (value: ValueOf<T>, key: KeyOf<T>, obj: T) => boolean;
|
|
517
|
+
/**
|
|
518
|
+
* Functions can use this type to accept either an array of keys or a
|
|
519
|
+
* filter callback. This provides type safety for such a parameter
|
|
520
|
+
* type, whose value can then be passed into `matchKeys` to receive a
|
|
521
|
+
* matching function.
|
|
522
|
+
*/
|
|
523
|
+
type KeyFilter<T extends object = object, Key extends keyof any = keyof any> = KeyFilterFunction<T> | readonly Key[];
|
|
524
|
+
/**
|
|
525
|
+
* Returns true if the key is in the “keys array” or if the “filter
|
|
526
|
+
* function” returns true.
|
|
527
|
+
*/
|
|
528
|
+
declare const filterKey: (obj: object, key: string, keys: KeyFilter) => boolean;
|
|
529
|
+
|
|
514
530
|
/**
|
|
515
531
|
* Dynamically get a nested value from an array or object with a
|
|
516
532
|
* string.
|
|
@@ -699,7 +715,7 @@ declare const title: (str: string | null | undefined) => string;
|
|
|
699
715
|
*/
|
|
700
716
|
declare const trim: (str: string | null | undefined, charsToTrim?: string) => string;
|
|
701
717
|
|
|
702
|
-
declare const isArray: (
|
|
718
|
+
declare const isArray: (value: unknown) => value is readonly any[];
|
|
703
719
|
|
|
704
720
|
declare const isDate: (value: any) => value is Date;
|
|
705
721
|
|
|
@@ -743,4 +759,4 @@ declare const isString: (value: any) => value is string;
|
|
|
743
759
|
|
|
744
760
|
declare const isSymbol: (value: any) => value is symbol;
|
|
745
761
|
|
|
746
|
-
export { AggregateError, type DebounceFunction, type RetryOptions, type ThrottledFunction, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, 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, select, 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 };
|
|
762
|
+
export { AggregateError, type DebounceFunction, type KeyFilter, type KeyFilterFunction, type RetryOptions, type ThrottledFunction, 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, select, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -156,7 +156,7 @@ declare const replaceOrAppend: <T>(list: readonly T[], newItem: T, match: (a: T,
|
|
|
156
156
|
* @example
|
|
157
157
|
* select([1, 2, 3, 4], x => x*x, x > 2) == [9, 16]
|
|
158
158
|
*/
|
|
159
|
-
declare const select: <T, K>(array: readonly T[], mapper: (item: T, index: number) => K, condition
|
|
159
|
+
declare const select: <T, K>(array: readonly T[], mapper: (item: T, index: number) => K, condition?: ((item: T, index: number) => boolean) | undefined) => K[];
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* Shift array items by n steps If n > 0 items will shift n steps to
|
|
@@ -196,7 +196,7 @@ declare const toggle: <T>(list: readonly T[], item: T, toKey?: ((item: T, idx: n
|
|
|
196
196
|
* Accepts an optional identity function to convert each item in the
|
|
197
197
|
* list to a comparable identity value
|
|
198
198
|
*/
|
|
199
|
-
declare const unique: <T, K
|
|
199
|
+
declare const unique: <T, K = T>(array: readonly T[], toKey?: ((item: T) => K) | undefined) => T[];
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
202
|
* Creates an array of grouped elements, the first of which contains
|
|
@@ -511,6 +511,22 @@ declare const construct: <TObject extends object>(obj: TObject) => object;
|
|
|
511
511
|
*/
|
|
512
512
|
declare const crush: <TValue extends object>(value: TValue) => object;
|
|
513
513
|
|
|
514
|
+
type KeyOf<T extends object> = object extends T ? keyof any : keyof T;
|
|
515
|
+
type ValueOf<T extends object> = object extends T ? unknown : T[keyof T];
|
|
516
|
+
type KeyFilterFunction<T extends object = object> = (value: ValueOf<T>, key: KeyOf<T>, obj: T) => boolean;
|
|
517
|
+
/**
|
|
518
|
+
* Functions can use this type to accept either an array of keys or a
|
|
519
|
+
* filter callback. This provides type safety for such a parameter
|
|
520
|
+
* type, whose value can then be passed into `matchKeys` to receive a
|
|
521
|
+
* matching function.
|
|
522
|
+
*/
|
|
523
|
+
type KeyFilter<T extends object = object, Key extends keyof any = keyof any> = KeyFilterFunction<T> | readonly Key[];
|
|
524
|
+
/**
|
|
525
|
+
* Returns true if the key is in the “keys array” or if the “filter
|
|
526
|
+
* function” returns true.
|
|
527
|
+
*/
|
|
528
|
+
declare const filterKey: (obj: object, key: string, keys: KeyFilter) => boolean;
|
|
529
|
+
|
|
514
530
|
/**
|
|
515
531
|
* Dynamically get a nested value from an array or object with a
|
|
516
532
|
* string.
|
|
@@ -699,7 +715,7 @@ declare const title: (str: string | null | undefined) => string;
|
|
|
699
715
|
*/
|
|
700
716
|
declare const trim: (str: string | null | undefined, charsToTrim?: string) => string;
|
|
701
717
|
|
|
702
|
-
declare const isArray: (
|
|
718
|
+
declare const isArray: (value: unknown) => value is readonly any[];
|
|
703
719
|
|
|
704
720
|
declare const isDate: (value: any) => value is Date;
|
|
705
721
|
|
|
@@ -743,4 +759,4 @@ declare const isString: (value: any) => value is string;
|
|
|
743
759
|
|
|
744
760
|
declare const isSymbol: (value: any) => value is symbol;
|
|
745
761
|
|
|
746
|
-
export { AggregateError, type DebounceFunction, type RetryOptions, type ThrottledFunction, all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, 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, select, 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 };
|
|
762
|
+
export { AggregateError, type DebounceFunction, type KeyFilter, type KeyFilterFunction, type RetryOptions, type ThrottledFunction, 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, select, 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 };
|
package/dist/index.js
CHANGED
|
@@ -193,9 +193,10 @@ var replaceOrAppend = (list2, newItem, match) => {
|
|
|
193
193
|
// src/array/select.ts
|
|
194
194
|
var select = (array, mapper, condition) => {
|
|
195
195
|
if (!array) return [];
|
|
196
|
+
let mapped;
|
|
196
197
|
return array.reduce((acc, item, index) => {
|
|
197
|
-
if (
|
|
198
|
-
|
|
198
|
+
if (condition) condition(item, index) && acc.push(mapper(item, index));
|
|
199
|
+
else (mapped = mapper(item, index)) != null && acc.push(mapped);
|
|
199
200
|
return acc;
|
|
200
201
|
}, []);
|
|
201
202
|
};
|
|
@@ -241,13 +242,18 @@ var toggle = (list2, item, toKey, options) => {
|
|
|
241
242
|
|
|
242
243
|
// src/array/unique.ts
|
|
243
244
|
var unique = (array, toKey) => {
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
245
|
+
if (toKey) {
|
|
246
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
247
|
+
return array.reduce((acc, item) => {
|
|
248
|
+
const key = toKey(item);
|
|
249
|
+
if (!keys2.has(key)) {
|
|
250
|
+
keys2.add(key);
|
|
251
|
+
acc.push(item);
|
|
252
|
+
}
|
|
253
|
+
return acc;
|
|
254
|
+
}, []);
|
|
255
|
+
}
|
|
256
|
+
return [...new Set(array)];
|
|
251
257
|
};
|
|
252
258
|
|
|
253
259
|
// src/array/zip.ts
|
|
@@ -626,6 +632,11 @@ var crush = (value) => {
|
|
|
626
632
|
);
|
|
627
633
|
};
|
|
628
634
|
|
|
635
|
+
// src/object/filterKey.ts
|
|
636
|
+
var filterKey = (obj, key, keys2) => {
|
|
637
|
+
return isArray(keys2) ? Object.hasOwnProperty.call(obj, key) && keys2.includes(key) : keys2(obj[key], key, obj);
|
|
638
|
+
};
|
|
639
|
+
|
|
629
640
|
// src/object/get.ts
|
|
630
641
|
var get = (value, path, defaultValue) => {
|
|
631
642
|
const segments = path.split(/[\.\[\]]/g);
|
|
@@ -918,7 +929,7 @@ var trim = (str, charsToTrim = " ") => {
|
|
|
918
929
|
};
|
|
919
930
|
|
|
920
931
|
// src/typed/isArray.ts
|
|
921
|
-
var isArray = Array.isArray;
|
|
932
|
+
var isArray = /* @__PURE__ */ (() => Array.isArray)();
|
|
922
933
|
|
|
923
934
|
// src/typed/isDate.ts
|
|
924
935
|
var isDate = (value) => {
|
|
@@ -1051,6 +1062,7 @@ export {
|
|
|
1051
1062
|
defer,
|
|
1052
1063
|
diff,
|
|
1053
1064
|
draw,
|
|
1065
|
+
filterKey,
|
|
1054
1066
|
first,
|
|
1055
1067
|
flat,
|
|
1056
1068
|
fork,
|