radashi 12.4.0 → 12.5.0-beta.6d5c035
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/radashi.cjs +28 -6
- package/dist/radashi.d.cts +75 -11
- package/dist/radashi.d.ts +75 -11
- package/dist/radashi.js +27 -7
- package/package.json +3 -3
package/dist/radashi.cjs
CHANGED
|
@@ -54,6 +54,20 @@ function cluster(array, size = 2) {
|
|
|
54
54
|
return clusters;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// src/array/concat.ts
|
|
58
|
+
function concat(...values) {
|
|
59
|
+
const result = [];
|
|
60
|
+
const append = (value) => value != null && result.push(value);
|
|
61
|
+
for (const value of values) {
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
value.forEach(append);
|
|
64
|
+
} else {
|
|
65
|
+
append(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
57
71
|
// src/array/counting.ts
|
|
58
72
|
function counting(array, identity) {
|
|
59
73
|
if (!array) {
|
|
@@ -163,8 +177,8 @@ function list(startOrLength, end, valueOrMapper, step) {
|
|
|
163
177
|
// src/array/mapify.ts
|
|
164
178
|
function mapify(array, getKey, getValue = (item) => item) {
|
|
165
179
|
const map2 = /* @__PURE__ */ new Map();
|
|
166
|
-
for (const item of array) {
|
|
167
|
-
map2.set(getKey(item,
|
|
180
|
+
for (const [index, item] of array.entries()) {
|
|
181
|
+
map2.set(getKey(item, index), getValue(item, index));
|
|
168
182
|
}
|
|
169
183
|
return map2;
|
|
170
184
|
}
|
|
@@ -204,6 +218,15 @@ function objectify(array, getKey, getValue = (item) => item) {
|
|
|
204
218
|
);
|
|
205
219
|
}
|
|
206
220
|
|
|
221
|
+
// src/array/pluck.ts
|
|
222
|
+
function pluck(array, mappings) {
|
|
223
|
+
return array.map(
|
|
224
|
+
mappings ? (item) => mappings.map(
|
|
225
|
+
(mapping) => isFunction(mapping) ? mapping(item) : item[mapping]
|
|
226
|
+
) : Object.values
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
207
230
|
// src/array/remove.ts
|
|
208
231
|
function remove(array, predicate) {
|
|
209
232
|
return array.filter((item) => !predicate(item));
|
|
@@ -881,9 +904,6 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
|
|
|
881
904
|
const final = end ?? startOrLength;
|
|
882
905
|
for (let i = start; i <= final; i += step) {
|
|
883
906
|
yield mapper(i);
|
|
884
|
-
if (i + step > final) {
|
|
885
|
-
break;
|
|
886
|
-
}
|
|
887
907
|
}
|
|
888
908
|
}
|
|
889
909
|
|
|
@@ -1040,7 +1060,7 @@ function crush(value) {
|
|
|
1040
1060
|
|
|
1041
1061
|
// src/object/filterKey.ts
|
|
1042
1062
|
function filterKey(obj, key, filter) {
|
|
1043
|
-
return Object.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
|
|
1063
|
+
return Object.prototype.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
|
|
1044
1064
|
}
|
|
1045
1065
|
|
|
1046
1066
|
// src/object/get.ts
|
|
@@ -1840,6 +1860,7 @@ exports.clone = clone;
|
|
|
1840
1860
|
exports.cloneDeep = cloneDeep;
|
|
1841
1861
|
exports.cluster = cluster;
|
|
1842
1862
|
exports.compose = compose;
|
|
1863
|
+
exports.concat = concat;
|
|
1843
1864
|
exports.construct = construct;
|
|
1844
1865
|
exports.counting = counting;
|
|
1845
1866
|
exports.crush = crush;
|
|
@@ -1918,6 +1939,7 @@ exports.partial = partial;
|
|
|
1918
1939
|
exports.partob = partob;
|
|
1919
1940
|
exports.pascal = pascal;
|
|
1920
1941
|
exports.pick = pick;
|
|
1942
|
+
exports.pluck = pluck;
|
|
1921
1943
|
exports.proxied = proxied;
|
|
1922
1944
|
exports.random = random;
|
|
1923
1945
|
exports.range = range;
|
package/dist/radashi.d.cts
CHANGED
|
@@ -110,6 +110,26 @@ type CastArrayIfExists<T> = [T] extends [never] ? never[] : [unknown] extends [T
|
|
|
110
110
|
*/
|
|
111
111
|
declare function cluster<T>(array: readonly T[], size?: number): T[][];
|
|
112
112
|
|
|
113
|
+
type Concat<T extends readonly any[]> = T[number] extends infer TElement ? (TElement extends readonly (infer TNestedElement)[] ? Exclude<TNestedElement, undefined | null> : Exclude<TElement, undefined | null>)[] : unknown[];
|
|
114
|
+
/**
|
|
115
|
+
* Flattens and filters nullish values from arguments, returning a new
|
|
116
|
+
* array containing only the non-nullish elements. Nested arrays are
|
|
117
|
+
* flattened one level deep.
|
|
118
|
+
*
|
|
119
|
+
* @see https://radashi.js.org/reference/array/concat
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const result = _.concat('', ['a'], undefined, [null, 'b'])
|
|
123
|
+
* // => ['', 'a', 'b']
|
|
124
|
+
* ```
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const result = _.concat(1, [2, [3]], null)
|
|
128
|
+
* // => [1, 2, [3]] // Note: only flattens one level
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function concat<T extends readonly [any, any, ...any[]]>(...values: T): Concat<T>;
|
|
132
|
+
|
|
113
133
|
/**
|
|
114
134
|
* Counts the occurrences of each unique value returned by the `identity`
|
|
115
135
|
* function when applied to each item in the array.
|
|
@@ -332,6 +352,47 @@ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item:
|
|
|
332
352
|
*/
|
|
333
353
|
declare function objectify<T, Key extends string | number | symbol, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Record<Key, Value>;
|
|
334
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Extracts values from an array of objects based on specified
|
|
357
|
+
* mappings. Useful for extracting multiple properties from an array
|
|
358
|
+
* of objects (e.g. for tabular data). Also supports “computed
|
|
359
|
+
* properties” via mapping functions, which can combine and transform
|
|
360
|
+
* values on-the-fly.
|
|
361
|
+
*
|
|
362
|
+
* - If mappings are provided, returns an array of arrays where each
|
|
363
|
+
* inner array contains the values extracted by applying each
|
|
364
|
+
* mapping to the corresponding object.
|
|
365
|
+
* - If no mappings are provided, returns an array of arrays
|
|
366
|
+
* containing all values of each object.
|
|
367
|
+
*
|
|
368
|
+
* @see https://radashi.js.org/reference/array/pluck
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* interface God {
|
|
372
|
+
* name: string;
|
|
373
|
+
* power: number;
|
|
374
|
+
* domain: string;
|
|
375
|
+
* }
|
|
376
|
+
*
|
|
377
|
+
* const gods: God[] = [
|
|
378
|
+
* { name: 'Ra', power: 100, domain: 'Sun' },
|
|
379
|
+
* { name: 'Zeus', power: 98, domain: 'Lightning' },
|
|
380
|
+
* { name: 'Loki', power: 72, domain: 'Tricks' }
|
|
381
|
+
* ];
|
|
382
|
+
*
|
|
383
|
+
* // Extract a set of properties
|
|
384
|
+
* pluck(gods, ['power', 'domain']);
|
|
385
|
+
* // [[100, 'Sun'], [98, 'Lightning'], [72, 'Tricks']]
|
|
386
|
+
*
|
|
387
|
+
* // Extract all properties
|
|
388
|
+
* pluck(gods);
|
|
389
|
+
* // [['Ra', 100, 'Sun'], ['Zeus', 98, 'Lightning'], ['Loki', 72, 'Tricks']]
|
|
390
|
+
* ```
|
|
391
|
+
* @version 12.5.0
|
|
392
|
+
*/
|
|
393
|
+
declare function pluck<T extends object, TMapping extends Mapping<T>>(array: readonly T[], mappings: readonly TMapping[]): MappedOutput<TMapping, T>[];
|
|
394
|
+
declare function pluck<T extends object>(array: readonly T[], mappings?: readonly Mapping<T>[]): unknown[];
|
|
395
|
+
|
|
335
396
|
/**
|
|
336
397
|
* Removes elements from an array based on the specified predicate
|
|
337
398
|
* function.
|
|
@@ -804,6 +865,11 @@ declare function retry<TResponse>(options: RetryOptions, func: (exit: (err: any)
|
|
|
804
865
|
*/
|
|
805
866
|
declare function sleep(milliseconds: number): Promise<void>;
|
|
806
867
|
|
|
868
|
+
declare class TimeoutError extends Error {
|
|
869
|
+
name: string;
|
|
870
|
+
constructor(message?: string);
|
|
871
|
+
}
|
|
872
|
+
|
|
807
873
|
/**
|
|
808
874
|
* The `timeout` function creates a promise that rejects after a
|
|
809
875
|
* specified delay, with an optional custom error message or error
|
|
@@ -841,11 +907,6 @@ ms: number,
|
|
|
841
907
|
*/
|
|
842
908
|
error?: string | (() => TError)): Promise<never>;
|
|
843
909
|
|
|
844
|
-
declare class TimeoutError extends Error {
|
|
845
|
-
name: string;
|
|
846
|
-
constructor(message?: string);
|
|
847
|
-
}
|
|
848
|
-
|
|
849
910
|
interface BigInt {
|
|
850
911
|
/**
|
|
851
912
|
* Returns a string representation of an object.
|
|
@@ -1398,14 +1459,17 @@ type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
|
1398
1459
|
type StrictExtract<T, U> = SwitchNever<Extract<SwitchAny<T, unknown>, U>, unknown>;
|
|
1399
1460
|
/**
|
|
1400
1461
|
* Resolve a type union of property name literals within type `T`
|
|
1401
|
-
* whose property values are assignable to type `
|
|
1462
|
+
* whose property values are assignable to type `TConstraint`. If `T`
|
|
1463
|
+
* is a primitive, it's first transformed into its boxed equivalent
|
|
1464
|
+
* (e.g. `string` becomes `String`, `number` becomes `Number`, and so
|
|
1465
|
+
* on).
|
|
1402
1466
|
*
|
|
1403
1467
|
* Use case: “I want to know which properties of `T` are compatible
|
|
1404
|
-
* with `
|
|
1468
|
+
* with `TConstraint`.”
|
|
1405
1469
|
*/
|
|
1406
|
-
type CompatibleProperty<T,
|
|
1407
|
-
[P in keyof
|
|
1408
|
-
}[keyof
|
|
1470
|
+
type CompatibleProperty<T, TConstraint> = [T] extends [Any] ? keyof any : T extends null | undefined ? never : (T extends object ? T : BoxedPrimitive<T>) extends infer TObject ? {
|
|
1471
|
+
[P in keyof TObject]: TObject[P] extends TConstraint ? P : never;
|
|
1472
|
+
}[keyof TObject] : never;
|
|
1409
1473
|
/**
|
|
1410
1474
|
* A value that can be reliably compared with JavaScript comparison
|
|
1411
1475
|
* operators (e.g. `>`, `>=`, etc).
|
|
@@ -3717,4 +3781,4 @@ declare function isWeakMap<K extends WeakKey = WeakKey, V = unknown>(value: unkn
|
|
|
3717
3781
|
*/
|
|
3718
3782
|
declare function isWeakSet<T extends WeakKey = WeakKey>(value: unknown): value is WeakSet<T>;
|
|
3719
3783
|
|
|
3720
|
-
export { AggregateErrorOrPolyfill as AggregateError, Any, type Assign, type BoxedPrimitive, type BuiltInType, type CastArray, type CastArrayIfExists, type Class, type CloningStrategy, type Comparable, type ComparableProperty, type Comparator, type ComparatorMapping, type CompatibleProperty, type Crush, type CustomClass, type CustomClassRegistry, type DebounceFunction, type DebounceOptions, DefaultCloningStrategy, type Err, type ExtractArray, type ExtractClass, type ExtractMap, type ExtractNotAny, type ExtractSet, type Falsy, FastCloningStrategy, type FilteredKeys, type Flip, type Intersect, type IsExactType, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MappedInput, type MappedOutput, type Mapping, type MappingFunction, type MemoOptions, type NoInfer, type Ok, type OnceFunction, type OptionalKeys, type OptionalMapping, type ParallelOptions, type Primitive, type PromiseWithResolvers, type RequiredKeys, type Result, type ResultPromise, type RetryOptions, type Series, type Simplify, type StrictExtract, type SwitchAny, type SwitchNever, type ThrottledFunction, TimeoutError, type ToEmpty, type ToEmptyAble, type TraverseContext, type TraverseOptions, type TraverseVisitor, type TryitResult, type TypedArray, type UppercaseKeys, all, alphabetical, always, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isAsyncIterable, isBigInt, isBoolean, isClass, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
|
|
3784
|
+
export { AggregateErrorOrPolyfill as AggregateError, Any, type Assign, type BoxedPrimitive, type BuiltInType, type CastArray, type CastArrayIfExists, type Class, type CloningStrategy, type Comparable, type ComparableProperty, type Comparator, type ComparatorMapping, type CompatibleProperty, type Concat, type Crush, type CustomClass, type CustomClassRegistry, type DebounceFunction, type DebounceOptions, DefaultCloningStrategy, type Err, type ExtractArray, type ExtractClass, type ExtractMap, type ExtractNotAny, type ExtractSet, type Falsy, FastCloningStrategy, type FilteredKeys, type Flip, type Intersect, type IsExactType, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MappedInput, type MappedOutput, type Mapping, type MappingFunction, type MemoOptions, type NoInfer, type Ok, type OnceFunction, type OptionalKeys, type OptionalMapping, type ParallelOptions, type Primitive, type PromiseWithResolvers, type RequiredKeys, type Result, type ResultPromise, type RetryOptions, type Series, type Simplify, type StrictExtract, type SwitchAny, type SwitchNever, type ThrottledFunction, TimeoutError, type ToEmpty, type ToEmptyAble, type TraverseContext, type TraverseOptions, type TraverseVisitor, type TryitResult, type TypedArray, type UppercaseKeys, all, alphabetical, always, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, concat, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isAsyncIterable, isBigInt, isBoolean, isClass, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, partial, partob, pascal, pick, pluck, proxied, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
|
package/dist/radashi.d.ts
CHANGED
|
@@ -110,6 +110,26 @@ type CastArrayIfExists<T> = [T] extends [never] ? never[] : [unknown] extends [T
|
|
|
110
110
|
*/
|
|
111
111
|
declare function cluster<T>(array: readonly T[], size?: number): T[][];
|
|
112
112
|
|
|
113
|
+
type Concat<T extends readonly any[]> = T[number] extends infer TElement ? (TElement extends readonly (infer TNestedElement)[] ? Exclude<TNestedElement, undefined | null> : Exclude<TElement, undefined | null>)[] : unknown[];
|
|
114
|
+
/**
|
|
115
|
+
* Flattens and filters nullish values from arguments, returning a new
|
|
116
|
+
* array containing only the non-nullish elements. Nested arrays are
|
|
117
|
+
* flattened one level deep.
|
|
118
|
+
*
|
|
119
|
+
* @see https://radashi.js.org/reference/array/concat
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const result = _.concat('', ['a'], undefined, [null, 'b'])
|
|
123
|
+
* // => ['', 'a', 'b']
|
|
124
|
+
* ```
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const result = _.concat(1, [2, [3]], null)
|
|
128
|
+
* // => [1, 2, [3]] // Note: only flattens one level
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function concat<T extends readonly [any, any, ...any[]]>(...values: T): Concat<T>;
|
|
132
|
+
|
|
113
133
|
/**
|
|
114
134
|
* Counts the occurrences of each unique value returned by the `identity`
|
|
115
135
|
* function when applied to each item in the array.
|
|
@@ -332,6 +352,47 @@ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item:
|
|
|
332
352
|
*/
|
|
333
353
|
declare function objectify<T, Key extends string | number | symbol, Value = T>(array: readonly T[], getKey: (item: T) => Key, getValue?: (item: T) => Value): Record<Key, Value>;
|
|
334
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Extracts values from an array of objects based on specified
|
|
357
|
+
* mappings. Useful for extracting multiple properties from an array
|
|
358
|
+
* of objects (e.g. for tabular data). Also supports “computed
|
|
359
|
+
* properties” via mapping functions, which can combine and transform
|
|
360
|
+
* values on-the-fly.
|
|
361
|
+
*
|
|
362
|
+
* - If mappings are provided, returns an array of arrays where each
|
|
363
|
+
* inner array contains the values extracted by applying each
|
|
364
|
+
* mapping to the corresponding object.
|
|
365
|
+
* - If no mappings are provided, returns an array of arrays
|
|
366
|
+
* containing all values of each object.
|
|
367
|
+
*
|
|
368
|
+
* @see https://radashi.js.org/reference/array/pluck
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* interface God {
|
|
372
|
+
* name: string;
|
|
373
|
+
* power: number;
|
|
374
|
+
* domain: string;
|
|
375
|
+
* }
|
|
376
|
+
*
|
|
377
|
+
* const gods: God[] = [
|
|
378
|
+
* { name: 'Ra', power: 100, domain: 'Sun' },
|
|
379
|
+
* { name: 'Zeus', power: 98, domain: 'Lightning' },
|
|
380
|
+
* { name: 'Loki', power: 72, domain: 'Tricks' }
|
|
381
|
+
* ];
|
|
382
|
+
*
|
|
383
|
+
* // Extract a set of properties
|
|
384
|
+
* pluck(gods, ['power', 'domain']);
|
|
385
|
+
* // [[100, 'Sun'], [98, 'Lightning'], [72, 'Tricks']]
|
|
386
|
+
*
|
|
387
|
+
* // Extract all properties
|
|
388
|
+
* pluck(gods);
|
|
389
|
+
* // [['Ra', 100, 'Sun'], ['Zeus', 98, 'Lightning'], ['Loki', 72, 'Tricks']]
|
|
390
|
+
* ```
|
|
391
|
+
* @version 12.5.0
|
|
392
|
+
*/
|
|
393
|
+
declare function pluck<T extends object, TMapping extends Mapping<T>>(array: readonly T[], mappings: readonly TMapping[]): MappedOutput<TMapping, T>[];
|
|
394
|
+
declare function pluck<T extends object>(array: readonly T[], mappings?: readonly Mapping<T>[]): unknown[];
|
|
395
|
+
|
|
335
396
|
/**
|
|
336
397
|
* Removes elements from an array based on the specified predicate
|
|
337
398
|
* function.
|
|
@@ -804,6 +865,11 @@ declare function retry<TResponse>(options: RetryOptions, func: (exit: (err: any)
|
|
|
804
865
|
*/
|
|
805
866
|
declare function sleep(milliseconds: number): Promise<void>;
|
|
806
867
|
|
|
868
|
+
declare class TimeoutError extends Error {
|
|
869
|
+
name: string;
|
|
870
|
+
constructor(message?: string);
|
|
871
|
+
}
|
|
872
|
+
|
|
807
873
|
/**
|
|
808
874
|
* The `timeout` function creates a promise that rejects after a
|
|
809
875
|
* specified delay, with an optional custom error message or error
|
|
@@ -841,11 +907,6 @@ ms: number,
|
|
|
841
907
|
*/
|
|
842
908
|
error?: string | (() => TError)): Promise<never>;
|
|
843
909
|
|
|
844
|
-
declare class TimeoutError extends Error {
|
|
845
|
-
name: string;
|
|
846
|
-
constructor(message?: string);
|
|
847
|
-
}
|
|
848
|
-
|
|
849
910
|
interface BigInt {
|
|
850
911
|
/**
|
|
851
912
|
* Returns a string representation of an object.
|
|
@@ -1398,14 +1459,17 @@ type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
|
1398
1459
|
type StrictExtract<T, U> = SwitchNever<Extract<SwitchAny<T, unknown>, U>, unknown>;
|
|
1399
1460
|
/**
|
|
1400
1461
|
* Resolve a type union of property name literals within type `T`
|
|
1401
|
-
* whose property values are assignable to type `
|
|
1462
|
+
* whose property values are assignable to type `TConstraint`. If `T`
|
|
1463
|
+
* is a primitive, it's first transformed into its boxed equivalent
|
|
1464
|
+
* (e.g. `string` becomes `String`, `number` becomes `Number`, and so
|
|
1465
|
+
* on).
|
|
1402
1466
|
*
|
|
1403
1467
|
* Use case: “I want to know which properties of `T` are compatible
|
|
1404
|
-
* with `
|
|
1468
|
+
* with `TConstraint`.”
|
|
1405
1469
|
*/
|
|
1406
|
-
type CompatibleProperty<T,
|
|
1407
|
-
[P in keyof
|
|
1408
|
-
}[keyof
|
|
1470
|
+
type CompatibleProperty<T, TConstraint> = [T] extends [Any] ? keyof any : T extends null | undefined ? never : (T extends object ? T : BoxedPrimitive<T>) extends infer TObject ? {
|
|
1471
|
+
[P in keyof TObject]: TObject[P] extends TConstraint ? P : never;
|
|
1472
|
+
}[keyof TObject] : never;
|
|
1409
1473
|
/**
|
|
1410
1474
|
* A value that can be reliably compared with JavaScript comparison
|
|
1411
1475
|
* operators (e.g. `>`, `>=`, etc).
|
|
@@ -3717,4 +3781,4 @@ declare function isWeakMap<K extends WeakKey = WeakKey, V = unknown>(value: unkn
|
|
|
3717
3781
|
*/
|
|
3718
3782
|
declare function isWeakSet<T extends WeakKey = WeakKey>(value: unknown): value is WeakSet<T>;
|
|
3719
3783
|
|
|
3720
|
-
export { AggregateErrorOrPolyfill as AggregateError, Any, type Assign, type BoxedPrimitive, type BuiltInType, type CastArray, type CastArrayIfExists, type Class, type CloningStrategy, type Comparable, type ComparableProperty, type Comparator, type ComparatorMapping, type CompatibleProperty, type Crush, type CustomClass, type CustomClassRegistry, type DebounceFunction, type DebounceOptions, DefaultCloningStrategy, type Err, type ExtractArray, type ExtractClass, type ExtractMap, type ExtractNotAny, type ExtractSet, type Falsy, FastCloningStrategy, type FilteredKeys, type Flip, type Intersect, type IsExactType, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MappedInput, type MappedOutput, type Mapping, type MappingFunction, type MemoOptions, type NoInfer, type Ok, type OnceFunction, type OptionalKeys, type OptionalMapping, type ParallelOptions, type Primitive, type PromiseWithResolvers, type RequiredKeys, type Result, type ResultPromise, type RetryOptions, type Series, type Simplify, type StrictExtract, type SwitchAny, type SwitchNever, type ThrottledFunction, TimeoutError, type ToEmpty, type ToEmptyAble, type TraverseContext, type TraverseOptions, type TraverseVisitor, type TryitResult, type TypedArray, type UppercaseKeys, all, alphabetical, always, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isAsyncIterable, isBigInt, isBoolean, isClass, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
|
|
3784
|
+
export { AggregateErrorOrPolyfill as AggregateError, Any, type Assign, type BoxedPrimitive, type BuiltInType, type CastArray, type CastArrayIfExists, type Class, type CloningStrategy, type Comparable, type ComparableProperty, type Comparator, type ComparatorMapping, type CompatibleProperty, type Concat, type Crush, type CustomClass, type CustomClassRegistry, type DebounceFunction, type DebounceOptions, DefaultCloningStrategy, type Err, type ExtractArray, type ExtractClass, type ExtractMap, type ExtractNotAny, type ExtractSet, type Falsy, FastCloningStrategy, type FilteredKeys, type Flip, type Intersect, type IsExactType, type KeyFilter, type KeyFilterFunction, type LowercaseKeys, type MappedInput, type MappedOutput, type Mapping, type MappingFunction, type MemoOptions, type NoInfer, type Ok, type OnceFunction, type OptionalKeys, type OptionalMapping, type ParallelOptions, type Primitive, type PromiseWithResolvers, type RequiredKeys, type Result, type ResultPromise, type RetryOptions, type Series, type Simplify, type StrictExtract, type SwitchAny, type SwitchNever, type ThrottledFunction, TimeoutError, type ToEmpty, type ToEmptyAble, type TraverseContext, type TraverseOptions, type TraverseVisitor, type TryitResult, type TypedArray, type UppercaseKeys, all, alphabetical, always, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, concat, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isAsyncIterable, isBigInt, isBoolean, isClass, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, partial, partob, pascal, pick, pluck, proxied, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
|
package/dist/radashi.js
CHANGED
|
@@ -52,6 +52,20 @@ function cluster(array, size = 2) {
|
|
|
52
52
|
return clusters;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// src/array/concat.ts
|
|
56
|
+
function concat(...values) {
|
|
57
|
+
const result = [];
|
|
58
|
+
const append = (value) => value != null && result.push(value);
|
|
59
|
+
for (const value of values) {
|
|
60
|
+
if (Array.isArray(value)) {
|
|
61
|
+
value.forEach(append);
|
|
62
|
+
} else {
|
|
63
|
+
append(value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
55
69
|
// src/array/counting.ts
|
|
56
70
|
function counting(array, identity) {
|
|
57
71
|
if (!array) {
|
|
@@ -161,8 +175,8 @@ function list(startOrLength, end, valueOrMapper, step) {
|
|
|
161
175
|
// src/array/mapify.ts
|
|
162
176
|
function mapify(array, getKey, getValue = (item) => item) {
|
|
163
177
|
const map2 = /* @__PURE__ */ new Map();
|
|
164
|
-
for (const item of array) {
|
|
165
|
-
map2.set(getKey(item,
|
|
178
|
+
for (const [index, item] of array.entries()) {
|
|
179
|
+
map2.set(getKey(item, index), getValue(item, index));
|
|
166
180
|
}
|
|
167
181
|
return map2;
|
|
168
182
|
}
|
|
@@ -202,6 +216,15 @@ function objectify(array, getKey, getValue = (item) => item) {
|
|
|
202
216
|
);
|
|
203
217
|
}
|
|
204
218
|
|
|
219
|
+
// src/array/pluck.ts
|
|
220
|
+
function pluck(array, mappings) {
|
|
221
|
+
return array.map(
|
|
222
|
+
mappings ? (item) => mappings.map(
|
|
223
|
+
(mapping) => isFunction(mapping) ? mapping(item) : item[mapping]
|
|
224
|
+
) : Object.values
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
205
228
|
// src/array/remove.ts
|
|
206
229
|
function remove(array, predicate) {
|
|
207
230
|
return array.filter((item) => !predicate(item));
|
|
@@ -879,9 +902,6 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
|
|
|
879
902
|
const final = end ?? startOrLength;
|
|
880
903
|
for (let i = start; i <= final; i += step) {
|
|
881
904
|
yield mapper(i);
|
|
882
|
-
if (i + step > final) {
|
|
883
|
-
break;
|
|
884
|
-
}
|
|
885
905
|
}
|
|
886
906
|
}
|
|
887
907
|
|
|
@@ -1038,7 +1058,7 @@ function crush(value) {
|
|
|
1038
1058
|
|
|
1039
1059
|
// src/object/filterKey.ts
|
|
1040
1060
|
function filterKey(obj, key, filter) {
|
|
1041
|
-
return Object.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
|
|
1061
|
+
return Object.prototype.hasOwnProperty.call(obj, key) && (filter == null || (isArray(filter) ? filter.includes(key) : filter(obj[key], key, obj)));
|
|
1042
1062
|
}
|
|
1043
1063
|
|
|
1044
1064
|
// src/object/get.ts
|
|
@@ -1815,4 +1835,4 @@ function isWeakSet(value) {
|
|
|
1815
1835
|
return isTagged(value, "[object WeakSet]");
|
|
1816
1836
|
}
|
|
1817
1837
|
|
|
1818
|
-
export { AggregateErrorOrPolyfill as AggregateError, DefaultCloningStrategy, FastCloningStrategy, TimeoutError, all, alphabetical, always, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isAsyncIterable, isBigInt, isBoolean, isClass, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
|
|
1838
|
+
export { AggregateErrorOrPolyfill as AggregateError, DefaultCloningStrategy, FastCloningStrategy, TimeoutError, all, alphabetical, always, assign, boil, callable, camel, capitalize, cartesianProduct, castArray, castArrayIfExists, castComparator, castMapping, chain, clamp, clone, cloneDeep, cluster, compose, concat, construct, counting, crush, dash, debounce, dedent, defer, diff, draw, filterKey, first, flat, flip, fork, get, group, guard, inRange, intersects, invert, isArray, isAsyncIterable, isBigInt, isBoolean, isClass, isDate, isEmpty, isEqual, isError, isFloat, isFunction, isInt, isIntString, isIterable, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isResult, isResultErr, isResultOk, isSet, isString, isSymbol, isTagged, isUndefined, isWeakMap, isWeakSet, iterate, keys, last, lerp, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, mapify, max, memo, memoLastCall, merge, min, noop, objectify, omit, once, parallel, partial, partob, pascal, pick, pluck, proxied, random, range, reduce, remove, replace, replaceOrAppend, retry, round, select, selectFirst, series, set, shake, shift, shuffle, sift, similarity, sleep, snake, sort, sum, template, throttle, timeout, title, toFloat, toInt, toResult, toggle, traverse, trim, tryit as try, tryit, uid, unique, unzip, upperize, withResolvers, zip, zipToObject };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "radashi",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.0-beta.6d5c035",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"update-browserslist": "node scripts/run update-browserslist"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@biomejs/biome": "
|
|
48
|
+
"@biomejs/biome": "2.0.0-beta.1",
|
|
49
49
|
"@radashi-org/biome-config": "link:scripts/biome-config",
|
|
50
50
|
"@types/node": "^22.7.7",
|
|
51
51
|
"@vitest/coverage-v8": "2.1.5",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"and_chr >= 57",
|
|
64
64
|
"chrome >= 57",
|
|
65
65
|
"and_ff >= 52",
|
|
66
|
-
"android >=
|
|
66
|
+
"android >= 133",
|
|
67
67
|
"edge >= 15",
|
|
68
68
|
"samsung >= 7.4",
|
|
69
69
|
"safari >= 10.1",
|