@homer0/object-utils 6.0.2 → 6.0.5
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/index.d.ts +191 -222
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,127 +1,118 @@
|
|
|
1
|
+
//#region src/fns/copy.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Creates a deep copy of a given object.
|
|
3
4
|
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* returned.
|
|
5
|
+
* @template T The type of the input object, which will be the same as the one returned.
|
|
6
|
+
* @param target The object to copy.
|
|
7
7
|
*/
|
|
8
8
|
declare const copy: <T>(target: T) => T;
|
|
9
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/fns/formatKeys.d.ts
|
|
10
11
|
/**
|
|
11
12
|
* The callback that will be used to replace a key.
|
|
12
13
|
*
|
|
13
|
-
* @param substring
|
|
14
|
-
* @param args
|
|
14
|
+
* @param substring The captured string to replace.
|
|
15
|
+
* @param args The list of groups captured by the expression.
|
|
15
16
|
*/
|
|
16
17
|
type FormatKeysReplaceFn = (substring: string, ...args: string[]) => string;
|
|
17
18
|
type FormatKeysOptions = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
exclude?: string[];
|
|
40
|
-
/**
|
|
41
|
-
* The delimiter that will separate the path components for both `include` and `exclude`.
|
|
42
|
-
*/
|
|
43
|
-
pathDelimiter?: string;
|
|
19
|
+
/** The object to transform. */
|
|
20
|
+
target: unknown;
|
|
21
|
+
/** A regular expression to match the keys to transform. */
|
|
22
|
+
search: RegExp;
|
|
23
|
+
/**
|
|
24
|
+
* The callback that will be used to replace the matched substring. Think of `search`
|
|
25
|
+
* and `replace` as the parameters of `String.replace`.
|
|
26
|
+
*/
|
|
27
|
+
replace: FormatKeysReplaceFn;
|
|
28
|
+
/**
|
|
29
|
+
* A list of keys or paths where the transformation will be made. If not specified, the
|
|
30
|
+
* function will use all the keys from the object.
|
|
31
|
+
*/
|
|
32
|
+
include?: string[];
|
|
33
|
+
/** A list of keys or paths where the transformation won't be made. */
|
|
34
|
+
exclude?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* The delimiter that will separate the path components for both `include` and
|
|
37
|
+
* `exclude`.
|
|
38
|
+
*/
|
|
39
|
+
pathDelimiter?: string;
|
|
44
40
|
};
|
|
45
41
|
type FormatKeysExtensionOptions = Omit<FormatKeysOptions, 'search' | 'replace'>;
|
|
46
42
|
/**
|
|
47
43
|
* Formats all the keys on an object using a way similar to `.replace(regexp, ...)` but
|
|
48
44
|
* that also works recursively and with _"object paths"_.
|
|
49
45
|
*
|
|
50
|
-
* @param options The set of options to customize the transformation.
|
|
51
|
-
* @template T The type of the returned object.
|
|
52
46
|
* @example
|
|
53
|
-
*
|
|
54
47
|
* const target = {
|
|
55
|
-
*
|
|
48
|
+
* prop_one: 'Charito!',
|
|
56
49
|
* };
|
|
57
50
|
* console.log(
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
51
|
+
* formatKeys({
|
|
52
|
+
* target,
|
|
53
|
+
* // Find all the keys with snake case.
|
|
54
|
+
* search: /([a-z])_([a-z])/g,
|
|
55
|
+
* // Using the same .replace style callback, replace it with lower camel case.
|
|
56
|
+
* replace: (_, firstLetter, secondLetter) => {
|
|
57
|
+
* const newSecondLetter = secondLetter.toUpperCase();
|
|
58
|
+
* return `${firstLetter}${newSecondLetter}`;
|
|
59
|
+
* },
|
|
60
|
+
* }),
|
|
68
61
|
* );
|
|
69
62
|
* // Will output { propOne: 'Charito!}.
|
|
70
63
|
*
|
|
64
|
+
* @template T The type of the returned object.
|
|
65
|
+
* @param options The set of options to customize the transformation.
|
|
71
66
|
*/
|
|
72
67
|
declare const formatKeys: <T = Record<string, unknown>>(options: FormatKeysOptions) => T;
|
|
73
|
-
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/fns/dashToLowerCamelKeys.d.ts
|
|
74
70
|
/**
|
|
75
|
-
* A shorthand method for {@link formatKeys} that transforms the keys from `dash-case`
|
|
76
|
-
*
|
|
71
|
+
* A shorthand method for {@link formatKeys} that transforms the keys from `dash-case` to
|
|
72
|
+
* `lowerCamelCase`.
|
|
77
73
|
*
|
|
78
|
-
* @
|
|
79
|
-
* @
|
|
74
|
+
* @template T The type of the returned object.
|
|
75
|
+
* @param options The options to use.
|
|
80
76
|
*/
|
|
81
77
|
declare const dashToLowerCamelKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
82
|
-
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/fns/dashToSnakeKeys.d.ts
|
|
83
80
|
/**
|
|
84
|
-
* A shorthand method for {@link formatKeys} that transforms the keys from `dash-case`
|
|
85
|
-
*
|
|
81
|
+
* A shorthand method for {@link formatKeys} that transforms the keys from `dash-case` to
|
|
82
|
+
* `snake_case`.
|
|
86
83
|
*
|
|
87
|
-
* @
|
|
88
|
-
* @
|
|
84
|
+
* @template T The type of the returned object.
|
|
85
|
+
* @param options The options to use.
|
|
89
86
|
*/
|
|
90
87
|
declare const dashToSnakeKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
91
|
-
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/fns/extract.d.ts
|
|
92
90
|
/**
|
|
93
|
-
* Used in the {@link extract} function to specify a path for a property, or an "origin
|
|
94
|
-
* and an "extraction path".
|
|
91
|
+
* Used in the {@link extract} function to specify a path for a property, or an "origin
|
|
92
|
+
* path" and an "extraction path".
|
|
95
93
|
*/
|
|
96
94
|
type extractionPath = string | Record<string, string>;
|
|
97
95
|
type ExtractOptions = {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
* Whether or not to throw an error when the path is invalid. If this is `false`, the
|
|
114
|
-
* method will silently fail an empty object.
|
|
115
|
-
*/
|
|
116
|
-
failWithError?: boolean;
|
|
96
|
+
/** The object from where the property/properties will be extracted. */
|
|
97
|
+
target: unknown;
|
|
98
|
+
/**
|
|
99
|
+
* This can be a single path or a list of them. And for this method, the paths are not
|
|
100
|
+
* only strings but can also be an object with a single key, that would be the path to
|
|
101
|
+
* where to "do the extraction", and the value the path on the target object.
|
|
102
|
+
*/
|
|
103
|
+
paths: extractionPath | extractionPath[];
|
|
104
|
+
/** The delimiter that will separate the path components. */
|
|
105
|
+
pathDelimiter?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Whether or not to throw an error when the path is invalid. If this is `false`, the
|
|
108
|
+
* method will silently fail an empty object.
|
|
109
|
+
*/
|
|
110
|
+
failWithError?: boolean;
|
|
117
111
|
};
|
|
118
112
|
/**
|
|
119
113
|
* Extracts a property or properties from an object in order to create a new one.
|
|
120
114
|
*
|
|
121
|
-
* @param options The options to use.
|
|
122
|
-
* @template T The type of the returned object.
|
|
123
115
|
* @example
|
|
124
|
-
*
|
|
125
116
|
* const target = {
|
|
126
117
|
* name: {
|
|
127
118
|
* first: 'Pilar',
|
|
@@ -140,83 +131,72 @@ type ExtractOptions = {
|
|
|
140
131
|
* );
|
|
141
132
|
* // Will output { name: 'Pilar', age: 3, address: { planet: 'earth' } }
|
|
142
133
|
*
|
|
134
|
+
* @template T The type of the returned object.
|
|
135
|
+
* @param options The options to use.
|
|
143
136
|
*/
|
|
144
137
|
declare const extract: <T = Record<string, unknown>>(options: ExtractOptions) => T | undefined;
|
|
145
|
-
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/fns/flat.d.ts
|
|
146
140
|
/**
|
|
147
141
|
* Checks whether a key for an array or an Object should be flattened.
|
|
148
142
|
*
|
|
149
|
-
* @param key
|
|
150
|
-
* @param value
|
|
143
|
+
* @param key The key to check inside its parent.
|
|
144
|
+
* @param value The value of the key.
|
|
151
145
|
*/
|
|
152
146
|
type ShouldFlattenFn = (key: string, value: unknown) => boolean;
|
|
153
147
|
type FlatOptions = {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
* A custom function that can be used in order to tell the function whether an Object or
|
|
170
|
-
* an Array property should be flatten or not.
|
|
171
|
-
*/
|
|
172
|
-
shouldFlatten?: ShouldFlattenFn;
|
|
148
|
+
/** The object to transform. */
|
|
149
|
+
target: unknown;
|
|
150
|
+
/**
|
|
151
|
+
* A custom prefix to be added before the name of the properties. This can be used on
|
|
152
|
+
* custom cases and it's also used when the method calls itself in order to flatten a
|
|
153
|
+
* sub object.
|
|
154
|
+
*/
|
|
155
|
+
prefix?: string;
|
|
156
|
+
/** The delimiter that will separate the path components. */
|
|
157
|
+
pathDelimiter?: string;
|
|
158
|
+
/**
|
|
159
|
+
* A custom function that can be used in order to tell the function whether an Object or
|
|
160
|
+
* an Array property should be flatten or not.
|
|
161
|
+
*/
|
|
162
|
+
shouldFlatten?: ShouldFlattenFn;
|
|
173
163
|
};
|
|
174
164
|
/**
|
|
175
165
|
* Flattens an object properties into a single level dictionary.
|
|
176
166
|
*
|
|
177
|
-
* @param options The options to use.
|
|
178
|
-
* @template T The type of the returned object.
|
|
179
167
|
* @example
|
|
168
|
+
* const target = {
|
|
169
|
+
* propOne: {
|
|
170
|
+
* propOneSub: 'Charito!',
|
|
171
|
+
* },
|
|
172
|
+
* propTwo: '!!!',
|
|
173
|
+
* };
|
|
174
|
+
* console.log(flat({ target });
|
|
175
|
+
* // Will output { 'propOne.propOneSub': 'Charito!', propTwo: '!!!' }
|
|
180
176
|
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* propOneSub: 'Charito!',
|
|
184
|
-
* },
|
|
185
|
-
* propTwo: '!!!',
|
|
186
|
-
* };
|
|
187
|
-
* console.log(flat({ target });
|
|
188
|
-
* // Will output { 'propOne.propOneSub': 'Charito!', propTwo: '!!!' }
|
|
189
|
-
*
|
|
177
|
+
* @template T The type of the returned object.
|
|
178
|
+
* @param options The options to use.
|
|
190
179
|
*/
|
|
191
180
|
declare const flat: <T = Record<string, unknown>>(options: FlatOptions) => T;
|
|
192
|
-
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/fns/get.d.ts
|
|
193
183
|
type GetOptions = {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
pathDelimiter?: string;
|
|
206
|
-
/**
|
|
207
|
-
* Whether or not to throw an error when the path is invalid. If this is `false`,
|
|
208
|
-
* the method will silently fail and return `undefined`.
|
|
209
|
-
*/
|
|
210
|
-
failWithError?: boolean;
|
|
184
|
+
/** The object from where the property will be read. */
|
|
185
|
+
target: unknown;
|
|
186
|
+
/** The path to the property. */
|
|
187
|
+
path: string;
|
|
188
|
+
/** The delimiter that will separate the path components. */
|
|
189
|
+
pathDelimiter?: string;
|
|
190
|
+
/**
|
|
191
|
+
* Whether or not to throw an error when the path is invalid. If this is `false`, the
|
|
192
|
+
* method will silently fail and return `undefined`.
|
|
193
|
+
*/
|
|
194
|
+
failWithError?: boolean;
|
|
211
195
|
};
|
|
212
196
|
/**
|
|
213
197
|
* Returns the value of an object property using a path.
|
|
214
198
|
*
|
|
215
|
-
* @param options The options to use.
|
|
216
|
-
* @template T The type of the returned object.
|
|
217
|
-
* @throws {Error} If the path is invalid and `failWithError` is set to `true`.
|
|
218
199
|
* @example
|
|
219
|
-
*
|
|
220
200
|
* const obj = {
|
|
221
201
|
* propOne: {
|
|
222
202
|
* propOneSub: 'Charito!',
|
|
@@ -226,83 +206,79 @@ type GetOptions = {
|
|
|
226
206
|
* console.log(get({ target: obj, path: 'propOne.propOneSub' }));
|
|
227
207
|
* // Will output 'Charito!'
|
|
228
208
|
*
|
|
209
|
+
* @template T The type of the returned object.
|
|
210
|
+
* @param options The options to use.
|
|
211
|
+
* @throws {Error} If the path is invalid and `failWithError` is set to `true`.
|
|
229
212
|
*/
|
|
230
213
|
declare function get<T>(options: GetOptions): T | undefined;
|
|
231
214
|
declare function get<T>(options: unknown, path: string): T | undefined;
|
|
232
|
-
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/fns/lowerCamelToDashKeys.d.ts
|
|
233
217
|
/**
|
|
234
|
-
* A shorthand method for {@link formatKeys} that transforms the keys from
|
|
235
|
-
*
|
|
218
|
+
* A shorthand method for {@link formatKeys} that transforms the keys from `lowerCamelCase`
|
|
219
|
+
* to `dash-case`.
|
|
236
220
|
*
|
|
237
|
-
* @
|
|
238
|
-
* @
|
|
221
|
+
* @template T The type of the returned object.
|
|
222
|
+
* @param options The options to use.
|
|
239
223
|
*/
|
|
240
224
|
declare const lowerCamelToDashKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
241
|
-
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/fns/lowerCamelToSnakeKeys.d.ts
|
|
242
227
|
/**
|
|
243
228
|
* A shorthand method for {@link formatKeys} that transforms the keys from
|
|
244
229
|
* `lowerCamelCase` to `snake_case`.
|
|
245
230
|
*
|
|
246
|
-
* @
|
|
247
|
-
* @
|
|
231
|
+
* @template T The type of the returned object.
|
|
232
|
+
* @param options The options to use.
|
|
248
233
|
*/
|
|
249
234
|
declare const lowerCamelToSnakeKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
250
|
-
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/fns/merge.d.ts
|
|
251
237
|
/**
|
|
252
238
|
* This method makes a deep merge of a list of objects into a new one. The method also
|
|
253
239
|
* supports arrays: if the first element is an array, it will be merged into an array,
|
|
254
240
|
* otherwise, it will be an object.
|
|
255
241
|
*
|
|
256
|
-
* @param targets The list of objects to merge.
|
|
257
|
-
* @template T The type of the merged object that will be returned.
|
|
258
242
|
* @example
|
|
259
|
-
*
|
|
260
243
|
* const objA = { a: 'first' };
|
|
261
244
|
* const objB = { b: 'second' };
|
|
262
245
|
* console.log(merge(objA, objB));
|
|
263
246
|
* // Will output { a: 'first', b: 'second' }
|
|
264
247
|
*
|
|
265
248
|
* @example
|
|
266
|
-
*
|
|
267
249
|
* const arrA = [{ a: 'first' }];
|
|
268
250
|
* const arrB = [{ b: 'second' }];
|
|
269
251
|
* console.log(merge(objA, objB));
|
|
270
252
|
* // Will output [{ a: 'first', b: 'second' }]
|
|
271
253
|
*
|
|
254
|
+
* @template T The type of the merged object that will be returned.
|
|
255
|
+
* @param targets The list of objects to merge.
|
|
272
256
|
*/
|
|
273
257
|
declare const merge: <T = unknown>(...targets: unknown[]) => T;
|
|
274
|
-
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/fns/remove.d.ts
|
|
275
260
|
type RemoveOptions = {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
failWithError?: boolean;
|
|
293
|
-
/**
|
|
294
|
-
* If this flag is `true` and after removing the property the parent object is empty,
|
|
295
|
-
* it will remove it recursively until a non empty parent object is found.
|
|
296
|
-
*/
|
|
297
|
-
cleanEmptyProperties?: boolean;
|
|
261
|
+
/** The object from where the property will be removed. */
|
|
262
|
+
target: unknown;
|
|
263
|
+
/** The path to the property. */
|
|
264
|
+
path: string;
|
|
265
|
+
/** The delimiter that will separate the path components. */
|
|
266
|
+
pathDelimiter?: string;
|
|
267
|
+
/**
|
|
268
|
+
* Whether or not to throw an error when the path is invalid. If this is `false`, the
|
|
269
|
+
* function will silently fail.
|
|
270
|
+
*/
|
|
271
|
+
failWithError?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* If this flag is `true` and after removing the property the parent object is empty, it
|
|
274
|
+
* will remove it recursively until a non empty parent object is found.
|
|
275
|
+
*/
|
|
276
|
+
cleanEmptyProperties?: boolean;
|
|
298
277
|
};
|
|
299
278
|
/**
|
|
300
279
|
* Deletes a property of an object using a path.
|
|
301
280
|
*
|
|
302
|
-
* @param options The options to use.
|
|
303
|
-
* @template T The type of the returned object.
|
|
304
281
|
* @example
|
|
305
|
-
*
|
|
306
282
|
* const target = {
|
|
307
283
|
* propOne: {
|
|
308
284
|
* propOneSub: 'Charito!',
|
|
@@ -312,87 +288,77 @@ type RemoveOptions = {
|
|
|
312
288
|
* console.log(remove({ target, path: 'propOne.propOneSub' }));
|
|
313
289
|
* // Will output { propTwo: '!!!' }
|
|
314
290
|
*
|
|
291
|
+
* @template T The type of the returned object.
|
|
292
|
+
* @param options The options to use.
|
|
315
293
|
*/
|
|
316
294
|
declare function remove<T = unknown>(options: RemoveOptions): T | undefined;
|
|
317
295
|
declare function remove<T = unknown>(options: unknown, path: string): T | undefined;
|
|
318
|
-
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/fns/set.d.ts
|
|
319
298
|
type SetOptions = {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
* The delimiter that will separate the path components.
|
|
334
|
-
*/
|
|
335
|
-
pathDelimiter?: string;
|
|
336
|
-
/**
|
|
337
|
-
* Whether or not to throw an error when the path is invalid. If this is `false`, the method
|
|
338
|
-
* will silently fail and return `undefined`.
|
|
339
|
-
*/
|
|
340
|
-
failWithError?: boolean;
|
|
299
|
+
/** The object where the property will be set. */
|
|
300
|
+
target: unknown;
|
|
301
|
+
/** The path for the property. */
|
|
302
|
+
path: string;
|
|
303
|
+
/** The value to set on the property. */
|
|
304
|
+
value: unknown;
|
|
305
|
+
/** The delimiter that will separate the path components. */
|
|
306
|
+
pathDelimiter?: string;
|
|
307
|
+
/**
|
|
308
|
+
* Whether or not to throw an error when the path is invalid. If this is `false`, the
|
|
309
|
+
* method will silently fail and return `undefined`.
|
|
310
|
+
*/
|
|
311
|
+
failWithError?: boolean;
|
|
341
312
|
};
|
|
342
313
|
/**
|
|
343
314
|
* Sets a property on an object using a path. If the path doesn't exist, it will be
|
|
344
315
|
* created.
|
|
345
316
|
*
|
|
346
|
-
* @param options The options to use.
|
|
347
|
-
* @template T The type of the returned object.
|
|
348
|
-
* @throws {Error} If one of the path components is for a non-object property and
|
|
349
|
-
* `failWithError` is set to `true`.
|
|
350
317
|
* @example
|
|
351
|
-
*
|
|
352
318
|
* const target = {};
|
|
353
319
|
* console.log(set({ target, path: 'some.prop.path', value: 'some-value' }));
|
|
354
320
|
* // Will output { some: { prop: { path: 'some-value' } } }
|
|
355
321
|
*
|
|
322
|
+
* @template T The type of the returned object.
|
|
323
|
+
* @param options The options to use.
|
|
324
|
+
* @throws {Error} If one of the path components is for a non-object property and
|
|
325
|
+
* `failWithError` is set to `true`.
|
|
356
326
|
*/
|
|
357
327
|
declare function set<T = Record<string, unknown>>(options: SetOptions): T | undefined;
|
|
358
328
|
declare function set<T = Record<string, unknown>>(options: SetOptions | unknown, path: string, value: unknown): T | undefined;
|
|
359
|
-
|
|
329
|
+
//#endregion
|
|
330
|
+
//#region src/fns/snakeToDashKeys.d.ts
|
|
360
331
|
/**
|
|
361
332
|
* A shorthand method for {@link formatKeys} that transforms the keys from `snake_case` to
|
|
362
333
|
* `dash-case`.
|
|
363
334
|
*
|
|
364
|
-
* @
|
|
365
|
-
* @
|
|
335
|
+
* @template T The type of the returned object.
|
|
336
|
+
* @param options The options to use.
|
|
366
337
|
*/
|
|
367
338
|
declare const snakeToDashKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
368
|
-
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region src/fns/snakeToLowerCamelKeys.d.ts
|
|
369
341
|
/**
|
|
370
342
|
* A shorthand method for {@link formatKeys} that transforms the keys from `snake_case` to
|
|
371
343
|
* `lowerCamelCase`.
|
|
372
344
|
*
|
|
373
|
-
* @
|
|
374
|
-
* @
|
|
345
|
+
* @template T The type of the returned object.
|
|
346
|
+
* @param options The options to use.
|
|
375
347
|
*/
|
|
376
348
|
declare const snakeToLowerCamelKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
377
|
-
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/fns/unflat.d.ts
|
|
378
351
|
type UnflatOptions = {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* The delimiter that will separate the path components.
|
|
385
|
-
*/
|
|
386
|
-
pathDelimiter?: string;
|
|
352
|
+
/** The object to transform. */
|
|
353
|
+
target: unknown;
|
|
354
|
+
/** The delimiter that will separate the path components. */
|
|
355
|
+
pathDelimiter?: string;
|
|
387
356
|
};
|
|
388
357
|
/**
|
|
389
358
|
* This method does the exact opposite from `flat`: It takes an already flatten object and
|
|
390
359
|
* restores it structure.
|
|
391
360
|
*
|
|
392
|
-
* @param options The options to use.
|
|
393
|
-
* @template T The type of the returned object.
|
|
394
361
|
* @example
|
|
395
|
-
*
|
|
396
362
|
* const target = {
|
|
397
363
|
* 'propOne.propOneSub': 'Charito!',
|
|
398
364
|
* propTwo: '!!!',
|
|
@@ -400,7 +366,10 @@ type UnflatOptions = {
|
|
|
400
366
|
* console.log(unflat({ target }));
|
|
401
367
|
* // Will output { propOne: { propOneSub: 'Charito!' }, 'propTwo': '!!!' }
|
|
402
368
|
*
|
|
369
|
+
* @template T The type of the returned object.
|
|
370
|
+
* @param options The options to use.
|
|
403
371
|
*/
|
|
404
372
|
declare const unflat: <T = Record<string, unknown>>(options: UnflatOptions) => T;
|
|
405
|
-
|
|
406
|
-
export {
|
|
373
|
+
//#endregion
|
|
374
|
+
export { ExtractOptions, FlatOptions, FormatKeysExtensionOptions, FormatKeysOptions, FormatKeysReplaceFn, GetOptions, RemoveOptions, SetOptions, ShouldFlattenFn, UnflatOptions, copy, dashToLowerCamelKeys, dashToSnakeKeys, extract, extractionPath, flat, formatKeys, get, lowerCamelToDashKeys, lowerCamelToSnakeKeys, merge, remove, set, snakeToDashKeys, snakeToLowerCamelKeys, unflat };
|
|
375
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import e from"extend";const t=(...t)=>{let[n]=t;return e(!0,Array.isArray(n)?[]:{},...t)},n=e=>t(e),r=e=>{let{target:t,search:n,replace:i,include:a=[],exclude:o=[],pathDelimiter:s=`.`}=e,c=t,l=Object.keys(t),u={};l.forEach(e=>{let t=c[e];u[e]=!!(t&&typeof t==`object`&&t&&!Array.isArray(t)&&Object.keys(t))});let d=s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),f=RegExp(`^${d}`,`i`),p=RegExp(`${d}$`,`i`),m={},h;h=a.length?a.map(e=>{let t=e.replace(f,``).replace(p,``),n;if(t.includes(s)){let e=t.split(s),r=e.shift();n=``,m[r]||(m[r]=[]),m[r].push(e.join(s))}else n=t;return n}).filter(e=>e):l;let g={};if(o.length){let e=[];o.forEach(t=>{let n=t.replace(f,``).replace(p,``);if(n.includes(s)){let e=n.split(s),t=e.shift();g[t]||(g[t]=[]),g[t].push(e.join(s))}else u[n]=!1,e.push(n)}),h=h.filter(t=>t&&!e.includes(t))}return l.reduce((e,t)=>{let a,o,l=c[t];return a=h.includes(t)?t.replace(n,i):t,o=u[t]?r({target:l,search:n,replace:i,include:m[t]||[],exclude:g[t]||[],pathDelimiter:s}):l,{...e,[a]:o}},{})},i=e=>r({...e,search:/([a-z])-([a-z])/g,replace:(e,t,n)=>`${t}${n.toUpperCase()}`}),a=e=>r({...e,search:/([a-z])-([a-z])/g,replace:(e,t,n)=>`${t}_${n}`});function o(e,t){let n;n=typeof t==`string`?{target:e,path:t}:e;let{target:r,path:i,pathDelimiter:a=`.`,failWithError:o=!1}=n,s=r,c=i.split(a),l=c.shift(),u=s[l];if(u===void 0){if(o)throw Error(`There's nothing on '${i}'`);return}if(!c.length)return u;let d=l;return c.some(e=>{let t=!1;if(d+=`${a}${e}`,u=u[e],u===void 0){if(o)throw Error(`There's nothing on '${d}'`);t=!0}return t}),u}const s=[`__proto__`,`prototype`,`constructor`];function c(e,t,r){let i;i=typeof t==`string`?{target:e,path:t,value:r}:e;let{target:a,path:o,value:c,pathDelimiter:l=`.`,failWithError:u=!1}=i,d=n(a);if(!o.includes(l))return!o||s.includes(o.toLowerCase())?void 0:(d[o]=c,d);let f=o.split(l);if(f.some(e=>!e||s.includes(e.toLowerCase())))return;let p=f.pop(),m=d,h=``,g=!1;if(f.forEach(e=>{h+=`${l}${e}`;let t=typeof m[e];if(t===`undefined`)m[e]={},m=m[e];else if(t===`object`)m=m[e];else{let e=h.substring(l.length);if(u)throw Error(`There's already an element of type '${t}' on '${e}'`);g=!0}}),!g)return m[p]=c,d}const l=e=>{let{target:t,paths:r,pathDelimiter:i=`.`,failWithError:a=!1}=e,s=n(t),l={},u=!1;if((Array.isArray(r)?r:[r]).reduce((e,t)=>{let n,r;if(typeof t==`string`)n=t,r=t;else{let[e]=Object.keys(t);n=e,r=t[n]}return e.push({origin:r,customDest:n.includes(i),dest:n}),e},[]).some(e=>{let t=!1,n=o({target:s,path:e.origin,pathDelimiter:i,failWithError:a});if(n!==void 0)if(e.customDest){let r=c({target:l,path:e.dest,value:n,pathDelimiter:i,failWithError:a});r===void 0?(t=!0,u=!0):l=r}else l[e.dest]=n;return t}),!u)return l},u=e=>{let{target:r,shouldFlatten:i,pathDelimiter:a=`.`,prefix:o=``}=e,s=r,c={},l=o?`${o}${a}`:``;return Object.keys(s).forEach(e=>{let r=`${l}${e}`,o=s[e],d=typeof o==`object`&&!!o;d&&(!i||i(e,o))?c=t(c,u({target:o,pathDelimiter:a,prefix:r,shouldFlatten:i})):c[r]=d?n(o):o}),c},d=e=>r({...e,search:/([a-z])([A-Z])/g,replace:(e,t,n)=>`${t}-${n.toLowerCase()}`}),f=e=>r({...e,search:/([a-z])([A-Z])/g,replace:(e,t,n)=>`${t}_${n.toLowerCase()}`});function p(e,t){let r;r=typeof t==`string`?{target:e,path:t}:e;let{target:i,path:a,pathDelimiter:s=`.`,cleanEmptyProperties:c=!0,failWithError:l=!1}=r,u=a.split(s),d=u.pop(),f=n(i);if(!u.length)return delete f[d],f;let m=u.join(s),h=o({target:f,path:m,pathDelimiter:s,failWithError:l});if(h!==void 0)return delete h[d],c&&!Object.keys(h).length?p({target:f,path:m,pathDelimiter:s,failWithError:l,cleanEmptyProperties:c}):f}const m=e=>r({...e,search:/([a-z])_([a-z])/g,replace:(e,t,n)=>`${t}-${n}`}),h=e=>r({...e,search:/([a-z])_([a-z])/g,replace:(e,t,n)=>`${t}${n.toUpperCase()}`}),g=e=>{let{target:t,pathDelimiter:n=`.`}=e,r=t;return Object.keys(r).reduce((e,t)=>c({target:e,path:t,value:r[t],pathDelimiter:n}),{})};export{n as copy,i as dashToLowerCamelKeys,a as dashToSnakeKeys,l as extract,u as flat,r as formatKeys,o as get,d as lowerCamelToDashKeys,f as lowerCamelToSnakeKeys,t as merge,p as remove,c as set,m as snakeToDashKeys,h as snakeToLowerCamelKeys,g as unflat};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fns/merge.ts","../src/fns/copy.ts","../src/fns/formatKeys.ts","../src/fns/dashToLowerCamelKeys.ts","../src/fns/dashToSnakeKeys.ts","../src/fns/get.ts","../src/fns/set.ts","../src/fns/extract.ts","../src/fns/flat.ts","../src/fns/lowerCamelToDashKeys.ts","../src/fns/lowerCamelToSnakeKeys.ts","../src/fns/remove.ts","../src/fns/snakeToDashKeys.ts","../src/fns/snakeToLowerCamelKeys.ts","../src/fns/unflat.ts"],"sourcesContent":["import extend from 'extend';\n\n/**\n * This method makes a deep merge of a list of objects into a new one. The method also\n * supports arrays: if the first element is an array, it will be merged into an array,\n * otherwise, it will be an object.\n *\n * @param targets The list of objects to merge.\n * @template T The type of the merged object that will be returned.\n * @example\n *\n * const objA = { a: 'first' };\n * const objB = { b: 'second' };\n * console.log(merge(objA, objB));\n * // Will output { a: 'first', b: 'second' }\n *\n * @example\n *\n * const arrA = [{ a: 'first' }];\n * const arrB = [{ b: 'second' }];\n * console.log(merge(objA, objB));\n * // Will output [{ a: 'first', b: 'second' }]\n *\n */\nexport const merge = <T = unknown>(...targets: unknown[]): T => {\n const [firstTarget] = targets;\n const base = Array.isArray(firstTarget) ? [] : {};\n return extend(true, base, ...targets) as T;\n};\n","import { merge } from './merge.js';\n\n/**\n * Creates a deep copy of a given object.\n *\n * @param target The object to copy.\n * @template T The type of the input object, which will be the same as the one\n * returned.\n */\nexport const copy = <T>(target: T): T => merge(target);\n","/**\n * The callback that will be used to replace a key.\n *\n * @param substring The captured string to replace.\n * @param args The list of groups captured by the expression.\n */\nexport type FormatKeysReplaceFn = (substring: string, ...args: string[]) => string;\n\nexport type FormatKeysOptions = {\n /**\n * The object to transform.\n */\n target: unknown;\n /**\n * A regular expression to match the keys to transform.\n */\n search: RegExp;\n /**\n * The callback that will be used to replace the matched substring. Think of `search` and\n * `replace` as the parameters of `String.replace`.\n */\n replace: FormatKeysReplaceFn;\n /**\n * A list of keys or paths where the transformation will be made. If not specified, the\n * function will use all the keys from the object.\n */\n include?: string[];\n /**\n * A list of keys or paths where the transformation won't be made.\n */\n exclude?: string[];\n /**\n * The delimiter that will separate the path components for both `include` and `exclude`.\n */\n pathDelimiter?: string;\n};\n\nexport type FormatKeysExtensionOptions = Omit<FormatKeysOptions, 'search' | 'replace'>;\n\n/**\n * Formats all the keys on an object using a way similar to `.replace(regexp, ...)` but\n * that also works recursively and with _\"object paths\"_.\n *\n * @param options The set of options to customize the transformation.\n * @template T The type of the returned object.\n * @example\n *\n * const target = {\n * prop_one: 'Charito!',\n * };\n * console.log(\n * formatKeys({\n * target,\n * // Find all the keys with snake case.\n * search: /([a-z])_([a-z])/g,\n * // Using the same .replace style callback, replace it with lower camel case.\n * replace: (_, firstLetter, secondLetter) => {\n * const newSecondLetter = secondLetter.toUpperCase();\n * return `${firstLetter}${newSecondLetter}`;\n * },\n * }),\n * );\n * // Will output { propOne: 'Charito!}.\n *\n */\nexport const formatKeys = <T = Record<string, unknown>>(\n options: FormatKeysOptions,\n): T => {\n const {\n target,\n search,\n replace,\n include = [],\n exclude = [],\n pathDelimiter = '.',\n } = options;\n // Re-case target.\n const useTarget = target as Record<string, unknown>;\n // First of all, get all the keys from the target.\n const keys = Object.keys(target as Record<string, unknown>);\n /**\n * Then, check which keys are parent to other objects.\n * This is saved on a dictionary not only because it makes it easier to check if the\n * method should make a recursive call for a key, but also because when parsing the\n * `exclude`\n * parameter, if one of items is a key (and not an specific path), the method won't make\n * the recursive call.\n *\n * @ignore\n */\n const hasChildrenByKey: Record<string, unknown> = {};\n keys.forEach((key) => {\n const value = useTarget[key];\n hasChildrenByKey[key] = !!(\n value &&\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n Object.keys(value)\n );\n });\n /**\n * Escape the path delimiter and create two regular expression: One that removes the path\n * delimiter from the start of a path and one that removes it from the end.\n * They are later used to normalize paths in order to avoid \"incomplete paths\" (paths that\n * end or start with the delimiter).\n */\n const escapedPathDelimiter = pathDelimiter.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&');\n const cleanPathStartExpression = new RegExp(`^${escapedPathDelimiter}`, 'i');\n const cleanPathEndExpression = new RegExp(`${escapedPathDelimiter}$`, 'i');\n /**\n * This dictionary will be used to save the `include` parameter that will be sent for specific\n * keys on recursive calls.\n * If `include` has a path like `myKey.mySubKey`, `myKey` is not transformed, but `mySubKey`\n * is saved on this dictionary (`{ myKey: ['mySubKey']}`) and when the method applies the\n * formatting to the object, if `myKey` has an object, it will make a recursive all and\n * send `['mySubKey]` as its `include` parameter.\n */\n const subIncludeByKey: Record<string, string[]> = {};\n /**\n * This will be an array containing the final list of `keys` that should be tranformed.\n * To be clear, these keys will be from the top level, so, they won't be paths.\n * Thd following blocks will parse `include` and `exclude` in order to extract the real keys,\n * prepare the `include` and `exclude` for recursive calls, and save the actual keys\n * from the object \"at the current level of this call\" (no, it's not thinking about the\n * children :P).\n */\n let keysToFormat: string[];\n // If the `include` parameter has paths/keys...\n if (include.length) {\n keysToFormat = include\n .map((includePath) => {\n // Normalize the path/key.\n const useIncludePath = includePath\n .replace(cleanPathStartExpression, '')\n .replace(cleanPathEndExpression, '');\n // Define the variable that will, eventually, have the real key.\n let key;\n // If the value is a path...\n if (useIncludePath.includes(pathDelimiter)) {\n // Split all its components.\n const pathParts = useIncludePath.split(pathDelimiter);\n // Get the first component, a.k.a. the real key.\n const pathKey = pathParts.shift()!;\n /**\n * This is very important: Since the path was specified with sub components\n * (like `myProp.mySubProp`), the method won't format the key, but the sub\n * key(s)\n * (`mySubProp`).\n * The `key` is set to `''` so it will be later removed using `.filter`.\n *\n * @ignore\n */\n key = '';\n /**\n * If there's no array for the key on the \"`include` dictionary for recursive calls\",\n * create an empty one.\n */\n if (!subIncludeByKey[pathKey]) {\n subIncludeByKey[pathKey] = [];\n }\n // Save the rest of the path to be sent on the recursive call as `include`.\n subIncludeByKey[pathKey]!.push(pathParts.join(pathDelimiter));\n } else {\n // If the value wasn't a path, assume it's a key, and set it to be returned.\n key = useIncludePath;\n }\n\n return key;\n })\n // Remove any _empty keys_.\n .filter((key) => key);\n } else {\n // There's nothing on the `include` parameter, so use all the keys.\n keysToFormat = keys;\n }\n /**\n * Similar to `subIncludeByKey`, this dictionary will be used to save the `exclude` parameter\n * that will be sent for specific keys on recursive calls.\n * If `exclude` has a path like `myKey.mySubKey`, `myKey` will be transformed, but `mySubKey`\n * is saved on this dictionary (`{ myKey: ['mySubKey']}`) and when the method applies the\n * formatting to the object, if `myKey` has an object, it will make a recursive all and\n * send `['mySubKey]` as its `exclude` parameter.\n */\n const subExcludeByKey: Record<string, string[]> = {};\n // If the `include` parameter has paths/keys...\n if (exclude.length) {\n /**\n * Create a dictionary of keys that should be removed from `keysToFormat`.\n * It's easier to have them on a list and use `.filter` than actually call `.splice` for\n * every key that should be removed.\n */\n const keysToRemove: string[] = [];\n exclude.forEach((excludePath) => {\n // Normalize the path/key.\n const useExcludePath = excludePath\n .replace(cleanPathStartExpression, '')\n .replace(cleanPathEndExpression, '');\n // If the value is a path...\n if (useExcludePath.includes(pathDelimiter)) {\n // Split all its components.\n const pathParts = useExcludePath.split(pathDelimiter);\n // Get the first component, a.k.a. the real key.\n const pathKey = pathParts.shift()!;\n /**\n * If there's no array for the key on the \"`exclude` dictionary for recursive calls\",\n * create an empty one.\n */\n if (!subExcludeByKey[pathKey]) {\n subExcludeByKey[pathKey] = [];\n }\n // Save the rest of the path to be sent on the recursive call as `exclude`.\n subExcludeByKey[pathKey]!.push(pathParts.join(pathDelimiter));\n } else {\n /**\n * If the value wasn't a path, assume it's a key, turn the flag on the \"children\n * dictionary\" to `false`, to prevent recursive calls, and add the key to the list\n * of keys that will be removed from `keysToFormat`.\n * Basically: If it's a key, don't format it and don't make recursive calls for\n * it.\n *\n * @ignore\n */\n hasChildrenByKey[useExcludePath] = false;\n keysToRemove.push(useExcludePath);\n }\n });\n // Remove keys that should be excluded.\n keysToFormat = keysToFormat.filter((key) => key && !keysToRemove.includes(key));\n }\n // \"Finally\", reduce all the keys from the object and create the new one...\n return keys.reduce<Record<string, unknown>>((newObj, key) => {\n /**\n * Define the new key and value for the object property. Depending on the validations,\n * they may be replaced with formatted ones.\n */\n let newKey;\n let newValue;\n /**\n * Get the current value for the key, in case it's needed for a recursive call or just\n * to send it back because it didn't need any change.\n */\n const value = useTarget[key];\n // If the key should be formatted, apply the formatting; otherwise, keep the original.\n if (keysToFormat.includes(key)) {\n newKey = key.replace(search, replace);\n } else {\n newKey = key;\n }\n /**\n * If the paths/keys on `exclude` didn't modify the \"children dictionary\" for the key and\n * the value is another object, make a recursive call; otherwise, just use the original\n * value.\n */\n if (hasChildrenByKey[key]) {\n newValue = formatKeys({\n target: value,\n search,\n replace,\n include: subIncludeByKey[key] || [],\n exclude: subExcludeByKey[key] || [],\n pathDelimiter,\n });\n } else {\n newValue = value;\n }\n // \"Done\", return the new object with the \"new key\" and the \"new value\".\n return { ...newObj, [newKey]: newValue };\n }, {}) as T;\n};\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from `dash-case`\n * to `lowerCamelCase`.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n */\nexport const dashToLowerCamelKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])-([a-z])/g,\n replace: (_, firstLetter, secondLetter) => {\n const newSecondLetter = secondLetter.toUpperCase();\n return `${firstLetter}${newSecondLetter}`;\n },\n });\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from `dash-case`\n * to `snake_case`.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n */\nexport const dashToSnakeKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])-([a-z])/g,\n replace: (_, firstLetter, secondLetter) => `${firstLetter}_${secondLetter}`,\n });\n","export type GetOptions = {\n /**\n * The object from where the property will be read.\n */\n target: unknown;\n /**\n * The path to the property.\n */\n path: string;\n /**\n * The delimiter that will separate the path components.\n */\n pathDelimiter?: string;\n /**\n * Whether or not to throw an error when the path is invalid. If this is `false`,\n * the method will silently fail and return `undefined`.\n */\n failWithError?: boolean;\n};\n\n/**\n * Returns the value of an object property using a path.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n * @throws {Error} If the path is invalid and `failWithError` is set to `true`.\n * @example\n *\n * const obj = {\n * propOne: {\n * propOneSub: 'Charito!',\n * },\n * propTwo: '!!!',\n * };\n * console.log(get({ target: obj, path: 'propOne.propOneSub' }));\n * // Will output 'Charito!'\n *\n */\nfunction get<T>(options: GetOptions): T | undefined;\nfunction get<T>(options: unknown, path: string): T | undefined;\nfunction get<T>(options: GetOptions | unknown, path?: string): T | undefined {\n let useOptions: GetOptions;\n if (typeof path === 'string') {\n useOptions = {\n target: options,\n path,\n };\n } else {\n useOptions = options as GetOptions;\n }\n\n const {\n target,\n path: usePath,\n pathDelimiter = '.',\n failWithError = false,\n } = useOptions;\n const useTarget = target as Record<string, unknown>;\n const parts = usePath.split(pathDelimiter);\n const first = parts.shift()!;\n let currentElement = useTarget[first] as Record<string, unknown>;\n if (typeof currentElement === 'undefined') {\n if (failWithError) {\n throw new Error(`There's nothing on '${usePath}'`);\n }\n\n return undefined;\n }\n\n if (!parts.length) {\n return currentElement as T;\n }\n\n let currentPath = first;\n parts.some((currentPart) => {\n let breakLoop = false;\n currentPath += `${pathDelimiter}${currentPart}`;\n currentElement = currentElement[currentPart] as Record<string, unknown>;\n if (typeof currentElement === 'undefined') {\n if (failWithError) {\n throw new Error(`There's nothing on '${currentPath}'`);\n } else {\n breakLoop = true;\n }\n }\n\n return breakLoop;\n });\n\n return currentElement as T;\n}\n\nexport { get };\n","import { copy } from './copy.js';\n\n/**\n * List of paths that are forbidden to use on the `set` function, as they could lead to\n * security issues.\n *\n * @access protected\n */\nconst FORBIDDEN_PATHS = ['__proto__', 'prototype', 'constructor'];\n\nexport type SetOptions = {\n /**\n * The object where the property will be set.\n */\n target: unknown;\n /**\n * The path for the property.\n */\n path: string;\n /**\n * The value to set on the property.\n */\n value: unknown;\n /**\n * The delimiter that will separate the path components.\n */\n pathDelimiter?: string;\n /**\n * Whether or not to throw an error when the path is invalid. If this is `false`, the method\n * will silently fail and return `undefined`.\n */\n failWithError?: boolean;\n};\n/**\n * Sets a property on an object using a path. If the path doesn't exist, it will be\n * created.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n * @throws {Error} If one of the path components is for a non-object property and\n * `failWithError` is set to `true`.\n * @example\n *\n * const target = {};\n * console.log(set({ target, path: 'some.prop.path', value: 'some-value' }));\n * // Will output { some: { prop: { path: 'some-value' } } }\n *\n */\nfunction set<T = Record<string, unknown>>(options: SetOptions): T | undefined;\nfunction set<T = Record<string, unknown>>(\n options: SetOptions | unknown,\n path: string,\n value: unknown,\n): T | undefined;\nfunction set<T = Record<string, unknown>>(\n options: SetOptions | unknown,\n path?: string,\n value?: unknown,\n): T | undefined {\n let useOptions: SetOptions;\n if (typeof path === 'string') {\n useOptions = {\n target: options,\n path,\n value,\n };\n } else {\n useOptions = options as SetOptions;\n }\n\n const {\n target,\n path: usePath,\n value: useValue,\n pathDelimiter = '.',\n failWithError = false,\n } = useOptions;\n const result = copy(target) as Record<string, unknown>;\n if (!usePath.includes(pathDelimiter)) {\n if (!usePath || FORBIDDEN_PATHS.includes(usePath.toLowerCase())) {\n return undefined;\n }\n\n result[usePath] = useValue;\n return result as T;\n }\n\n const parts = usePath.split(pathDelimiter);\n const isInvalid = parts.some(\n (part) => !part || FORBIDDEN_PATHS.includes(part.toLowerCase()),\n );\n\n if (isInvalid) {\n return undefined;\n }\n\n // Path validation ensures that every component is defined and non-empty.\n const last = parts.pop()!;\n let currentElement = result;\n let currentPath = '';\n let foundInvalid = false;\n parts.forEach((part) => {\n currentPath += `${pathDelimiter}${part}`;\n const element = currentElement[part];\n const elementType = typeof element;\n if (elementType === 'undefined') {\n currentElement[part] = {};\n currentElement = currentElement[part] as Record<string, unknown>;\n } else if (elementType === 'object') {\n currentElement = currentElement[part] as Record<string, unknown>;\n } else {\n const errorPath = currentPath.substring(pathDelimiter.length);\n if (failWithError) {\n throw new Error(\n `There's already an element of type '${elementType}' on '${errorPath}'`,\n );\n } else {\n foundInvalid = true;\n }\n }\n });\n\n if (foundInvalid) return undefined;\n\n currentElement[last] = useValue;\n\n return result as T | undefined;\n}\n\nexport { set };\n","import { get } from './get.js';\nimport { set } from './set.js';\nimport { copy } from './copy.js';\n/**\n * Used in the {@link extract} function to specify a path for a property, or an \"origin path\"\n * and an \"extraction path\".\n */\nexport type extractionPath = string | Record<string, string>;\n\nexport type ExtractOptions = {\n /**\n * The object from where the property/properties will be extracted.\n */\n target: unknown;\n /**\n * This can be a single path or a list of them. And for this method, the paths are not\n * only strings but can also be an object with a single key, that would be the path to\n * where to \"do the extraction\", and the value the path on the target object.\n */\n paths: extractionPath | extractionPath[];\n /**\n * The delimiter that will separate the path components.\n */\n pathDelimiter?: string;\n /**\n * Whether or not to throw an error when the path is invalid. If this is `false`, the\n * method will silently fail an empty object.\n */\n failWithError?: boolean;\n};\n/**\n * Extracts a property or properties from an object in order to create a new one.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n * @example\n *\n * const target = {\n * name: {\n * first: 'Pilar',\n * },\n * age: 3,\n * address: {\n * planet: 'earth',\n * something: 'else',\n * },\n * };\n * console.log(\n * extract({\n * target: obj,\n * paths: [{ name: 'name.first' }, 'age', 'address.planet'],\n * }),\n * );\n * // Will output { name: 'Pilar', age: 3, address: { planet: 'earth' } }\n *\n */\nexport const extract = <T = Record<string, unknown>>(\n options: ExtractOptions,\n): T | undefined => {\n const { target, paths, pathDelimiter = '.', failWithError = false } = options;\n const copied = copy(target) as Record<string, unknown>;\n let result: Record<string, unknown> = {};\n let failed = false;\n (Array.isArray(paths) ? paths : [paths])\n .reduce<Array<{ origin: string; customDest: boolean; dest: string }>>(\n (acc, objPath) => {\n let destPath: string;\n let originPath: string;\n if (typeof objPath === 'string') {\n destPath = objPath;\n originPath = objPath;\n } else {\n const [firstKey] = Object.keys(objPath);\n destPath = firstKey!;\n originPath = objPath[destPath]!;\n }\n\n acc.push({\n origin: originPath,\n customDest: destPath.includes(pathDelimiter),\n dest: destPath,\n });\n return acc;\n },\n [],\n )\n .some((pathInfo) => {\n let breakLoop = false;\n const value = get({\n target: copied,\n path: pathInfo.origin,\n pathDelimiter,\n failWithError,\n });\n if (typeof value !== 'undefined') {\n if (pathInfo.customDest) {\n const withCustomProp = set({\n target: result,\n path: pathInfo.dest,\n value,\n pathDelimiter,\n failWithError,\n });\n if (typeof withCustomProp === 'undefined') {\n breakLoop = true;\n failed = true;\n } else {\n result = withCustomProp;\n }\n } else {\n result[pathInfo.dest] = value;\n }\n }\n\n return breakLoop;\n });\n\n if (failed) return undefined;\n return result as T;\n};\n","import { copy } from './copy.js';\nimport { merge } from './merge.js';\n\n/**\n * Checks whether a key for an array or an Object should be flattened.\n *\n * @param key The key to check inside its parent.\n * @param value The value of the key.\n */\nexport type ShouldFlattenFn = (key: string, value: unknown) => boolean;\n\nexport type FlatOptions = {\n /**\n * The object to transform.\n */\n target: unknown;\n /**\n * A custom prefix to be added before the name of the properties. This can be used on\n * custom cases and it's also used when the method calls itself in order to flatten a\n * sub object.\n */\n prefix?: string;\n /**\n * The delimiter that will separate the path components.\n */\n pathDelimiter?: string;\n /**\n * A custom function that can be used in order to tell the function whether an Object or\n * an Array property should be flatten or not.\n */\n shouldFlatten?: ShouldFlattenFn;\n};\n/**\n * Flattens an object properties into a single level dictionary.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n * @example\n *\n * const target = {\n * propOne: {\n * propOneSub: 'Charito!',\n * },\n * propTwo: '!!!',\n * };\n * console.log(flat({ target });\n * // Will output { 'propOne.propOneSub': 'Charito!', propTwo: '!!!' }\n *\n */\nexport const flat = <T = Record<string, unknown>>(options: FlatOptions): T => {\n const { target, shouldFlatten, pathDelimiter = '.', prefix = '' } = options;\n const useTarget = target as Record<string, unknown>;\n let result: Record<string, unknown> = {};\n const namePrefix = prefix ? `${prefix}${pathDelimiter}` : '';\n Object.keys(useTarget).forEach((key) => {\n const name = `${namePrefix}${key}`;\n const value = useTarget[key] as unknown;\n const valueType = typeof value;\n const isObject = valueType === 'object' && value !== null;\n if (isObject && (!shouldFlatten || shouldFlatten(key, value))) {\n result = merge(\n result,\n flat({ target: value, pathDelimiter, prefix: name, shouldFlatten }),\n );\n } else {\n result[name] = isObject ? copy(value) : value;\n }\n });\n\n return result as T;\n};\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from\n * `lowerCamelCase` to `dash-case`.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n */\nexport const lowerCamelToDashKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])([A-Z])/g,\n replace: (_, firstLetter, secondLetter) => {\n const newSecondLetter = secondLetter.toLowerCase();\n return `${firstLetter}-${newSecondLetter}`;\n },\n });\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from\n * `lowerCamelCase` to `snake_case`.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n */\nexport const lowerCamelToSnakeKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])([A-Z])/g,\n replace: (_, firstLetter, secondLetter) => {\n const newSecondLetter = secondLetter.toLowerCase();\n return `${firstLetter}_${newSecondLetter}`;\n },\n });\n","import { copy } from './copy.js';\nimport { get } from './get.js';\n\nexport type RemoveOptions = {\n /**\n * The object from where the property will be removed.\n */\n target: unknown;\n /**\n * The path to the property.\n */\n path: string;\n /**\n * The delimiter that will separate the path components.\n */\n pathDelimiter?: string;\n /**\n * Whether or not to throw an error when the path is invalid. If this is `false`, the\n * function will silently fail.\n */\n failWithError?: boolean;\n /**\n * If this flag is `true` and after removing the property the parent object is empty,\n * it will remove it recursively until a non empty parent object is found.\n */\n cleanEmptyProperties?: boolean;\n};\n/**\n * Deletes a property of an object using a path.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n * @example\n *\n * const target = {\n * propOne: {\n * propOneSub: 'Charito!',\n * },\n * propTwo: '!!!',\n * };\n * console.log(remove({ target, path: 'propOne.propOneSub' }));\n * // Will output { propTwo: '!!!' }\n *\n */\nfunction remove<T = unknown>(options: RemoveOptions): T | undefined;\nfunction remove<T = unknown>(options: unknown, path: string): T | undefined;\nfunction remove<T = unknown>(\n options: RemoveOptions | unknown,\n path?: string,\n): T | undefined {\n let useOptions: RemoveOptions;\n if (typeof path === 'string') {\n useOptions = {\n target: options,\n path,\n };\n } else {\n useOptions = options as RemoveOptions;\n }\n\n const {\n target,\n path: usePath,\n pathDelimiter = '.',\n cleanEmptyProperties = true,\n failWithError = false,\n } = useOptions;\n\n const parts = usePath.split(pathDelimiter);\n const last = parts.pop()!;\n const result = copy(target) as Record<string, unknown>;\n if (!parts.length) {\n delete result[last];\n return result as T;\n }\n const parentPath = parts.join(pathDelimiter);\n const parentObj = get<Record<string, unknown>>({\n target: result,\n path: parentPath,\n pathDelimiter,\n failWithError,\n });\n\n if (typeof parentObj === 'undefined') {\n return undefined;\n }\n\n delete parentObj[last];\n if (cleanEmptyProperties && !Object.keys(parentObj).length) {\n return remove({\n target: result,\n path: parentPath,\n pathDelimiter,\n failWithError,\n cleanEmptyProperties,\n }) as T;\n }\n\n return result as T;\n}\n\nexport { remove };\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from `snake_case` to\n * `dash-case`.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n */\nexport const snakeToDashKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])_([a-z])/g,\n replace: (_, firstLetter, secondLetter) => `${firstLetter}-${secondLetter}`,\n });\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from `snake_case` to\n * `lowerCamelCase`.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n */\nexport const snakeToLowerCamelKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])_([a-z])/g,\n replace: (_, firstLetter, secondLetter) => {\n const newSecondLetter = secondLetter.toUpperCase();\n return `${firstLetter}${newSecondLetter}`;\n },\n });\n","import { set } from './set.js';\n\nexport type UnflatOptions = {\n /**\n * The object to transform.\n */\n target: unknown;\n /**\n * The delimiter that will separate the path components.\n */\n pathDelimiter?: string;\n};\n/**\n * This method does the exact opposite from `flat`: It takes an already flatten object and\n * restores it structure.\n *\n * @param options The options to use.\n * @template T The type of the returned object.\n * @example\n *\n * const target = {\n * 'propOne.propOneSub': 'Charito!',\n * propTwo: '!!!',\n * };\n * console.log(unflat({ target }));\n * // Will output { propOne: { propOneSub: 'Charito!' }, 'propTwo': '!!!' }\n *\n */\nexport const unflat = <T = Record<string, unknown>>(options: UnflatOptions): T => {\n const { target, pathDelimiter = '.' } = options;\n const useTarget = target as Record<string, unknown>;\n return Object.keys(useTarget).reduce<Record<string, unknown>>(\n (current, key) =>\n set({ target: current, path: key, value: useTarget[key], pathDelimiter })!,\n {},\n ) as T;\n};\n"],"mappings":"AAAA,OAAOA,MAAY,SAwBZ,IAAMC,EAAQ,IAAiBC,IAA0B,CAC9D,GAAM,CAACC,CAAW,EAAID,EAChBE,EAAO,MAAM,QAAQD,CAAW,EAAI,CAAC,EAAI,CAAC,EAChD,OAAOH,EAAO,GAAMI,EAAM,GAAGF,CAAO,CACtC,ECnBO,IAAMG,EAAWC,GAAiBC,EAAMD,CAAM,ECwD9C,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C,EAAgB,GAAI,EAAIF,EAClCG,EAAYF,EAClB,OAAO,OAAO,KAAKE,CAAS,EAAE,OAC5B,CAACC,EAASC,IACRC,EAAI,CAAE,OAAQF,EAAS,KAAMC,EAAK,MAAOF,EAAUE,CAAG,EAAG,cAAAH,CAAc,CAAC,EAC1E,CAAC,CACH,CACF","names":["extend","merge","targets","firstTarget","base","copy","target","merge","formatKeys","options","target","search","replace","include","exclude","pathDelimiter","useTarget","keys","hasChildrenByKey","key","value","escapedPathDelimiter","cleanPathStartExpression","cleanPathEndExpression","subIncludeByKey","keysToFormat","includePath","useIncludePath","pathParts","pathKey","subExcludeByKey","keysToRemove","excludePath","useExcludePath","newObj","newKey","newValue","dashToLowerCamelKeys","options","formatKeys","_","firstLetter","secondLetter","newSecondLetter","dashToSnakeKeys","options","formatKeys","_","firstLetter","secondLetter","get","options","path","useOptions","target","usePath","pathDelimiter","failWithError","useTarget","parts","first","currentElement","currentPath","currentPart","breakLoop","FORBIDDEN_PATHS","set","options","path","value","useOptions","target","usePath","useValue","pathDelimiter","failWithError","result","copy","parts","part","last","currentElement","currentPath","foundInvalid","elementType","errorPath","extract","options","target","paths","pathDelimiter","failWithError","copied","copy","result","failed","acc","objPath","destPath","originPath","firstKey","pathInfo","breakLoop","value","get","withCustomProp","set","flat","options","target","shouldFlatten","pathDelimiter","prefix","useTarget","result","namePrefix","key","name","value","isObject","merge","copy","lowerCamelToDashKeys","options","formatKeys","_","firstLetter","secondLetter","newSecondLetter","lowerCamelToSnakeKeys","options","formatKeys","_","firstLetter","secondLetter","newSecondLetter","remove","options","path","useOptions","target","usePath","pathDelimiter","cleanEmptyProperties","failWithError","parts","last","result","copy","parentPath","parentObj","get","snakeToDashKeys","options","formatKeys","_","firstLetter","secondLetter","snakeToLowerCamelKeys","options","formatKeys","_","firstLetter","secondLetter","newSecondLetter","unflat","options","target","pathDelimiter","useTarget","current","key","set"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/fns/merge.ts","../src/fns/copy.ts","../src/fns/formatKeys.ts","../src/fns/dashToLowerCamelKeys.ts","../src/fns/dashToSnakeKeys.ts","../src/fns/get.ts","../src/fns/set.ts","../src/fns/extract.ts","../src/fns/flat.ts","../src/fns/lowerCamelToDashKeys.ts","../src/fns/lowerCamelToSnakeKeys.ts","../src/fns/remove.ts","../src/fns/snakeToDashKeys.ts","../src/fns/snakeToLowerCamelKeys.ts","../src/fns/unflat.ts"],"sourcesContent":["import extend from 'extend';\n\n/**\n * This method makes a deep merge of a list of objects into a new one. The method also\n * supports arrays: if the first element is an array, it will be merged into an array,\n * otherwise, it will be an object.\n *\n * @example\n * const objA = { a: 'first' };\n * const objB = { b: 'second' };\n * console.log(merge(objA, objB));\n * // Will output { a: 'first', b: 'second' }\n *\n * @example\n * const arrA = [{ a: 'first' }];\n * const arrB = [{ b: 'second' }];\n * console.log(merge(objA, objB));\n * // Will output [{ a: 'first', b: 'second' }]\n *\n * @template T The type of the merged object that will be returned.\n * @param targets The list of objects to merge.\n */\nexport const merge = <T = unknown>(...targets: unknown[]): T => {\n const [firstTarget] = targets;\n const base = Array.isArray(firstTarget) ? [] : {};\n return extend(true, base, ...targets) as T;\n};\n","import { merge } from './merge.js';\n\n/**\n * Creates a deep copy of a given object.\n *\n * @template T The type of the input object, which will be the same as the one returned.\n * @param target The object to copy.\n */\nexport const copy = <T>(target: T): T => merge(target);\n","/**\n * The callback that will be used to replace a key.\n *\n * @param substring The captured string to replace.\n * @param args The list of groups captured by the expression.\n */\nexport type FormatKeysReplaceFn = (substring: string, ...args: string[]) => string;\n\nexport type FormatKeysOptions = {\n /** The object to transform. */\n target: unknown;\n /** A regular expression to match the keys to transform. */\n search: RegExp;\n /**\n * The callback that will be used to replace the matched substring. Think of `search`\n * and `replace` as the parameters of `String.replace`.\n */\n replace: FormatKeysReplaceFn;\n /**\n * A list of keys or paths where the transformation will be made. If not specified, the\n * function will use all the keys from the object.\n */\n include?: string[];\n /** A list of keys or paths where the transformation won't be made. */\n exclude?: string[];\n /**\n * The delimiter that will separate the path components for both `include` and\n * `exclude`.\n */\n pathDelimiter?: string;\n};\n\nexport type FormatKeysExtensionOptions = Omit<FormatKeysOptions, 'search' | 'replace'>;\n\n/**\n * Formats all the keys on an object using a way similar to `.replace(regexp, ...)` but\n * that also works recursively and with _\"object paths\"_.\n *\n * @example\n * const target = {\n * prop_one: 'Charito!',\n * };\n * console.log(\n * formatKeys({\n * target,\n * // Find all the keys with snake case.\n * search: /([a-z])_([a-z])/g,\n * // Using the same .replace style callback, replace it with lower camel case.\n * replace: (_, firstLetter, secondLetter) => {\n * const newSecondLetter = secondLetter.toUpperCase();\n * return `${firstLetter}${newSecondLetter}`;\n * },\n * }),\n * );\n * // Will output { propOne: 'Charito!}.\n *\n * @template T The type of the returned object.\n * @param options The set of options to customize the transformation.\n */\nexport const formatKeys = <T = Record<string, unknown>>(\n options: FormatKeysOptions,\n): T => {\n const {\n target,\n search,\n replace,\n include = [],\n exclude = [],\n pathDelimiter = '.',\n } = options;\n // Re-case target.\n const useTarget = target as Record<string, unknown>;\n // First of all, get all the keys from the target.\n const keys = Object.keys(target as Record<string, unknown>);\n /**\n * Then, check which keys are parent to other objects. This is saved on a dictionary not\n * only because it makes it easier to check if the method should make a recursive call\n * for a key, but also because when parsing the `exclude` parameter, if one of items is\n * a key (and not an specific path), the method won't make the recursive call.\n *\n * @ignore\n */\n const hasChildrenByKey: Record<string, unknown> = {};\n keys.forEach((key) => {\n const value = useTarget[key];\n hasChildrenByKey[key] = !!(\n value &&\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n Object.keys(value)\n );\n });\n /**\n * Escape the path delimiter and create two regular expression: One that removes the\n * path delimiter from the start of a path and one that removes it from the end. They\n * are later used to normalize paths in order to avoid \"incomplete paths\" (paths that\n * end or start with the delimiter).\n */\n const escapedPathDelimiter = pathDelimiter.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&');\n const cleanPathStartExpression = new RegExp(`^${escapedPathDelimiter}`, 'i');\n const cleanPathEndExpression = new RegExp(`${escapedPathDelimiter}$`, 'i');\n /**\n * This dictionary will be used to save the `include` parameter that will be sent for\n * specific keys on recursive calls. If `include` has a path like `myKey.mySubKey`,\n * `myKey` is not transformed, but `mySubKey` is saved on this dictionary (`{ myKey:\n * ['mySubKey']}`) and when the method applies the formatting to the object, if `myKey`\n * has an object, it will make a recursive all and send `['mySubKey]` as its `include`\n * parameter.\n */\n const subIncludeByKey: Record<string, string[]> = {};\n /**\n * This will be an array containing the final list of `keys` that should be tranformed.\n * To be clear, these keys will be from the top level, so, they won't be paths. Thd\n * following blocks will parse `include` and `exclude` in order to extract the real\n * keys, prepare the `include` and `exclude` for recursive calls, and save the actual\n * keys from the object \"at the current level of this call\" (no, it's not thinking about\n * the children :P).\n */\n let keysToFormat: string[];\n // If the `include` parameter has paths/keys...\n if (include.length) {\n keysToFormat = include\n .map((includePath) => {\n // Normalize the path/key.\n const useIncludePath = includePath\n .replace(cleanPathStartExpression, '')\n .replace(cleanPathEndExpression, '');\n // Define the variable that will, eventually, have the real key.\n let key;\n // If the value is a path...\n if (useIncludePath.includes(pathDelimiter)) {\n // Split all its components.\n const pathParts = useIncludePath.split(pathDelimiter);\n // Get the first component, a.k.a. the real key.\n const pathKey = pathParts.shift()!;\n /**\n * This is very important: Since the path was specified with sub components\n * (like `myProp.mySubProp`), the method won't format the key, but the sub\n * key(s) (`mySubProp`). The `key` is set to `''` so it will be later removed\n * using `.filter`.\n *\n * @ignore\n */\n key = '';\n /**\n * If there's no array for the key on the \"`include` dictionary for recursive\n * calls\", create an empty one.\n */\n if (!subIncludeByKey[pathKey]) {\n subIncludeByKey[pathKey] = [];\n }\n // Save the rest of the path to be sent on the recursive call as `include`.\n subIncludeByKey[pathKey]!.push(pathParts.join(pathDelimiter));\n } else {\n // If the value wasn't a path, assume it's a key, and set it to be returned.\n key = useIncludePath;\n }\n\n return key;\n })\n // Remove any _empty keys_.\n .filter((key) => key);\n } else {\n // There's nothing on the `include` parameter, so use all the keys.\n keysToFormat = keys;\n }\n /**\n * Similar to `subIncludeByKey`, this dictionary will be used to save the `exclude`\n * parameter that will be sent for specific keys on recursive calls. If `exclude` has a\n * path like `myKey.mySubKey`, `myKey` will be transformed, but `mySubKey` is saved on\n * this dictionary (`{ myKey: ['mySubKey']}`) and when the method applies the formatting\n * to the object, if `myKey` has an object, it will make a recursive all and send\n * `['mySubKey]` as its `exclude` parameter.\n */\n const subExcludeByKey: Record<string, string[]> = {};\n // If the `include` parameter has paths/keys...\n if (exclude.length) {\n /**\n * Create a dictionary of keys that should be removed from `keysToFormat`. It's easier\n * to have them on a list and use `.filter` than actually call `.splice` for every key\n * that should be removed.\n */\n const keysToRemove: string[] = [];\n exclude.forEach((excludePath) => {\n // Normalize the path/key.\n const useExcludePath = excludePath\n .replace(cleanPathStartExpression, '')\n .replace(cleanPathEndExpression, '');\n // If the value is a path...\n if (useExcludePath.includes(pathDelimiter)) {\n // Split all its components.\n const pathParts = useExcludePath.split(pathDelimiter);\n // Get the first component, a.k.a. the real key.\n const pathKey = pathParts.shift()!;\n /**\n * If there's no array for the key on the \"`exclude` dictionary for recursive\n * calls\", create an empty one.\n */\n if (!subExcludeByKey[pathKey]) {\n subExcludeByKey[pathKey] = [];\n }\n // Save the rest of the path to be sent on the recursive call as `exclude`.\n subExcludeByKey[pathKey]!.push(pathParts.join(pathDelimiter));\n } else {\n /**\n * If the value wasn't a path, assume it's a key, turn the flag on the \"children\n * dictionary\" to `false`, to prevent recursive calls, and add the key to the list\n * of keys that will be removed from `keysToFormat`. Basically: If it's a key,\n * don't format it and don't make recursive calls for it.\n *\n * @ignore\n */\n hasChildrenByKey[useExcludePath] = false;\n keysToRemove.push(useExcludePath);\n }\n });\n // Remove keys that should be excluded.\n keysToFormat = keysToFormat.filter((key) => key && !keysToRemove.includes(key));\n }\n // \"Finally\", reduce all the keys from the object and create the new one...\n return keys.reduce<Record<string, unknown>>((newObj, key) => {\n /**\n * Define the new key and value for the object property. Depending on the validations,\n * they may be replaced with formatted ones.\n */\n let newKey;\n let newValue;\n /**\n * Get the current value for the key, in case it's needed for a recursive call or just\n * to send it back because it didn't need any change.\n */\n const value = useTarget[key];\n // If the key should be formatted, apply the formatting; otherwise, keep the original.\n if (keysToFormat.includes(key)) {\n newKey = key.replace(search, replace);\n } else {\n newKey = key;\n }\n /**\n * If the paths/keys on `exclude` didn't modify the \"children dictionary\" for the key\n * and the value is another object, make a recursive call; otherwise, just use the\n * original value.\n */\n if (hasChildrenByKey[key]) {\n newValue = formatKeys({\n target: value,\n search,\n replace,\n include: subIncludeByKey[key] || [],\n exclude: subExcludeByKey[key] || [],\n pathDelimiter,\n });\n } else {\n newValue = value;\n }\n // \"Done\", return the new object with the \"new key\" and the \"new value\".\n return { ...newObj, [newKey]: newValue };\n }, {}) as T;\n};\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from `dash-case` to\n * `lowerCamelCase`.\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nexport const dashToLowerCamelKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])-([a-z])/g,\n replace: (_, firstLetter, secondLetter) => {\n const newSecondLetter = secondLetter.toUpperCase();\n return `${firstLetter}${newSecondLetter}`;\n },\n });\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from `dash-case` to\n * `snake_case`.\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nexport const dashToSnakeKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])-([a-z])/g,\n replace: (_, firstLetter, secondLetter) => `${firstLetter}_${secondLetter}`,\n });\n","export type GetOptions = {\n /** The object from where the property will be read. */\n target: unknown;\n /** The path to the property. */\n path: string;\n /** The delimiter that will separate the path components. */\n pathDelimiter?: string;\n /**\n * Whether or not to throw an error when the path is invalid. If this is `false`, the\n * method will silently fail and return `undefined`.\n */\n failWithError?: boolean;\n};\n\n/**\n * Returns the value of an object property using a path.\n *\n * @example\n * const obj = {\n * propOne: {\n * propOneSub: 'Charito!',\n * },\n * propTwo: '!!!',\n * };\n * console.log(get({ target: obj, path: 'propOne.propOneSub' }));\n * // Will output 'Charito!'\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n * @throws {Error} If the path is invalid and `failWithError` is set to `true`.\n */\nfunction get<T>(options: GetOptions): T | undefined;\nfunction get<T>(options: unknown, path: string): T | undefined;\nfunction get<T>(options: GetOptions | unknown, path?: string): T | undefined {\n let useOptions: GetOptions;\n if (typeof path === 'string') {\n useOptions = {\n target: options,\n path,\n };\n } else {\n useOptions = options as GetOptions;\n }\n\n const {\n target,\n path: usePath,\n pathDelimiter = '.',\n failWithError = false,\n } = useOptions;\n const useTarget = target as Record<string, unknown>;\n const parts = usePath.split(pathDelimiter);\n const first = parts.shift()!;\n let currentElement = useTarget[first] as Record<string, unknown>;\n if (typeof currentElement === 'undefined') {\n if (failWithError) {\n throw new Error(`There's nothing on '${usePath}'`);\n }\n\n return undefined;\n }\n\n if (!parts.length) {\n return currentElement as T;\n }\n\n let currentPath = first;\n parts.some((currentPart) => {\n let breakLoop = false;\n currentPath += `${pathDelimiter}${currentPart}`;\n currentElement = currentElement[currentPart] as Record<string, unknown>;\n if (typeof currentElement === 'undefined') {\n if (failWithError) {\n throw new Error(`There's nothing on '${currentPath}'`);\n } else {\n breakLoop = true;\n }\n }\n\n return breakLoop;\n });\n\n return currentElement as T;\n}\n\nexport { get };\n","import { copy } from './copy.js';\n\n/**\n * List of paths that are forbidden to use on the `set` function, as they could lead to\n * security issues.\n *\n * @access protected\n */\nconst FORBIDDEN_PATHS = ['__proto__', 'prototype', 'constructor'];\n\nexport type SetOptions = {\n /** The object where the property will be set. */\n target: unknown;\n /** The path for the property. */\n path: string;\n /** The value to set on the property. */\n value: unknown;\n /** The delimiter that will separate the path components. */\n pathDelimiter?: string;\n /**\n * Whether or not to throw an error when the path is invalid. If this is `false`, the\n * method will silently fail and return `undefined`.\n */\n failWithError?: boolean;\n};\n/**\n * Sets a property on an object using a path. If the path doesn't exist, it will be\n * created.\n *\n * @example\n * const target = {};\n * console.log(set({ target, path: 'some.prop.path', value: 'some-value' }));\n * // Will output { some: { prop: { path: 'some-value' } } }\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n * @throws {Error} If one of the path components is for a non-object property and\n * `failWithError` is set to `true`.\n */\nfunction set<T = Record<string, unknown>>(options: SetOptions): T | undefined;\nfunction set<T = Record<string, unknown>>(\n options: SetOptions | unknown,\n path: string,\n value: unknown,\n): T | undefined;\nfunction set<T = Record<string, unknown>>(\n options: SetOptions | unknown,\n path?: string,\n value?: unknown,\n): T | undefined {\n let useOptions: SetOptions;\n if (typeof path === 'string') {\n useOptions = {\n target: options,\n path,\n value,\n };\n } else {\n useOptions = options as SetOptions;\n }\n\n const {\n target,\n path: usePath,\n value: useValue,\n pathDelimiter = '.',\n failWithError = false,\n } = useOptions;\n const result = copy(target) as Record<string, unknown>;\n if (!usePath.includes(pathDelimiter)) {\n if (!usePath || FORBIDDEN_PATHS.includes(usePath.toLowerCase())) {\n return undefined;\n }\n\n result[usePath] = useValue;\n return result as T;\n }\n\n const parts = usePath.split(pathDelimiter);\n const isInvalid = parts.some(\n (part) => !part || FORBIDDEN_PATHS.includes(part.toLowerCase()),\n );\n\n if (isInvalid) {\n return undefined;\n }\n\n // Path validation ensures that every component is defined and non-empty.\n const last = parts.pop()!;\n let currentElement = result;\n let currentPath = '';\n let foundInvalid = false;\n parts.forEach((part) => {\n currentPath += `${pathDelimiter}${part}`;\n const element = currentElement[part];\n const elementType = typeof element;\n if (elementType === 'undefined') {\n currentElement[part] = {};\n currentElement = currentElement[part] as Record<string, unknown>;\n } else if (elementType === 'object') {\n currentElement = currentElement[part] as Record<string, unknown>;\n } else {\n const errorPath = currentPath.substring(pathDelimiter.length);\n if (failWithError) {\n throw new Error(\n `There's already an element of type '${elementType}' on '${errorPath}'`,\n );\n } else {\n foundInvalid = true;\n }\n }\n });\n\n if (foundInvalid) return undefined;\n\n currentElement[last] = useValue;\n\n return result as T | undefined;\n}\n\nexport { set };\n","import { copy } from './copy.js';\nimport { get } from './get.js';\nimport { set } from './set.js';\n/**\n * Used in the {@link extract} function to specify a path for a property, or an \"origin\n * path\" and an \"extraction path\".\n */\nexport type extractionPath = string | Record<string, string>;\n\nexport type ExtractOptions = {\n /** The object from where the property/properties will be extracted. */\n target: unknown;\n /**\n * This can be a single path or a list of them. And for this method, the paths are not\n * only strings but can also be an object with a single key, that would be the path to\n * where to \"do the extraction\", and the value the path on the target object.\n */\n paths: extractionPath | extractionPath[];\n /** The delimiter that will separate the path components. */\n pathDelimiter?: string;\n /**\n * Whether or not to throw an error when the path is invalid. If this is `false`, the\n * method will silently fail an empty object.\n */\n failWithError?: boolean;\n};\n/**\n * Extracts a property or properties from an object in order to create a new one.\n *\n * @example\n * const target = {\n * name: {\n * first: 'Pilar',\n * },\n * age: 3,\n * address: {\n * planet: 'earth',\n * something: 'else',\n * },\n * };\n * console.log(\n * extract({\n * target: obj,\n * paths: [{ name: 'name.first' }, 'age', 'address.planet'],\n * }),\n * );\n * // Will output { name: 'Pilar', age: 3, address: { planet: 'earth' } }\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nexport const extract = <T = Record<string, unknown>>(\n options: ExtractOptions,\n): T | undefined => {\n const { target, paths, pathDelimiter = '.', failWithError = false } = options;\n const copied = copy(target) as Record<string, unknown>;\n let result: Record<string, unknown> = {};\n let failed = false;\n (Array.isArray(paths) ? paths : [paths])\n .reduce<Array<{ origin: string; customDest: boolean; dest: string }>>(\n (acc, objPath) => {\n let destPath: string;\n let originPath: string;\n if (typeof objPath === 'string') {\n destPath = objPath;\n originPath = objPath;\n } else {\n const [firstKey] = Object.keys(objPath);\n destPath = firstKey!;\n originPath = objPath[destPath]!;\n }\n\n acc.push({\n origin: originPath,\n customDest: destPath.includes(pathDelimiter),\n dest: destPath,\n });\n return acc;\n },\n [],\n )\n .some((pathInfo) => {\n let breakLoop = false;\n const value = get({\n target: copied,\n path: pathInfo.origin,\n pathDelimiter,\n failWithError,\n });\n if (typeof value !== 'undefined') {\n if (pathInfo.customDest) {\n const withCustomProp = set({\n target: result,\n path: pathInfo.dest,\n value,\n pathDelimiter,\n failWithError,\n });\n if (typeof withCustomProp === 'undefined') {\n breakLoop = true;\n failed = true;\n } else {\n result = withCustomProp;\n }\n } else {\n result[pathInfo.dest] = value;\n }\n }\n\n return breakLoop;\n });\n\n if (failed) return undefined;\n return result as T;\n};\n","import { copy } from './copy.js';\nimport { merge } from './merge.js';\n\n/**\n * Checks whether a key for an array or an Object should be flattened.\n *\n * @param key The key to check inside its parent.\n * @param value The value of the key.\n */\nexport type ShouldFlattenFn = (key: string, value: unknown) => boolean;\n\nexport type FlatOptions = {\n /** The object to transform. */\n target: unknown;\n /**\n * A custom prefix to be added before the name of the properties. This can be used on\n * custom cases and it's also used when the method calls itself in order to flatten a\n * sub object.\n */\n prefix?: string;\n /** The delimiter that will separate the path components. */\n pathDelimiter?: string;\n /**\n * A custom function that can be used in order to tell the function whether an Object or\n * an Array property should be flatten or not.\n */\n shouldFlatten?: ShouldFlattenFn;\n};\n/**\n * Flattens an object properties into a single level dictionary.\n *\n * @example\n * const target = {\n * propOne: {\n * propOneSub: 'Charito!',\n * },\n * propTwo: '!!!',\n * };\n * console.log(flat({ target });\n * // Will output { 'propOne.propOneSub': 'Charito!', propTwo: '!!!' }\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nexport const flat = <T = Record<string, unknown>>(options: FlatOptions): T => {\n const { target, shouldFlatten, pathDelimiter = '.', prefix = '' } = options;\n const useTarget = target as Record<string, unknown>;\n let result: Record<string, unknown> = {};\n const namePrefix = prefix ? `${prefix}${pathDelimiter}` : '';\n Object.keys(useTarget).forEach((key) => {\n const name = `${namePrefix}${key}`;\n const value = useTarget[key] as unknown;\n const valueType = typeof value;\n const isObject = valueType === 'object' && value !== null;\n if (isObject && (!shouldFlatten || shouldFlatten(key, value))) {\n result = merge(\n result,\n flat({ target: value, pathDelimiter, prefix: name, shouldFlatten }),\n );\n } else {\n result[name] = isObject ? copy(value) : value;\n }\n });\n\n return result as T;\n};\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from `lowerCamelCase`\n * to `dash-case`.\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nexport const lowerCamelToDashKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])([A-Z])/g,\n replace: (_, firstLetter, secondLetter) => {\n const newSecondLetter = secondLetter.toLowerCase();\n return `${firstLetter}-${newSecondLetter}`;\n },\n });\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from\n * `lowerCamelCase` to `snake_case`.\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nexport const lowerCamelToSnakeKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])([A-Z])/g,\n replace: (_, firstLetter, secondLetter) => {\n const newSecondLetter = secondLetter.toLowerCase();\n return `${firstLetter}_${newSecondLetter}`;\n },\n });\n","import { copy } from './copy.js';\nimport { get } from './get.js';\n\nexport type RemoveOptions = {\n /** The object from where the property will be removed. */\n target: unknown;\n /** The path to the property. */\n path: string;\n /** The delimiter that will separate the path components. */\n pathDelimiter?: string;\n /**\n * Whether or not to throw an error when the path is invalid. If this is `false`, the\n * function will silently fail.\n */\n failWithError?: boolean;\n /**\n * If this flag is `true` and after removing the property the parent object is empty, it\n * will remove it recursively until a non empty parent object is found.\n */\n cleanEmptyProperties?: boolean;\n};\n/**\n * Deletes a property of an object using a path.\n *\n * @example\n * const target = {\n * propOne: {\n * propOneSub: 'Charito!',\n * },\n * propTwo: '!!!',\n * };\n * console.log(remove({ target, path: 'propOne.propOneSub' }));\n * // Will output { propTwo: '!!!' }\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nfunction remove<T = unknown>(options: RemoveOptions): T | undefined;\nfunction remove<T = unknown>(options: unknown, path: string): T | undefined;\nfunction remove<T = unknown>(\n options: RemoveOptions | unknown,\n path?: string,\n): T | undefined {\n let useOptions: RemoveOptions;\n if (typeof path === 'string') {\n useOptions = {\n target: options,\n path,\n };\n } else {\n useOptions = options as RemoveOptions;\n }\n\n const {\n target,\n path: usePath,\n pathDelimiter = '.',\n cleanEmptyProperties = true,\n failWithError = false,\n } = useOptions;\n\n const parts = usePath.split(pathDelimiter);\n const last = parts.pop()!;\n const result = copy(target) as Record<string, unknown>;\n if (!parts.length) {\n delete result[last];\n return result as T;\n }\n const parentPath = parts.join(pathDelimiter);\n const parentObj = get<Record<string, unknown>>({\n target: result,\n path: parentPath,\n pathDelimiter,\n failWithError,\n });\n\n if (typeof parentObj === 'undefined') {\n return undefined;\n }\n\n delete parentObj[last];\n if (cleanEmptyProperties && !Object.keys(parentObj).length) {\n return remove({\n target: result,\n path: parentPath,\n pathDelimiter,\n failWithError,\n cleanEmptyProperties,\n }) as T;\n }\n\n return result as T;\n}\n\nexport { remove };\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from `snake_case` to\n * `dash-case`.\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nexport const snakeToDashKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])_([a-z])/g,\n replace: (_, firstLetter, secondLetter) => `${firstLetter}-${secondLetter}`,\n });\n","import { formatKeys, type FormatKeysExtensionOptions } from './formatKeys.js';\n\n/**\n * A shorthand method for {@link formatKeys} that transforms the keys from `snake_case` to\n * `lowerCamelCase`.\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nexport const snakeToLowerCamelKeys = <T>(options: FormatKeysExtensionOptions): T =>\n formatKeys<T>({\n ...options,\n search: /([a-z])_([a-z])/g,\n replace: (_, firstLetter, secondLetter) => {\n const newSecondLetter = secondLetter.toUpperCase();\n return `${firstLetter}${newSecondLetter}`;\n },\n });\n","import { set } from './set.js';\n\nexport type UnflatOptions = {\n /** The object to transform. */\n target: unknown;\n /** The delimiter that will separate the path components. */\n pathDelimiter?: string;\n};\n/**\n * This method does the exact opposite from `flat`: It takes an already flatten object and\n * restores it structure.\n *\n * @example\n * const target = {\n * 'propOne.propOneSub': 'Charito!',\n * propTwo: '!!!',\n * };\n * console.log(unflat({ target }));\n * // Will output { propOne: { propOneSub: 'Charito!' }, 'propTwo': '!!!' }\n *\n * @template T The type of the returned object.\n * @param options The options to use.\n */\nexport const unflat = <T = Record<string, unknown>>(options: UnflatOptions): T => {\n const { target, pathDelimiter = '.' } = options;\n const useTarget = target as Record<string, unknown>;\n return Object.keys(useTarget).reduce<Record<string, unknown>>(\n (current, key) =>\n set({ target: current, path: key, value: useTarget[key], pathDelimiter })!,\n {},\n ) as T;\n};\n"],"mappings":"sBAsBA,MAAa,GAAsB,GAAG,IAA0B,CAC9D,GAAM,CAAC,GAAe,EAEtB,OAAO,EAAO,GADD,MAAM,QAAQ,CAAW,EAAI,CAAC,EAAI,CAAC,EACtB,GAAG,CAAO,CACtC,EClBa,EAAW,GAAiB,EAAM,CAAM,ECmDxC,EACX,GACM,CACN,GAAM,CACJ,SACA,SACA,UACA,UAAU,CAAC,EACX,UAAU,CAAC,EACX,gBAAgB,KACd,EAEE,EAAY,EAEZ,EAAO,OAAO,KAAK,CAAiC,EASpD,EAA4C,CAAC,EACnD,EAAK,QAAS,GAAQ,CACpB,IAAM,EAAQ,EAAU,GACxB,EAAiB,GAAO,CAAC,EACvB,GACA,OAAO,GAAU,UACjB,GACA,CAAC,MAAM,QAAQ,CAAK,GACpB,OAAO,KAAK,CAAK,EAErB,CAAC,EAOD,IAAM,EAAuB,EAA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ACA,KAAM,EACN,gBAAgB,IAChB,uBAAuB,GACvB,gBAAgB,IACd,EAEE,EAAQ,EAAQ,MAAM,CAAa,EACnC,EAAO,EAAM,IAAI,EACjB,EAAS,EAAK,CAAM,EAC1B,GAAI,CAAC,EAAM,OAET,OADA,OAAO,EAAO,GACP,EAET,IAAM,EAAa,EAAM,KAAK,CAAa,EACrC,EAAY,EAA6B,CAC7C,OAAQ,EACR,KAAM,EACN,gBACA,eACF,CAAC,EAEG,GAAO,IAAc,OAezB,OAXA,OAAO,EAAU,GACb,GAAwB,CAAC,OAAO,KAAK,CAAS,CAAC,CAAC,OAC3C,EAAO,CACZ,OAAQ,EACR,KAAM,EACN,gBACA,gBACA,sBACF,CAAC,EAGI,CACT,CCnFA,MAAa,EAAsB,GACjC,EAAc,CACZ,GAAG,EACH,OAAQ,mBACR,SAAU,EAAG,EAAa,IAAiB,GAAG,EAAY,GAAG,GAC/D,CAAC,ECLU,EAA4B,GACvC,EAAc,CACZ,GAAG,EACH,OAAQ,mBACR,SAAU,EAAG,EAAa,IAEjB,GAAG,IADc,EAAa,YACC,GAE1C,CAAC,ECMU,EAAuC,GAA8B,CAChF,GAAM,CAAE,SAAQ,gBAAgB,KAAQ,EAClC,EAAY,EAClB,OAAO,OAAO,KAAK,CAAS,CAAC,CAAC,QAC3B,EAAS,IACR,EAAI,CAAE,OAAQ,EAAS,KAAM,EAAK,MAAO,EAAU,GAAM,eAAc,CAAC,EAC1E,CAAC,CACH,CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homer0/object-utils",
|
|
3
3
|
"description": "A small collection of utility methods to work with objects.",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.5",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/homer0/packages.git",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"extend": "^3.0.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@homer0/oxlint-config": "0.3
|
|
41
|
-
"@homer0/tsconfig": "5.0.
|
|
40
|
+
"@homer0/oxlint-config": "1.0.3",
|
|
41
|
+
"@homer0/tsconfig": "5.0.1",
|
|
42
42
|
"@types/extend": "^3.0.4",
|
|
43
43
|
"@vitest/coverage-v8": "catalog:",
|
|
44
44
|
"oxlint": "catalog:",
|
|
45
|
-
"
|
|
45
|
+
"tsdown": "catalog:",
|
|
46
46
|
"typescript": "catalog:",
|
|
47
47
|
"unplugin-swc": "catalog:",
|
|
48
48
|
"vitest": "catalog:"
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"lint:file": "oxlint $@",
|
|
57
57
|
"test": "vitest run $@",
|
|
58
58
|
"types:check": "tsc --noEmit && tsc --noEmit --project ./tests/tsconfig.json",
|
|
59
|
-
"build": "
|
|
59
|
+
"build": "tsdown",
|
|
60
60
|
"prepublishOnly": "pnpm run build"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "27e773cc888ac2ffe26fabd5976a45ea7fdfaae8"
|
|
63
63
|
}
|