@fluixi/utils 1.0.0-alpha.53
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 +21 -0
- package/README.md +73 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/lib/array/advanced.cjs +1 -0
- package/dist/lib/array/advanced.d.ts +1116 -0
- package/dist/lib/array/advanced.d.ts.map +1 -0
- package/dist/lib/array/advanced.js +2429 -0
- package/dist/lib/array/advanced.mjs +1 -0
- package/dist/lib/array/array.cjs +1 -0
- package/dist/lib/array/array.d.ts +6 -0
- package/dist/lib/array/array.d.ts.map +1 -0
- package/dist/lib/array/array.js +31 -0
- package/dist/lib/array/array.mjs +1 -0
- package/dist/lib/array/index.cjs +1 -0
- package/dist/lib/array/index.d.ts +4 -0
- package/dist/lib/array/index.d.ts.map +1 -0
- package/dist/lib/array/index.js +3 -0
- package/dist/lib/array/index.mjs +1 -0
- package/dist/lib/array/utils.cjs +1 -0
- package/dist/lib/array/utils.d.ts +100 -0
- package/dist/lib/array/utils.d.ts.map +1 -0
- package/dist/lib/array/utils.js +165 -0
- package/dist/lib/array/utils.mjs +1 -0
- package/dist/lib/color/color.cjs +1 -0
- package/dist/lib/color/color.d.ts +366 -0
- package/dist/lib/color/color.d.ts.map +1 -0
- package/dist/lib/color/color.js +722 -0
- package/dist/lib/color/color.mjs +1 -0
- package/dist/lib/color/constants.cjs +1 -0
- package/dist/lib/color/constants.d.ts +361 -0
- package/dist/lib/color/constants.d.ts.map +1 -0
- package/dist/lib/color/constants.js +358 -0
- package/dist/lib/color/constants.mjs +1 -0
- package/dist/lib/color/conversions.cjs +1 -0
- package/dist/lib/color/conversions.d.ts +166 -0
- package/dist/lib/color/conversions.d.ts.map +1 -0
- package/dist/lib/color/conversions.js +766 -0
- package/dist/lib/color/conversions.mjs +1 -0
- package/dist/lib/color/helpers.cjs +1 -0
- package/dist/lib/color/helpers.d.ts +75 -0
- package/dist/lib/color/helpers.d.ts.map +1 -0
- package/dist/lib/color/helpers.js +419 -0
- package/dist/lib/color/helpers.mjs +1 -0
- package/dist/lib/color/index.cjs +1 -0
- package/dist/lib/color/index.d.ts +12 -0
- package/dist/lib/color/index.d.ts.map +1 -0
- package/dist/lib/color/index.js +15 -0
- package/dist/lib/color/index.mjs +1 -0
- package/dist/lib/color/types.cjs +1 -0
- package/dist/lib/color/types.d.ts +179 -0
- package/dist/lib/color/types.d.ts.map +1 -0
- package/dist/lib/color/types.js +1 -0
- package/dist/lib/color/types.mjs +0 -0
- package/dist/lib/color/utils.cjs +1 -0
- package/dist/lib/color/utils.d.ts +199 -0
- package/dist/lib/color/utils.d.ts.map +1 -0
- package/dist/lib/color/utils.js +858 -0
- package/dist/lib/color/utils.mjs +1 -0
- package/dist/lib/compare/comparators.cjs +1 -0
- package/dist/lib/compare/comparators.d.ts +65 -0
- package/dist/lib/compare/comparators.d.ts.map +1 -0
- package/dist/lib/compare/comparators.js +210 -0
- package/dist/lib/compare/comparators.mjs +1 -0
- package/dist/lib/compare/index.cjs +1 -0
- package/dist/lib/compare/index.d.ts +2 -0
- package/dist/lib/compare/index.d.ts.map +1 -0
- package/dist/lib/compare/index.js +1 -0
- package/dist/lib/compare/index.mjs +1 -0
- package/dist/lib/crypto/hash.cjs +1 -0
- package/dist/lib/crypto/hash.d.ts +6 -0
- package/dist/lib/crypto/hash.d.ts.map +1 -0
- package/dist/lib/crypto/hash.js +53 -0
- package/dist/lib/crypto/hash.mjs +1 -0
- package/dist/lib/crypto/index.cjs +1 -0
- package/dist/lib/crypto/index.d.ts +2 -0
- package/dist/lib/crypto/index.d.ts.map +1 -0
- package/dist/lib/crypto/index.js +1 -0
- package/dist/lib/crypto/index.mjs +1 -0
- package/dist/lib/dom/events.cjs +1 -0
- package/dist/lib/dom/events.d.ts +159 -0
- package/dist/lib/dom/events.d.ts.map +1 -0
- package/dist/lib/dom/events.js +50 -0
- package/dist/lib/dom/events.mjs +1 -0
- package/dist/lib/dom/index.cjs +1 -0
- package/dist/lib/dom/index.d.ts +3 -0
- package/dist/lib/dom/index.d.ts.map +1 -0
- package/dist/lib/dom/index.js +2 -0
- package/dist/lib/dom/index.mjs +1 -0
- package/dist/lib/dom/utils.cjs +1 -0
- package/dist/lib/dom/utils.d.ts +6 -0
- package/dist/lib/dom/utils.d.ts.map +1 -0
- package/dist/lib/dom/utils.js +37 -0
- package/dist/lib/dom/utils.mjs +1 -0
- package/dist/lib/functions/functions.cjs +1 -0
- package/dist/lib/functions/functions.d.ts +329 -0
- package/dist/lib/functions/functions.d.ts.map +1 -0
- package/dist/lib/functions/functions.js +585 -0
- package/dist/lib/functions/functions.mjs +1 -0
- package/dist/lib/functions/index.cjs +1 -0
- package/dist/lib/functions/index.d.ts +3 -0
- package/dist/lib/functions/index.d.ts.map +1 -0
- package/dist/lib/functions/index.js +1 -0
- package/dist/lib/functions/index.mjs +1 -0
- package/dist/lib/functions/types.cjs +1 -0
- package/dist/lib/functions/types.d.ts +2 -0
- package/dist/lib/functions/types.d.ts.map +1 -0
- package/dist/lib/functions/types.js +1 -0
- package/dist/lib/functions/types.mjs +0 -0
- package/dist/lib/helpers.cjs +1 -0
- package/dist/lib/helpers.d.ts +13 -0
- package/dist/lib/helpers.d.ts.map +1 -0
- package/dist/lib/helpers.js +66 -0
- package/dist/lib/helpers.mjs +1 -0
- package/dist/lib/index.cjs +1 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +8 -0
- package/dist/lib/index.mjs +1 -0
- package/dist/lib/maths/constants.cjs +1 -0
- package/dist/lib/maths/constants.d.ts +84 -0
- package/dist/lib/maths/constants.d.ts.map +1 -0
- package/dist/lib/maths/constants.js +79 -0
- package/dist/lib/maths/constants.mjs +1 -0
- package/dist/lib/maths/fn/advanced.cjs +1 -0
- package/dist/lib/maths/fn/advanced.d.ts +149 -0
- package/dist/lib/maths/fn/advanced.d.ts.map +1 -0
- package/dist/lib/maths/fn/advanced.js +264 -0
- package/dist/lib/maths/fn/advanced.mjs +1 -0
- package/dist/lib/maths/fn/basic.cjs +1 -0
- package/dist/lib/maths/fn/basic.d.ts +182 -0
- package/dist/lib/maths/fn/basic.d.ts.map +1 -0
- package/dist/lib/maths/fn/basic.js +343 -0
- package/dist/lib/maths/fn/basic.mjs +1 -0
- package/dist/lib/maths/fn/complex.cjs +1 -0
- package/dist/lib/maths/fn/complex.d.ts +153 -0
- package/dist/lib/maths/fn/complex.d.ts.map +1 -0
- package/dist/lib/maths/fn/complex.js +383 -0
- package/dist/lib/maths/fn/complex.mjs +1 -0
- package/dist/lib/maths/fn/index.cjs +1 -0
- package/dist/lib/maths/fn/index.d.ts +10 -0
- package/dist/lib/maths/fn/index.d.ts.map +1 -0
- package/dist/lib/maths/fn/index.js +9 -0
- package/dist/lib/maths/fn/index.mjs +1 -0
- package/dist/lib/maths/fn/trigo.cjs +1 -0
- package/dist/lib/maths/fn/trigo.d.ts +147 -0
- package/dist/lib/maths/fn/trigo.d.ts.map +1 -0
- package/dist/lib/maths/fn/trigo.js +227 -0
- package/dist/lib/maths/fn/trigo.mjs +1 -0
- package/dist/lib/maths/fn/vector.cjs +1 -0
- package/dist/lib/maths/fn/vector.d.ts +512 -0
- package/dist/lib/maths/fn/vector.d.ts.map +1 -0
- package/dist/lib/maths/fn/vector.js +1136 -0
- package/dist/lib/maths/fn/vector.mjs +1 -0
- package/dist/lib/maths/formatter.cjs +1 -0
- package/dist/lib/maths/formatter.d.ts +35 -0
- package/dist/lib/maths/formatter.d.ts.map +1 -0
- package/dist/lib/maths/formatter.js +56 -0
- package/dist/lib/maths/formatter.mjs +1 -0
- package/dist/lib/maths/guards.cjs +1 -0
- package/dist/lib/maths/guards.d.ts +166 -0
- package/dist/lib/maths/guards.d.ts.map +1 -0
- package/dist/lib/maths/guards.js +315 -0
- package/dist/lib/maths/guards.mjs +1 -0
- package/dist/lib/maths/index.cjs +1 -0
- package/dist/lib/maths/index.d.ts +24 -0
- package/dist/lib/maths/index.d.ts.map +1 -0
- package/dist/lib/maths/index.js +29 -0
- package/dist/lib/maths/index.mjs +1 -0
- package/dist/lib/maths/parser.cjs +1 -0
- package/dist/lib/maths/parser.d.ts +20 -0
- package/dist/lib/maths/parser.d.ts.map +1 -0
- package/dist/lib/maths/parser.js +78 -0
- package/dist/lib/maths/parser.mjs +1 -0
- package/dist/lib/maths/random.cjs +1 -0
- package/dist/lib/maths/random.d.ts +27 -0
- package/dist/lib/maths/random.d.ts.map +1 -0
- package/dist/lib/maths/random.js +49 -0
- package/dist/lib/maths/random.mjs +1 -0
- package/dist/lib/maths/types/advanced.cjs +1 -0
- package/dist/lib/maths/types/advanced.d.ts +357 -0
- package/dist/lib/maths/types/advanced.d.ts.map +1 -0
- package/dist/lib/maths/types/advanced.js +5 -0
- package/dist/lib/maths/types/advanced.mjs +0 -0
- package/dist/lib/maths/types/basic.cjs +1 -0
- package/dist/lib/maths/types/basic.d.ts +95 -0
- package/dist/lib/maths/types/basic.d.ts.map +1 -0
- package/dist/lib/maths/types/basic.js +5 -0
- package/dist/lib/maths/types/basic.mjs +0 -0
- package/dist/lib/maths/types/index.cjs +1 -0
- package/dist/lib/maths/types/index.d.ts +4 -0
- package/dist/lib/maths/types/index.d.ts.map +1 -0
- package/dist/lib/maths/types/index.js +3 -0
- package/dist/lib/maths/types/index.mjs +0 -0
- package/dist/lib/maths/types/negative.cjs +1 -0
- package/dist/lib/maths/types/negative.d.ts +51 -0
- package/dist/lib/maths/types/negative.d.ts.map +1 -0
- package/dist/lib/maths/types/negative.js +5 -0
- package/dist/lib/maths/types/negative.mjs +0 -0
- package/dist/lib/maths/types/operations.cjs +1 -0
- package/dist/lib/maths/types/operations.d.ts +188 -0
- package/dist/lib/maths/types/operations.d.ts.map +1 -0
- package/dist/lib/maths/types/operations.js +6 -0
- package/dist/lib/maths/types/operations.mjs +0 -0
- package/dist/lib/object/clone.cjs +1 -0
- package/dist/lib/object/clone.d.ts +46 -0
- package/dist/lib/object/clone.d.ts.map +1 -0
- package/dist/lib/object/clone.js +104 -0
- package/dist/lib/object/clone.mjs +1 -0
- package/dist/lib/object/diff.cjs +1 -0
- package/dist/lib/object/diff.d.ts +203 -0
- package/dist/lib/object/diff.d.ts.map +1 -0
- package/dist/lib/object/diff.js +805 -0
- package/dist/lib/object/diff.mjs +1 -0
- package/dist/lib/object/getter-setter.cjs +1 -0
- package/dist/lib/object/getter-setter.d.ts +361 -0
- package/dist/lib/object/getter-setter.d.ts.map +1 -0
- package/dist/lib/object/getter-setter.js +1771 -0
- package/dist/lib/object/getter-setter.mjs +1 -0
- package/dist/lib/object/index.cjs +6 -0
- package/dist/lib/object/index.d.ts +13 -0
- package/dist/lib/object/index.d.ts.map +1 -0
- package/dist/lib/object/index.js +12 -0
- package/dist/lib/object/index.mjs +6 -0
- package/dist/lib/object/merge.cjs +1 -0
- package/dist/lib/object/merge.d.ts +93 -0
- package/dist/lib/object/merge.d.ts.map +1 -0
- package/dist/lib/object/merge.js +474 -0
- package/dist/lib/object/merge.mjs +1 -0
- package/dist/lib/object/object.cjs +1 -0
- package/dist/lib/object/object.d.ts +128 -0
- package/dist/lib/object/object.d.ts.map +1 -0
- package/dist/lib/object/object.js +432 -0
- package/dist/lib/object/object.mjs +1 -0
- package/dist/lib/object/omit.cjs +1 -0
- package/dist/lib/object/omit.d.ts +351 -0
- package/dist/lib/object/omit.d.ts.map +1 -0
- package/dist/lib/object/omit.js +656 -0
- package/dist/lib/object/omit.mjs +1 -0
- package/dist/lib/object/reconcile.cjs +1 -0
- package/dist/lib/object/reconcile.d.ts +7 -0
- package/dist/lib/object/reconcile.d.ts.map +1 -0
- package/dist/lib/object/reconcile.js +122 -0
- package/dist/lib/object/reconcile.mjs +1 -0
- package/dist/lib/object/selector.cjs +1 -0
- package/dist/lib/object/selector.d.ts +50 -0
- package/dist/lib/object/selector.d.ts.map +1 -0
- package/dist/lib/object/selector.js +371 -0
- package/dist/lib/object/selector.mjs +1 -0
- package/dist/lib/object/sort.cjs +1 -0
- package/dist/lib/object/sort.d.ts +149 -0
- package/dist/lib/object/sort.d.ts.map +1 -0
- package/dist/lib/object/sort.js +298 -0
- package/dist/lib/object/sort.mjs +1 -0
- package/dist/lib/object/transform.cjs +1 -0
- package/dist/lib/object/transform.d.ts +620 -0
- package/dist/lib/object/transform.d.ts.map +1 -0
- package/dist/lib/object/transform.js +1058 -0
- package/dist/lib/object/transform.mjs +1 -0
- package/dist/lib/object/types.cjs +1 -0
- package/dist/lib/object/types.d.ts +250 -0
- package/dist/lib/object/types.d.ts.map +1 -0
- package/dist/lib/object/types.js +1 -0
- package/dist/lib/object/types.mjs +0 -0
- package/dist/lib/object/utils.cjs +6 -0
- package/dist/lib/object/utils.d.ts +165 -0
- package/dist/lib/object/utils.d.ts.map +1 -0
- package/dist/lib/object/utils.js +444 -0
- package/dist/lib/object/utils.mjs +6 -0
- package/dist/lib/primitive/boolean/boolean.cjs +1 -0
- package/dist/lib/primitive/boolean/boolean.d.ts +276 -0
- package/dist/lib/primitive/boolean/boolean.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/boolean.js +615 -0
- package/dist/lib/primitive/boolean/boolean.mjs +1 -0
- package/dist/lib/primitive/boolean/index.cjs +1 -0
- package/dist/lib/primitive/boolean/index.d.ts +3 -0
- package/dist/lib/primitive/boolean/index.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/index.js +2 -0
- package/dist/lib/primitive/boolean/index.mjs +1 -0
- package/dist/lib/primitive/boolean/types.cjs +1 -0
- package/dist/lib/primitive/boolean/types.d.ts +14 -0
- package/dist/lib/primitive/boolean/types.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/types.js +1 -0
- package/dist/lib/primitive/boolean/types.mjs +0 -0
- package/dist/lib/primitive/date/date.cjs +1 -0
- package/dist/lib/primitive/date/date.d.ts +641 -0
- package/dist/lib/primitive/date/date.d.ts.map +1 -0
- package/dist/lib/primitive/date/date.js +1998 -0
- package/dist/lib/primitive/date/date.mjs +1 -0
- package/dist/lib/primitive/date/index.cjs +1 -0
- package/dist/lib/primitive/date/index.d.ts +3 -0
- package/dist/lib/primitive/date/index.d.ts.map +1 -0
- package/dist/lib/primitive/date/index.js +2 -0
- package/dist/lib/primitive/date/index.mjs +1 -0
- package/dist/lib/primitive/date/types.cjs +1 -0
- package/dist/lib/primitive/date/types.d.ts +205 -0
- package/dist/lib/primitive/date/types.d.ts.map +1 -0
- package/dist/lib/primitive/date/types.js +7 -0
- package/dist/lib/primitive/date/types.mjs +0 -0
- package/dist/lib/primitive/index.cjs +5 -0
- package/dist/lib/primitive/index.d.ts +5 -0
- package/dist/lib/primitive/index.d.ts.map +1 -0
- package/dist/lib/primitive/index.js +4 -0
- package/dist/lib/primitive/index.mjs +5 -0
- package/dist/lib/primitive/string/index.cjs +5 -0
- package/dist/lib/primitive/string/index.d.ts +3 -0
- package/dist/lib/primitive/string/index.d.ts.map +1 -0
- package/dist/lib/primitive/string/index.js +2 -0
- package/dist/lib/primitive/string/index.mjs +5 -0
- package/dist/lib/primitive/string/parser-2.cjs +8 -0
- package/dist/lib/primitive/string/parser-2.d.ts +17 -0
- package/dist/lib/primitive/string/parser-2.d.ts.map +1 -0
- package/dist/lib/primitive/string/parser-2.js +656 -0
- package/dist/lib/primitive/string/parser-2.mjs +8 -0
- package/dist/lib/primitive/string/parser.cjs +3 -0
- package/dist/lib/primitive/string/parser.d.ts +9 -0
- package/dist/lib/primitive/string/parser.d.ts.map +1 -0
- package/dist/lib/primitive/string/parser.js +775 -0
- package/dist/lib/primitive/string/parser.mjs +3 -0
- package/dist/lib/primitive/string/string.cjs +5 -0
- package/dist/lib/primitive/string/string.d.ts +535 -0
- package/dist/lib/primitive/string/string.d.ts.map +1 -0
- package/dist/lib/primitive/string/string.js +1301 -0
- package/dist/lib/primitive/string/string.mjs +5 -0
- package/dist/lib/primitive/string/types.cjs +1 -0
- package/dist/lib/primitive/string/types.d.ts +318 -0
- package/dist/lib/primitive/string/types.d.ts.map +1 -0
- package/dist/lib/primitive/string/types.js +5 -0
- package/dist/lib/primitive/string/types.mjs +0 -0
- package/dist/lib/primitive/types.cjs +1 -0
- package/dist/lib/primitive/types.d.ts +27 -0
- package/dist/lib/primitive/types.d.ts.map +1 -0
- package/dist/lib/primitive/types.js +1 -0
- package/dist/lib/primitive/types.mjs +0 -0
- package/dist/lib/url/index.cjs +1 -0
- package/dist/lib/url/index.d.ts +3 -0
- package/dist/lib/url/index.d.ts.map +1 -0
- package/dist/lib/url/index.js +2 -0
- package/dist/lib/url/index.mjs +1 -0
- package/dist/lib/url/parser.cjs +1 -0
- package/dist/lib/url/parser.d.ts +216 -0
- package/dist/lib/url/parser.d.ts.map +1 -0
- package/dist/lib/url/parser.js +488 -0
- package/dist/lib/url/parser.mjs +1 -0
- package/dist/lib/url/types.cjs +1 -0
- package/dist/lib/url/types.d.ts +18 -0
- package/dist/lib/url/types.d.ts.map +1 -0
- package/dist/lib/url/types.js +1 -0
- package/dist/lib/url/types.mjs +0 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +150 -0
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object transformation utilities for restructuring, mapping, and applying transformations.
|
|
3
|
+
* @module transform
|
|
4
|
+
*/
|
|
5
|
+
import { AnyObject, SelectorFor } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Maps object values with a transform function, keeping the same keys
|
|
8
|
+
*
|
|
9
|
+
* Creates a new object with the same keys as the input, but with transformed values
|
|
10
|
+
* using the provided function. The function receives the value, key, and original object.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The input object type
|
|
13
|
+
* @template R - The transformed value type
|
|
14
|
+
* @param obj - The source object
|
|
15
|
+
* @param fn - The transform function to apply to each value
|
|
16
|
+
* @returns A new object with transformed values
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const prices = { apple: '1.25', banana: '0.75', orange: '1.00' };
|
|
21
|
+
* const numericPrices = mapValues(prices, price => parseFloat(price));
|
|
22
|
+
* // { apple: 1.25, banana: 0.75, orange: 1 }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function mapValues<T extends AnyObject, R>(obj: T, fn: (value: T[keyof T], key: string, obj: T) => R): Record<keyof T, R>;
|
|
26
|
+
/**
|
|
27
|
+
* Maps object keys with a transform function, keeping the same values
|
|
28
|
+
*
|
|
29
|
+
* Creates a new object with transformed keys using the provided function,
|
|
30
|
+
* while maintaining the original values. The function receives the key, value, and original object.
|
|
31
|
+
*
|
|
32
|
+
* @template T - The input object type
|
|
33
|
+
* @param obj - The source object
|
|
34
|
+
* @param fn - The transform function to apply to each key
|
|
35
|
+
* @returns A new object with transformed keys
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const data = { firstName: 'Alice', lastName: 'Smith' };
|
|
40
|
+
* const camelToSnake = mapKeys(data, key => key.replace(/[A-Z]/g, c => `_${c.toLowerCase()}`));
|
|
41
|
+
* // { first_name: 'Alice', last_name: 'Smith' }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function mapKeys<T extends AnyObject>(obj: T, fn: (key: string, value: T[keyof T], obj: T) => string): Record<string, T[keyof T]>;
|
|
45
|
+
/**
|
|
46
|
+
* Transforms keys to camelCase
|
|
47
|
+
*
|
|
48
|
+
* Creates a new object with all keys transformed to camelCase format.
|
|
49
|
+
* Handles keys in kebab-case, snake_case, and PascalCase.
|
|
50
|
+
*
|
|
51
|
+
* @template T - The input object type
|
|
52
|
+
* @param obj - The source object
|
|
53
|
+
* @param options - Transformation options
|
|
54
|
+
* @param options.deep - Whether to transform nested objects (default: true)
|
|
55
|
+
* @returns A new object with camelCase keys
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const data = {
|
|
60
|
+
* first_name: 'Alice',
|
|
61
|
+
* 'last-name': 'Smith',
|
|
62
|
+
* ContactInfo: {
|
|
63
|
+
* email_address: 'alice@example.com',
|
|
64
|
+
* phone_number: '555-1234'
|
|
65
|
+
* }
|
|
66
|
+
* };
|
|
67
|
+
*
|
|
68
|
+
* const camelCased = camelCaseKeys(data);
|
|
69
|
+
* // {
|
|
70
|
+
* // firstName: 'Alice',
|
|
71
|
+
* // lastName: 'Smith',
|
|
72
|
+
* // contactInfo: {
|
|
73
|
+
* // emailAddress: 'alice@example.com',
|
|
74
|
+
* // phoneNumber: '555-1234'
|
|
75
|
+
* // }
|
|
76
|
+
* // }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function camelCaseKeys<T extends AnyObject>(obj: T, options?: {
|
|
80
|
+
deep?: boolean;
|
|
81
|
+
}): Record<string, any>;
|
|
82
|
+
/**
|
|
83
|
+
* Transforms keys to snake_case
|
|
84
|
+
*
|
|
85
|
+
* Creates a new object with all keys transformed to snake_case format.
|
|
86
|
+
* Handles keys in camelCase, kebab-case, and PascalCase.
|
|
87
|
+
*
|
|
88
|
+
* @template T - The input object type
|
|
89
|
+
* @param obj - The source object
|
|
90
|
+
* @param options - Transformation options
|
|
91
|
+
* @param options.deep - Whether to transform nested objects (default: true)
|
|
92
|
+
* @returns A new object with snake_case keys
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const data = {
|
|
97
|
+
* firstName: 'Alice',
|
|
98
|
+
* 'last-name': 'Smith',
|
|
99
|
+
* ContactInfo: {
|
|
100
|
+
* emailAddress: 'alice@example.com',
|
|
101
|
+
* phoneNumber: '555-1234'
|
|
102
|
+
* }
|
|
103
|
+
* };
|
|
104
|
+
*
|
|
105
|
+
* const snakeCased = snakeCaseKeys(data);
|
|
106
|
+
* // {
|
|
107
|
+
* // first_name: 'Alice',
|
|
108
|
+
* // last_name: 'Smith',
|
|
109
|
+
* // contact_info: {
|
|
110
|
+
* // email_address: 'alice@example.com',
|
|
111
|
+
* // phone_number: '555-1234'
|
|
112
|
+
* // }
|
|
113
|
+
* // }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare function snakeCaseKeys<T extends AnyObject>(obj: T, options?: {
|
|
117
|
+
deep?: boolean;
|
|
118
|
+
}): Record<string, any>;
|
|
119
|
+
/**
|
|
120
|
+
* Transforms keys to kebab-case
|
|
121
|
+
*
|
|
122
|
+
* Creates a new object with all keys transformed to kebab-case format.
|
|
123
|
+
* Handles keys in camelCase, snake_case, and PascalCase.
|
|
124
|
+
*
|
|
125
|
+
* @template T - The input object type
|
|
126
|
+
* @param obj - The source object
|
|
127
|
+
* @param options - Transformation options
|
|
128
|
+
* @param options.deep - Whether to transform nested objects (default: true)
|
|
129
|
+
* @returns A new object with kebab-case keys
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* const data = {
|
|
134
|
+
* firstName: 'Alice',
|
|
135
|
+
* last_name: 'Smith',
|
|
136
|
+
* ContactInfo: {
|
|
137
|
+
* emailAddress: 'alice@example.com',
|
|
138
|
+
* phone_number: '555-1234'
|
|
139
|
+
* }
|
|
140
|
+
* };
|
|
141
|
+
*
|
|
142
|
+
* const kebabCased = kebabCaseKeys(data);
|
|
143
|
+
* // {
|
|
144
|
+
* // 'first-name': 'Alice',
|
|
145
|
+
* // 'last-name': 'Smith',
|
|
146
|
+
* // 'contact-info': {
|
|
147
|
+
* // 'email-address': 'alice@example.com',
|
|
148
|
+
* // 'phone-number': '555-1234'
|
|
149
|
+
* // }
|
|
150
|
+
* // }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function kebabCaseKeys<T extends AnyObject>(obj: T, options?: {
|
|
154
|
+
deep?: boolean;
|
|
155
|
+
}): Record<string, any>;
|
|
156
|
+
/**
|
|
157
|
+
* Flattens a nested object structure into a single-level object with path-based keys
|
|
158
|
+
*
|
|
159
|
+
* Creates a new flat object where nested keys are represented as path strings.
|
|
160
|
+
* Supports custom path delimiters and array handling.
|
|
161
|
+
*
|
|
162
|
+
* @template T - The input object type
|
|
163
|
+
* @param obj - The source object to flatten
|
|
164
|
+
* @param options - Flattening options
|
|
165
|
+
* @param options.delimiter - Character(s) to separate path segments (default: '.')
|
|
166
|
+
* @param options.includeArrays - Whether to flatten arrays (default: true)
|
|
167
|
+
* @param options.maxDepth - Maximum depth to flatten (default: Infinity)
|
|
168
|
+
* @returns A flattened object with path keys
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* const user = {
|
|
173
|
+
* name: {
|
|
174
|
+
* first: 'Alice',
|
|
175
|
+
* last: 'Smith'
|
|
176
|
+
* },
|
|
177
|
+
* contacts: [
|
|
178
|
+
* { type: 'email', value: 'alice@example.com' },
|
|
179
|
+
* { type: 'phone', value: '555-1234' }
|
|
180
|
+
* ]
|
|
181
|
+
* };
|
|
182
|
+
*
|
|
183
|
+
* const flattened = flatten(user);
|
|
184
|
+
* // {
|
|
185
|
+
* // 'name.first': 'Alice',
|
|
186
|
+
* // 'name.last': 'Smith',
|
|
187
|
+
* // 'contacts.0.type': 'email',
|
|
188
|
+
* // 'contacts.0.value': 'alice@example.com',
|
|
189
|
+
* // 'contacts.1.type': 'phone',
|
|
190
|
+
* // 'contacts.1.value': '555-1234'
|
|
191
|
+
* // }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare const flatten: (obj: AnyObject, options?: {
|
|
195
|
+
delimiter?: string;
|
|
196
|
+
includeArrays?: boolean;
|
|
197
|
+
maxDepth?: number;
|
|
198
|
+
}) => AnyObject;
|
|
199
|
+
/**
|
|
200
|
+
* Unflatten a single-level object with path-based keys into a nested object structure
|
|
201
|
+
*
|
|
202
|
+
* Reverses the flattening process, converting an object with path keys back into a nested structure.
|
|
203
|
+
* Supports custom path delimiters and array detection.
|
|
204
|
+
*
|
|
205
|
+
* @param obj - The flattened object to unflatten
|
|
206
|
+
* @param options - Unflattening options
|
|
207
|
+
* @param options.delimiter - Character(s) that separate path segments (default: '.')
|
|
208
|
+
* @param options.detectArrays - Whether to convert numeric indices to arrays (default: true)
|
|
209
|
+
* @returns A nested object structure
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* const flattened = {
|
|
214
|
+
* 'user.name.first': 'Alice',
|
|
215
|
+
* 'user.name.last': 'Smith',
|
|
216
|
+
* 'user.contacts.0.type': 'email',
|
|
217
|
+
* 'user.contacts.0.value': 'alice@example.com',
|
|
218
|
+
* 'user.contacts.1.type': 'phone',
|
|
219
|
+
* 'user.contacts.1.value': '555-1234'
|
|
220
|
+
* };
|
|
221
|
+
*
|
|
222
|
+
* const nested = unflatten(flattened);
|
|
223
|
+
* // {
|
|
224
|
+
* // user: {
|
|
225
|
+
* // name: {
|
|
226
|
+
* // first: 'Alice',
|
|
227
|
+
* // last: 'Smith'
|
|
228
|
+
* // },
|
|
229
|
+
* // contacts: [
|
|
230
|
+
* // { type: 'email', value: 'alice@example.com' },
|
|
231
|
+
* // { type: 'phone', value: '555-1234' }
|
|
232
|
+
* // ]
|
|
233
|
+
* // }
|
|
234
|
+
* // }
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export declare function unflatten(obj: Record<string, any>, options?: {
|
|
238
|
+
delimiter?: string;
|
|
239
|
+
detectArrays?: boolean;
|
|
240
|
+
}): Record<string, any>;
|
|
241
|
+
/**
|
|
242
|
+
* Transforms object values by applying a series of transform functions
|
|
243
|
+
*
|
|
244
|
+
* Creates a new object with the same structure as the input,
|
|
245
|
+
* but with all values transformed by the provided sequence of functions.
|
|
246
|
+
* Each function is applied in order to the result of the previous function.
|
|
247
|
+
*
|
|
248
|
+
* @template T - The input object type
|
|
249
|
+
* @param obj - The source object
|
|
250
|
+
* @param transformers - One or more transform functions to apply
|
|
251
|
+
* @returns A new object with transformed values
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* const data = {
|
|
256
|
+
* name: ' Alice Smith ',
|
|
257
|
+
* email: 'ALICE@EXAMPLE.COM',
|
|
258
|
+
* score: '85'
|
|
259
|
+
* };
|
|
260
|
+
*
|
|
261
|
+
* // Apply multiple transforms: trim strings, convert to lowercase, and parse numbers
|
|
262
|
+
* const transformed = transformValues(data,
|
|
263
|
+
* value => typeof value === 'string' ? value.trim() : value,
|
|
264
|
+
* value => typeof value === 'string' ? value.toLowerCase() : value,
|
|
265
|
+
* value => !isNaN(Number(value)) ? Number(value) : value
|
|
266
|
+
* );
|
|
267
|
+
*
|
|
268
|
+
* // {
|
|
269
|
+
* // name: 'alice smith',
|
|
270
|
+
* // email: 'alice@example.com',
|
|
271
|
+
* // score: 85
|
|
272
|
+
* // }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export declare function transformValues<T extends AnyObject>(obj: T, ...transformers: Array<(value: any) => any>): Record<keyof T, any>;
|
|
276
|
+
/**
|
|
277
|
+
* Renames keys in an object according to a mapping
|
|
278
|
+
*
|
|
279
|
+
* Creates a new object with keys renamed according to the provided mapping.
|
|
280
|
+
* Keys not in the mapping are kept unchanged.
|
|
281
|
+
*
|
|
282
|
+
* @template T - The input object type
|
|
283
|
+
* @param obj - The source object
|
|
284
|
+
* @param mapping - Object mapping from original keys to new keys
|
|
285
|
+
* @param options - Renaming options
|
|
286
|
+
* @param options.removeUnmapped - Whether to remove keys not in the mapping (default: false)
|
|
287
|
+
* @returns A new object with renamed keys
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* const user = {
|
|
292
|
+
* first_name: 'Alice',
|
|
293
|
+
* last_name: 'Smith',
|
|
294
|
+
* email: 'alice@example.com',
|
|
295
|
+
* age: 30
|
|
296
|
+
* };
|
|
297
|
+
*
|
|
298
|
+
* const renamed = renameKeys(user, {
|
|
299
|
+
* first_name: 'firstName',
|
|
300
|
+
* last_name: 'lastName'
|
|
301
|
+
* });
|
|
302
|
+
*
|
|
303
|
+
* // {
|
|
304
|
+
* // firstName: 'Alice',
|
|
305
|
+
* // lastName: 'Smith',
|
|
306
|
+
* // email: 'alice@example.com',
|
|
307
|
+
* // age: 30
|
|
308
|
+
* // }
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
export declare function renameKeys<T extends AnyObject, M extends Record<string, string>>(obj: T, mapping: M, options?: {
|
|
312
|
+
removeUnmapped?: boolean;
|
|
313
|
+
}): Record<string, any>;
|
|
314
|
+
/**
|
|
315
|
+
* Deeply transforms objects, arrays, and values in a nested structure
|
|
316
|
+
*
|
|
317
|
+
* Recursively traverses an object or array and applies different transform functions
|
|
318
|
+
* based on the type of each node (object, array, or primitive value).
|
|
319
|
+
*
|
|
320
|
+
* @template T - The input type
|
|
321
|
+
* @param data - The data to transform
|
|
322
|
+
* @param options - Transform options
|
|
323
|
+
* @param options.transformObject - Function to transform objects (default: identity)
|
|
324
|
+
* @param options.transformArray - Function to transform arrays (default: identity)
|
|
325
|
+
* @param options.transformValue - Function to transform primitive values (default: identity)
|
|
326
|
+
* @param options.maxDepth - Maximum depth to transform (default: Infinity)
|
|
327
|
+
* @returns The transformed data
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```ts
|
|
331
|
+
* const data = {
|
|
332
|
+
* user: {
|
|
333
|
+
* name: 'Alice Smith',
|
|
334
|
+
* scores: [85, 92, 78],
|
|
335
|
+
* active: true
|
|
336
|
+
* },
|
|
337
|
+
* metadata: {
|
|
338
|
+
* lastUpdated: '2023-01-15'
|
|
339
|
+
* }
|
|
340
|
+
* };
|
|
341
|
+
*
|
|
342
|
+
* // Apply different transformations to objects, arrays, and primitive values
|
|
343
|
+
* const result = deepTransform(data, {
|
|
344
|
+
* transformObject: obj => ({ ...obj, _transformed: true }),
|
|
345
|
+
* transformArray: arr => arr.map(x => typeof x === 'number' ? x + 10 : x),
|
|
346
|
+
* transformValue: (val, key) => key === 'name' ? val.toUpperCase() : val
|
|
347
|
+
* });
|
|
348
|
+
*
|
|
349
|
+
* // {
|
|
350
|
+
* // user: {
|
|
351
|
+
* // name: 'ALICE SMITH',
|
|
352
|
+
* // scores: [95, 102, 88],
|
|
353
|
+
* // active: true,
|
|
354
|
+
* // _transformed: true
|
|
355
|
+
* // },
|
|
356
|
+
* // metadata: {
|
|
357
|
+
* // lastUpdated: '2023-01-15',
|
|
358
|
+
* // _transformed: true
|
|
359
|
+
* // },
|
|
360
|
+
* // _transformed: true
|
|
361
|
+
* // }
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
export declare function deepTransform<T, K extends SelectorFor<T>, R>(data: T, options?: {
|
|
365
|
+
transformObject?: (obj: Record<string, any>, path: K[]) => Record<string, any>;
|
|
366
|
+
transformArray?: (arr: any[], path: K[]) => R[];
|
|
367
|
+
transformValue?: (value: any, key: string, path: K[]) => R;
|
|
368
|
+
maxDepth?: number;
|
|
369
|
+
}): T;
|
|
370
|
+
/**
|
|
371
|
+
* Transforms a flat object with key-value pairs into a structured object by key pattern
|
|
372
|
+
*
|
|
373
|
+
* Useful for converting flat configuration objects or query parameters into structured objects.
|
|
374
|
+
* Groups keys by a shared prefix and nests them accordingly.
|
|
375
|
+
*
|
|
376
|
+
* @param obj - The flat object to structure
|
|
377
|
+
* @param options - Structuring options
|
|
378
|
+
* @param options.separator - The character(s) that separate key parts (default: '.')
|
|
379
|
+
* @param options.detectArrays - Whether to convert numeric indices to arrays (default: true)
|
|
380
|
+
* @returns A structured object
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* const params = {
|
|
385
|
+
* 'user.name': 'Alice',
|
|
386
|
+
* 'user.email': 'alice@example.com',
|
|
387
|
+
* 'preferences.theme': 'dark',
|
|
388
|
+
* 'preferences.notifications': 'true',
|
|
389
|
+
* 'items.0.id': '1001',
|
|
390
|
+
* 'items.0.name': 'Widget',
|
|
391
|
+
* 'items.1.id': '1002',
|
|
392
|
+
* 'items.1.name': 'Gadget'
|
|
393
|
+
* };
|
|
394
|
+
*
|
|
395
|
+
* const structured = structureByKeys(params);
|
|
396
|
+
* // {
|
|
397
|
+
* // user: {
|
|
398
|
+
* // name: 'Alice',
|
|
399
|
+
* // email: 'alice@example.com'
|
|
400
|
+
* // },
|
|
401
|
+
* // preferences: {
|
|
402
|
+
* // theme: 'dark',
|
|
403
|
+
* // notifications: 'true'
|
|
404
|
+
* // },
|
|
405
|
+
* // items: [
|
|
406
|
+
* // { id: '1001', name: 'Widget' },
|
|
407
|
+
* // { id: '1002', name: 'Gadget' }
|
|
408
|
+
* // ]
|
|
409
|
+
* // }
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
export declare function structureByKeys(obj: Record<string, any>, options?: {
|
|
413
|
+
separator?: string;
|
|
414
|
+
detectArrays?: boolean;
|
|
415
|
+
}): Record<string, any>;
|
|
416
|
+
/**
|
|
417
|
+
* Transforms values at specific paths in an object
|
|
418
|
+
*
|
|
419
|
+
* Applies transform functions to values at the specified path(s),
|
|
420
|
+
* supporting advanced path selectors including property paths, array indices,
|
|
421
|
+
* wildcards, and filters. Supports transforming multiple paths in a single operation.
|
|
422
|
+
*
|
|
423
|
+
* @template T - The input object type
|
|
424
|
+
* @param obj - The source object
|
|
425
|
+
* @param paths - Path selector or array of path selectors to the values to transform
|
|
426
|
+
* @param transformer - Function to transform the value
|
|
427
|
+
* @param options - Additional options
|
|
428
|
+
* @param options.transformAll - Whether to apply transformer to all paths or individually (default: false)
|
|
429
|
+
* @returns A new object with the transformed value(s)
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```ts
|
|
433
|
+
* const user = {
|
|
434
|
+
* id: 1,
|
|
435
|
+
* name: 'Alice Smith',
|
|
436
|
+
* profile: {
|
|
437
|
+
* email: 'alice@example.com',
|
|
438
|
+
* settings: {
|
|
439
|
+
* notifications: true
|
|
440
|
+
* }
|
|
441
|
+
* },
|
|
442
|
+
* posts: [
|
|
443
|
+
* { id: 101, title: 'Hello', likes: 5 },
|
|
444
|
+
* { id: 102, title: 'World', likes: 10 }
|
|
445
|
+
* ]
|
|
446
|
+
* };
|
|
447
|
+
*
|
|
448
|
+
* // Transform a simple property
|
|
449
|
+
* const result1 = transformPath(user, 'name', name => name.toUpperCase());
|
|
450
|
+
* // user.name becomes 'ALICE SMITH'
|
|
451
|
+
*
|
|
452
|
+
* // Transform a nested property
|
|
453
|
+
* const result2 = transformPath(user, 'profile.email', email => email.split('@')[0] + '@example.org');
|
|
454
|
+
* // user.profile.email becomes 'alice@example.org'
|
|
455
|
+
*
|
|
456
|
+
* // Transform using wildcards
|
|
457
|
+
* const result3 = transformPath(user, 'posts[*].likes', likes => likes * 2);
|
|
458
|
+
* // All post likes are doubled
|
|
459
|
+
*
|
|
460
|
+
* // Transform multiple paths
|
|
461
|
+
* const result4 = transformPath(
|
|
462
|
+
* user,
|
|
463
|
+
* ['name', 'profile.email', 'posts[*].likes'],
|
|
464
|
+
* value => {
|
|
465
|
+
* if (typeof value === 'string') return value.toUpperCase();
|
|
466
|
+
* if (typeof value === 'number') return value * 2;
|
|
467
|
+
* return value;
|
|
468
|
+
* }
|
|
469
|
+
* );
|
|
470
|
+
* // Transforms multiple properties at once
|
|
471
|
+
*
|
|
472
|
+
* // Use path-specific transformations
|
|
473
|
+
* const result5 = transformPath(
|
|
474
|
+
* user,
|
|
475
|
+
* ['name', 'profile.email', 'posts[*].likes'],
|
|
476
|
+
* (value, path) => {
|
|
477
|
+
* if (path === 'name') return value.toUpperCase();
|
|
478
|
+
* if (path === 'profile.email') return value.split('@')[0] + '@example.org';
|
|
479
|
+
* if (path.includes('likes')) return value + 10;
|
|
480
|
+
* return value;
|
|
481
|
+
* },
|
|
482
|
+
* { transformAll: true }
|
|
483
|
+
* );
|
|
484
|
+
* ```
|
|
485
|
+
*/
|
|
486
|
+
export declare function transformPath<T>(obj: T, paths: string | string[], transformer: (value: any, path?: string, parent?: any) => any, options?: {
|
|
487
|
+
transformAll?: boolean;
|
|
488
|
+
}): T;
|
|
489
|
+
/**
|
|
490
|
+
* Maps values at specific paths in an object
|
|
491
|
+
*
|
|
492
|
+
* Similar to transformPath, but returns an array of transformed values
|
|
493
|
+
* rather than modifying the object structure. Supports mapping multiple paths
|
|
494
|
+
* in a single operation.
|
|
495
|
+
*
|
|
496
|
+
* @template T - The input object type
|
|
497
|
+
* @template R - The output value type
|
|
498
|
+
* @param obj - The source object
|
|
499
|
+
* @param paths - Path selector or array of path selectors to the values to map
|
|
500
|
+
* @param mapper - Function to transform each value
|
|
501
|
+
* @param options - Additional options
|
|
502
|
+
* @param options.flatten - Whether to flatten the results into a single array (default: true)
|
|
503
|
+
* @returns An array of transformed values
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```ts
|
|
507
|
+
* const data = {
|
|
508
|
+
* users: [
|
|
509
|
+
* { id: 1, name: 'Alice', age: 30 },
|
|
510
|
+
* { id: 2, name: 'Bob', age: 25 },
|
|
511
|
+
* { id: 3, name: 'Charlie', age: 35 }
|
|
512
|
+
* ]
|
|
513
|
+
* };
|
|
514
|
+
*
|
|
515
|
+
* // Extract and transform user names
|
|
516
|
+
* const names = mapPath(data, 'users[*].name', name => name.toUpperCase());
|
|
517
|
+
* // ['ALICE', 'BOB', 'CHARLIE']
|
|
518
|
+
*
|
|
519
|
+
* // Filter and transform
|
|
520
|
+
* const youngUsers = mapPath(data, 'users[?(@.age < 30)].name', (name, user) => ({
|
|
521
|
+
* name,
|
|
522
|
+
* greeting: `Hello, ${name}!`
|
|
523
|
+
* }));
|
|
524
|
+
* // [{ name: 'Bob', greeting: 'Hello, Bob!' }]
|
|
525
|
+
*
|
|
526
|
+
* // Map multiple paths
|
|
527
|
+
* const info = mapPath(
|
|
528
|
+
* data,
|
|
529
|
+
* ['users[*].name', 'users[*].age'],
|
|
530
|
+
* value => typeof value === 'string' ? value.toUpperCase() : value
|
|
531
|
+
* );
|
|
532
|
+
* // ['ALICE', 'BOB', 'CHARLIE', 30, 25, 35]
|
|
533
|
+
*
|
|
534
|
+
* // Map multiple paths with path context
|
|
535
|
+
* const info = mapPath(
|
|
536
|
+
* data,
|
|
537
|
+
* ['users[*].name', 'users[*].age'],
|
|
538
|
+
* (value, path) => {
|
|
539
|
+
* if (path.includes('name')) return `Name: ${value}`;
|
|
540
|
+
* if (path.includes('age')) return `Age: ${value}`;
|
|
541
|
+
* return value;
|
|
542
|
+
* }
|
|
543
|
+
* );
|
|
544
|
+
* // ['Name: Alice', 'Name: Bob', 'Name: Charlie', 'Age: 30', 'Age: 25', 'Age: 35']
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
export declare function mapPath<T, K extends SelectorFor<T> | SelectorFor<T>[], R>(obj: T, paths: K, mapper: (value: any, path?: string, parent?: any) => R, options?: {
|
|
548
|
+
flatten?: boolean;
|
|
549
|
+
}): R[];
|
|
550
|
+
/**
|
|
551
|
+
* Transforms keys at specific paths in an object
|
|
552
|
+
*
|
|
553
|
+
* Applies a transform function to keys at the specified path(s),
|
|
554
|
+
* supporting advanced path selectors. Supports transforming keys at multiple paths
|
|
555
|
+
* in a single operation.
|
|
556
|
+
*
|
|
557
|
+
* @template T - The input object type
|
|
558
|
+
* @param obj - The source object
|
|
559
|
+
* @param paths - Path selector or array of path selectors to the objects whose keys should be transformed
|
|
560
|
+
* @param transformer - Function to transform each key
|
|
561
|
+
* @param options - Additional options
|
|
562
|
+
* @param options.recursive - Whether to recursively transform nested object keys (default: false)
|
|
563
|
+
* @returns A new object with transformed keys at the specified path(s)
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```ts
|
|
567
|
+
* const data = {
|
|
568
|
+
* user: {
|
|
569
|
+
* personal_info: {
|
|
570
|
+
* first_name: 'Alice',
|
|
571
|
+
* last_name: 'Smith',
|
|
572
|
+
* email_address: 'alice@example.com'
|
|
573
|
+
* },
|
|
574
|
+
* work_info: {
|
|
575
|
+
* job_title: 'Developer',
|
|
576
|
+
* department_name: 'Engineering'
|
|
577
|
+
* }
|
|
578
|
+
* }
|
|
579
|
+
* };
|
|
580
|
+
*
|
|
581
|
+
* // Transform snake_case keys to camelCase at a single path
|
|
582
|
+
* const result1 = transformKeysAtPath(data, 'user.personal_info', key =>
|
|
583
|
+
* key.replace(/_([a-z])/g, (_, c) => c.toUpperCase())
|
|
584
|
+
* );
|
|
585
|
+
*
|
|
586
|
+
* // Transform keys at multiple paths
|
|
587
|
+
* const result2 = transformKeysAtPath(
|
|
588
|
+
* data,
|
|
589
|
+
* ['user.personal_info', 'user.work_info'],
|
|
590
|
+
* key => key.replace(/_([a-z])/g, (_, c) => c.toUpperCase())
|
|
591
|
+
* );
|
|
592
|
+
*
|
|
593
|
+
* // Recursively transform all nested keys
|
|
594
|
+
* const result3 = transformKeysAtPath(
|
|
595
|
+
* data,
|
|
596
|
+
* 'user',
|
|
597
|
+
* key => key.replace(/_([a-z])/g, (_, c) => c.toUpperCase()),
|
|
598
|
+
* { recursive: true }
|
|
599
|
+
* );
|
|
600
|
+
*
|
|
601
|
+
* // Result3:
|
|
602
|
+
* // {
|
|
603
|
+
* // user: {
|
|
604
|
+
* // personalInfo: {
|
|
605
|
+
* // firstName: 'Alice',
|
|
606
|
+
* // lastName: 'Smith',
|
|
607
|
+
* // emailAddress: 'alice@example.com'
|
|
608
|
+
* // },
|
|
609
|
+
* // workInfo: {
|
|
610
|
+
* // jobTitle: 'Developer',
|
|
611
|
+
* // departmentName: 'Engineering'
|
|
612
|
+
* // }
|
|
613
|
+
* // }
|
|
614
|
+
* // }
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
617
|
+
export declare function transformKeysAtPath<T>(obj: T, paths: string | string[], transformer: (key: string, value: any, path?: string) => string, options?: {
|
|
618
|
+
recursive?: boolean;
|
|
619
|
+
}): T;
|
|
620
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":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