radashi 12.4.0 → 12.5.0-beta.8a7266a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/radashi.cjs CHANGED
@@ -204,6 +204,15 @@ function objectify(array, getKey, getValue = (item) => item) {
204
204
  );
205
205
  }
206
206
 
207
+ // src/array/pluck.ts
208
+ function pluck(array, mappings) {
209
+ return array.map(
210
+ mappings ? (item) => mappings.map(
211
+ (mapping) => isFunction(mapping) ? mapping(item) : item[mapping]
212
+ ) : Object.values
213
+ );
214
+ }
215
+
207
216
  // src/array/remove.ts
208
217
  function remove(array, predicate) {
209
218
  return array.filter((item) => !predicate(item));
@@ -1918,6 +1927,7 @@ exports.partial = partial;
1918
1927
  exports.partob = partob;
1919
1928
  exports.pascal = pascal;
1920
1929
  exports.pick = pick;
1930
+ exports.pluck = pluck;
1921
1931
  exports.proxied = proxied;
1922
1932
  exports.random = random;
1923
1933
  exports.range = range;
@@ -332,6 +332,47 @@ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item:
332
332
  */
333
333
  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
334
 
335
+ /**
336
+ * Extracts values from an array of objects based on specified
337
+ * mappings. Useful for extracting multiple properties from an array
338
+ * of objects (e.g. for tabular data). Also supports “computed
339
+ * properties” via mapping functions, which can combine and transform
340
+ * values on-the-fly.
341
+ *
342
+ * - If mappings are provided, returns an array of arrays where each
343
+ * inner array contains the values extracted by applying each
344
+ * mapping to the corresponding object.
345
+ * - If no mappings are provided, returns an array of arrays
346
+ * containing all values of each object.
347
+ *
348
+ * @see https://radashi.js.org/reference/array/pluck
349
+ * @example
350
+ * ```ts
351
+ * interface God {
352
+ * name: string;
353
+ * power: number;
354
+ * domain: string;
355
+ * }
356
+ *
357
+ * const gods: God[] = [
358
+ * { name: 'Ra', power: 100, domain: 'Sun' },
359
+ * { name: 'Zeus', power: 98, domain: 'Lightning' },
360
+ * { name: 'Loki', power: 72, domain: 'Tricks' }
361
+ * ];
362
+ *
363
+ * // Extract a set of properties
364
+ * pluck(gods, ['power', 'domain']);
365
+ * // [[100, 'Sun'], [98, 'Lightning'], [72, 'Tricks']]
366
+ *
367
+ * // Extract all properties
368
+ * pluck(gods);
369
+ * // [['Ra', 100, 'Sun'], ['Zeus', 98, 'Lightning'], ['Loki', 72, 'Tricks']]
370
+ * ```
371
+ * @version 12.5.0
372
+ */
373
+ declare function pluck<T extends object, TMapping extends Mapping<T>>(array: readonly T[], mappings: readonly TMapping[]): MappedOutput<TMapping, T>[];
374
+ declare function pluck<T extends object>(array: readonly T[], mappings?: readonly Mapping<T>[]): unknown[];
375
+
335
376
  /**
336
377
  * Removes elements from an array based on the specified predicate
337
378
  * function.
@@ -1398,14 +1439,17 @@ type NoInfer<T> = [T][T extends any ? 0 : never];
1398
1439
  type StrictExtract<T, U> = SwitchNever<Extract<SwitchAny<T, unknown>, U>, unknown>;
1399
1440
  /**
1400
1441
  * Resolve a type union of property name literals within type `T`
1401
- * whose property values are assignable to type `CompatibleValue`.
1442
+ * whose property values are assignable to type `TConstraint`. If `T`
1443
+ * is a primitive, it's first transformed into its boxed equivalent
1444
+ * (e.g. `string` becomes `String`, `number` becomes `Number`, and so
1445
+ * on).
1402
1446
  *
1403
1447
  * Use case: “I want to know which properties of `T` are compatible
1404
- * with `CompatibleValue`.”
1448
+ * with `TConstraint`.”
1405
1449
  */
1406
- type CompatibleProperty<T, CompatibleValue> = [T] extends [Any] ? keyof any : T extends null | undefined ? never : {
1407
- [P in keyof BoxedPrimitive<T>]: BoxedPrimitive<T>[P] extends CompatibleValue ? P : never;
1408
- }[keyof BoxedPrimitive<T>];
1450
+ type CompatibleProperty<T, TConstraint> = [T] extends [Any] ? keyof any : T extends null | undefined ? never : (T extends object ? T : BoxedPrimitive<T>) extends infer TObject ? {
1451
+ [P in keyof TObject]: TObject[P] extends TConstraint ? P : never;
1452
+ }[keyof TObject] : never;
1409
1453
  /**
1410
1454
  * A value that can be reliably compared with JavaScript comparison
1411
1455
  * operators (e.g. `>`, `>=`, etc).
@@ -3717,4 +3761,4 @@ declare function isWeakMap<K extends WeakKey = WeakKey, V = unknown>(value: unkn
3717
3761
  */
3718
3762
  declare function isWeakSet<T extends WeakKey = WeakKey>(value: unknown): value is WeakSet<T>;
3719
3763
 
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 };
3764
+ 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, 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
@@ -332,6 +332,47 @@ declare function merge<T>(prev: readonly T[], array: readonly T[], toKey: (item:
332
332
  */
333
333
  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
334
 
335
+ /**
336
+ * Extracts values from an array of objects based on specified
337
+ * mappings. Useful for extracting multiple properties from an array
338
+ * of objects (e.g. for tabular data). Also supports “computed
339
+ * properties” via mapping functions, which can combine and transform
340
+ * values on-the-fly.
341
+ *
342
+ * - If mappings are provided, returns an array of arrays where each
343
+ * inner array contains the values extracted by applying each
344
+ * mapping to the corresponding object.
345
+ * - If no mappings are provided, returns an array of arrays
346
+ * containing all values of each object.
347
+ *
348
+ * @see https://radashi.js.org/reference/array/pluck
349
+ * @example
350
+ * ```ts
351
+ * interface God {
352
+ * name: string;
353
+ * power: number;
354
+ * domain: string;
355
+ * }
356
+ *
357
+ * const gods: God[] = [
358
+ * { name: 'Ra', power: 100, domain: 'Sun' },
359
+ * { name: 'Zeus', power: 98, domain: 'Lightning' },
360
+ * { name: 'Loki', power: 72, domain: 'Tricks' }
361
+ * ];
362
+ *
363
+ * // Extract a set of properties
364
+ * pluck(gods, ['power', 'domain']);
365
+ * // [[100, 'Sun'], [98, 'Lightning'], [72, 'Tricks']]
366
+ *
367
+ * // Extract all properties
368
+ * pluck(gods);
369
+ * // [['Ra', 100, 'Sun'], ['Zeus', 98, 'Lightning'], ['Loki', 72, 'Tricks']]
370
+ * ```
371
+ * @version 12.5.0
372
+ */
373
+ declare function pluck<T extends object, TMapping extends Mapping<T>>(array: readonly T[], mappings: readonly TMapping[]): MappedOutput<TMapping, T>[];
374
+ declare function pluck<T extends object>(array: readonly T[], mappings?: readonly Mapping<T>[]): unknown[];
375
+
335
376
  /**
336
377
  * Removes elements from an array based on the specified predicate
337
378
  * function.
@@ -1398,14 +1439,17 @@ type NoInfer<T> = [T][T extends any ? 0 : never];
1398
1439
  type StrictExtract<T, U> = SwitchNever<Extract<SwitchAny<T, unknown>, U>, unknown>;
1399
1440
  /**
1400
1441
  * Resolve a type union of property name literals within type `T`
1401
- * whose property values are assignable to type `CompatibleValue`.
1442
+ * whose property values are assignable to type `TConstraint`. If `T`
1443
+ * is a primitive, it's first transformed into its boxed equivalent
1444
+ * (e.g. `string` becomes `String`, `number` becomes `Number`, and so
1445
+ * on).
1402
1446
  *
1403
1447
  * Use case: “I want to know which properties of `T` are compatible
1404
- * with `CompatibleValue`.”
1448
+ * with `TConstraint`.”
1405
1449
  */
1406
- type CompatibleProperty<T, CompatibleValue> = [T] extends [Any] ? keyof any : T extends null | undefined ? never : {
1407
- [P in keyof BoxedPrimitive<T>]: BoxedPrimitive<T>[P] extends CompatibleValue ? P : never;
1408
- }[keyof BoxedPrimitive<T>];
1450
+ type CompatibleProperty<T, TConstraint> = [T] extends [Any] ? keyof any : T extends null | undefined ? never : (T extends object ? T : BoxedPrimitive<T>) extends infer TObject ? {
1451
+ [P in keyof TObject]: TObject[P] extends TConstraint ? P : never;
1452
+ }[keyof TObject] : never;
1409
1453
  /**
1410
1454
  * A value that can be reliably compared with JavaScript comparison
1411
1455
  * operators (e.g. `>`, `>=`, etc).
@@ -3717,4 +3761,4 @@ declare function isWeakMap<K extends WeakKey = WeakKey, V = unknown>(value: unkn
3717
3761
  */
3718
3762
  declare function isWeakSet<T extends WeakKey = WeakKey>(value: unknown): value is WeakSet<T>;
3719
3763
 
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 };
3764
+ 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, 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
@@ -202,6 +202,15 @@ function objectify(array, getKey, getValue = (item) => item) {
202
202
  );
203
203
  }
204
204
 
205
+ // src/array/pluck.ts
206
+ function pluck(array, mappings) {
207
+ return array.map(
208
+ mappings ? (item) => mappings.map(
209
+ (mapping) => isFunction(mapping) ? mapping(item) : item[mapping]
210
+ ) : Object.values
211
+ );
212
+ }
213
+
205
214
  // src/array/remove.ts
206
215
  function remove(array, predicate) {
207
216
  return array.filter((item) => !predicate(item));
@@ -1815,4 +1824,4 @@ function isWeakSet(value) {
1815
1824
  return isTagged(value, "[object WeakSet]");
1816
1825
  }
1817
1826
 
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 };
1827
+ 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, 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.4.0",
3
+ "version": "12.5.0-beta.8a7266a",
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": {