@homer0/object-utils 6.0.7 → 7.0.1
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 +24 -54
- 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,21 +1,18 @@
|
|
|
1
|
-
//#region src/fns/copy.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Creates a deep copy of a given object.
|
|
4
3
|
*
|
|
5
4
|
* @template T The type of the input object, which will be the same as the one returned.
|
|
6
5
|
* @param target The object to copy.
|
|
7
6
|
*/
|
|
8
|
-
declare const copy: <T>(target: T) => T;
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/fns/formatKeys.d.ts
|
|
7
|
+
export declare const copy: <T>(target: T) => T;
|
|
11
8
|
/**
|
|
12
9
|
* The callback that will be used to replace a key.
|
|
13
10
|
*
|
|
14
11
|
* @param substring The captured string to replace.
|
|
15
12
|
* @param args The list of groups captured by the expression.
|
|
16
13
|
*/
|
|
17
|
-
type FormatKeysReplaceFn = (substring: string, ...args: string[]) => string;
|
|
18
|
-
type FormatKeysOptions = {
|
|
14
|
+
export type FormatKeysReplaceFn = (substring: string, ...args: string[]) => string;
|
|
15
|
+
export type FormatKeysOptions = {
|
|
19
16
|
/** The object to transform. */
|
|
20
17
|
target: unknown;
|
|
21
18
|
/** A regular expression to match the keys to transform. */
|
|
@@ -38,7 +35,7 @@ type FormatKeysOptions = {
|
|
|
38
35
|
*/
|
|
39
36
|
pathDelimiter?: string;
|
|
40
37
|
};
|
|
41
|
-
type FormatKeysExtensionOptions = Omit<FormatKeysOptions, 'search' | 'replace'>;
|
|
38
|
+
export type FormatKeysExtensionOptions = Omit<FormatKeysOptions, 'search' | 'replace'>;
|
|
42
39
|
/**
|
|
43
40
|
* Formats all the keys on an object using a way similar to `.replace(regexp, ...)` but
|
|
44
41
|
* that also works recursively and with _"object paths"_.
|
|
@@ -64,9 +61,7 @@ type FormatKeysExtensionOptions = Omit<FormatKeysOptions, 'search' | 'replace'>;
|
|
|
64
61
|
* @template T The type of the returned object.
|
|
65
62
|
* @param options The set of options to customize the transformation.
|
|
66
63
|
*/
|
|
67
|
-
declare const formatKeys: <T = Record<string, unknown>>(options: FormatKeysOptions) => T;
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region src/fns/dashToLowerCamelKeys.d.ts
|
|
64
|
+
export declare const formatKeys: <T = Record<string, unknown>>(options: FormatKeysOptions) => T;
|
|
70
65
|
/**
|
|
71
66
|
* A shorthand method for {@link formatKeys} that transforms the keys from `dash-case` to
|
|
72
67
|
* `lowerCamelCase`.
|
|
@@ -74,9 +69,7 @@ declare const formatKeys: <T = Record<string, unknown>>(options: FormatKeysOptio
|
|
|
74
69
|
* @template T The type of the returned object.
|
|
75
70
|
* @param options The options to use.
|
|
76
71
|
*/
|
|
77
|
-
declare const dashToLowerCamelKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/fns/dashToSnakeKeys.d.ts
|
|
72
|
+
export declare const dashToLowerCamelKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
80
73
|
/**
|
|
81
74
|
* A shorthand method for {@link formatKeys} that transforms the keys from `dash-case` to
|
|
82
75
|
* `snake_case`.
|
|
@@ -84,15 +77,13 @@ declare const dashToLowerCamelKeys: <T>(options: FormatKeysExtensionOptions) =>
|
|
|
84
77
|
* @template T The type of the returned object.
|
|
85
78
|
* @param options The options to use.
|
|
86
79
|
*/
|
|
87
|
-
declare const dashToSnakeKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/fns/extract.d.ts
|
|
80
|
+
export declare const dashToSnakeKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
90
81
|
/**
|
|
91
82
|
* Used in the {@link extract} function to specify a path for a property, or an "origin
|
|
92
83
|
* path" and an "extraction path".
|
|
93
84
|
*/
|
|
94
|
-
type extractionPath = string | Record<string, string>;
|
|
95
|
-
type ExtractOptions = {
|
|
85
|
+
export type extractionPath = string | Record<string, string>;
|
|
86
|
+
export type ExtractOptions = {
|
|
96
87
|
/** The object from where the property/properties will be extracted. */
|
|
97
88
|
target: unknown;
|
|
98
89
|
/**
|
|
@@ -134,17 +125,15 @@ type ExtractOptions = {
|
|
|
134
125
|
* @template T The type of the returned object.
|
|
135
126
|
* @param options The options to use.
|
|
136
127
|
*/
|
|
137
|
-
declare const extract: <T = Record<string, unknown>>(options: ExtractOptions) => T | undefined;
|
|
138
|
-
//#endregion
|
|
139
|
-
//#region src/fns/flat.d.ts
|
|
128
|
+
export declare const extract: <T = Record<string, unknown>>(options: ExtractOptions) => T | undefined;
|
|
140
129
|
/**
|
|
141
130
|
* Checks whether a key for an array or an Object should be flattened.
|
|
142
131
|
*
|
|
143
132
|
* @param key The key to check inside its parent.
|
|
144
133
|
* @param value The value of the key.
|
|
145
134
|
*/
|
|
146
|
-
type ShouldFlattenFn = (key: string, value: unknown) => boolean;
|
|
147
|
-
type FlatOptions = {
|
|
135
|
+
export type ShouldFlattenFn = (key: string, value: unknown) => boolean;
|
|
136
|
+
export type FlatOptions = {
|
|
148
137
|
/** The object to transform. */
|
|
149
138
|
target: unknown;
|
|
150
139
|
/**
|
|
@@ -177,10 +166,8 @@ type FlatOptions = {
|
|
|
177
166
|
* @template T The type of the returned object.
|
|
178
167
|
* @param options The options to use.
|
|
179
168
|
*/
|
|
180
|
-
declare const flat: <T = Record<string, unknown>>(options: FlatOptions) => T;
|
|
181
|
-
|
|
182
|
-
//#region src/fns/get.d.ts
|
|
183
|
-
type GetOptions = {
|
|
169
|
+
export declare const flat: <T = Record<string, unknown>>(options: FlatOptions) => T;
|
|
170
|
+
export type GetOptions = {
|
|
184
171
|
/** The object from where the property will be read. */
|
|
185
172
|
target: unknown;
|
|
186
173
|
/** The path to the property. */
|
|
@@ -212,8 +199,6 @@ type GetOptions = {
|
|
|
212
199
|
*/
|
|
213
200
|
declare function get<T>(options: GetOptions): T | undefined;
|
|
214
201
|
declare function get<T>(options: unknown, path: string): T | undefined;
|
|
215
|
-
//#endregion
|
|
216
|
-
//#region src/fns/lowerCamelToDashKeys.d.ts
|
|
217
202
|
/**
|
|
218
203
|
* A shorthand method for {@link formatKeys} that transforms the keys from `lowerCamelCase`
|
|
219
204
|
* to `dash-case`.
|
|
@@ -221,9 +206,7 @@ declare function get<T>(options: unknown, path: string): T | undefined;
|
|
|
221
206
|
* @template T The type of the returned object.
|
|
222
207
|
* @param options The options to use.
|
|
223
208
|
*/
|
|
224
|
-
declare const lowerCamelToDashKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
225
|
-
//#endregion
|
|
226
|
-
//#region src/fns/lowerCamelToSnakeKeys.d.ts
|
|
209
|
+
export declare const lowerCamelToDashKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
227
210
|
/**
|
|
228
211
|
* A shorthand method for {@link formatKeys} that transforms the keys from
|
|
229
212
|
* `lowerCamelCase` to `snake_case`.
|
|
@@ -231,9 +214,7 @@ declare const lowerCamelToDashKeys: <T>(options: FormatKeysExtensionOptions) =>
|
|
|
231
214
|
* @template T The type of the returned object.
|
|
232
215
|
* @param options The options to use.
|
|
233
216
|
*/
|
|
234
|
-
declare const lowerCamelToSnakeKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/fns/merge.d.ts
|
|
217
|
+
export declare const lowerCamelToSnakeKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
237
218
|
/**
|
|
238
219
|
* This method makes a deep merge of a list of objects into a new one. The method also
|
|
239
220
|
* supports arrays: if the first element is an array, it will be merged into an array,
|
|
@@ -254,10 +235,8 @@ declare const lowerCamelToSnakeKeys: <T>(options: FormatKeysExtensionOptions) =>
|
|
|
254
235
|
* @template T The type of the merged object that will be returned.
|
|
255
236
|
* @param targets The list of objects to merge.
|
|
256
237
|
*/
|
|
257
|
-
declare const merge: <T = unknown>(...targets: unknown[]) => T;
|
|
258
|
-
|
|
259
|
-
//#region src/fns/remove.d.ts
|
|
260
|
-
type RemoveOptions = {
|
|
238
|
+
export declare const merge: <T = unknown>(...targets: unknown[]) => T;
|
|
239
|
+
export type RemoveOptions = {
|
|
261
240
|
/** The object from where the property will be removed. */
|
|
262
241
|
target: unknown;
|
|
263
242
|
/** The path to the property. */
|
|
@@ -293,9 +272,7 @@ type RemoveOptions = {
|
|
|
293
272
|
*/
|
|
294
273
|
declare function remove<T = unknown>(options: RemoveOptions): T | undefined;
|
|
295
274
|
declare function remove<T = unknown>(options: unknown, path: string): T | undefined;
|
|
296
|
-
|
|
297
|
-
//#region src/fns/set.d.ts
|
|
298
|
-
type SetOptions = {
|
|
275
|
+
export type SetOptions = {
|
|
299
276
|
/** The object where the property will be set. */
|
|
300
277
|
target: unknown;
|
|
301
278
|
/** The path for the property. */
|
|
@@ -326,8 +303,6 @@ type SetOptions = {
|
|
|
326
303
|
*/
|
|
327
304
|
declare function set<T = Record<string, unknown>>(options: SetOptions): T | undefined;
|
|
328
305
|
declare function set<T = Record<string, unknown>>(options: SetOptions | unknown, path: string, value: unknown): T | undefined;
|
|
329
|
-
//#endregion
|
|
330
|
-
//#region src/fns/snakeToDashKeys.d.ts
|
|
331
306
|
/**
|
|
332
307
|
* A shorthand method for {@link formatKeys} that transforms the keys from `snake_case` to
|
|
333
308
|
* `dash-case`.
|
|
@@ -335,9 +310,7 @@ declare function set<T = Record<string, unknown>>(options: SetOptions | unknown,
|
|
|
335
310
|
* @template T The type of the returned object.
|
|
336
311
|
* @param options The options to use.
|
|
337
312
|
*/
|
|
338
|
-
declare const snakeToDashKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
339
|
-
//#endregion
|
|
340
|
-
//#region src/fns/snakeToLowerCamelKeys.d.ts
|
|
313
|
+
export declare const snakeToDashKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
341
314
|
/**
|
|
342
315
|
* A shorthand method for {@link formatKeys} that transforms the keys from `snake_case` to
|
|
343
316
|
* `lowerCamelCase`.
|
|
@@ -345,10 +318,8 @@ declare const snakeToDashKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
|
345
318
|
* @template T The type of the returned object.
|
|
346
319
|
* @param options The options to use.
|
|
347
320
|
*/
|
|
348
|
-
declare const snakeToLowerCamelKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
349
|
-
|
|
350
|
-
//#region src/fns/unflat.d.ts
|
|
351
|
-
type UnflatOptions = {
|
|
321
|
+
export declare const snakeToLowerCamelKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
322
|
+
export type UnflatOptions = {
|
|
352
323
|
/** The object to transform. */
|
|
353
324
|
target: unknown;
|
|
354
325
|
/** The delimiter that will separate the path components. */
|
|
@@ -369,7 +340,6 @@ type UnflatOptions = {
|
|
|
369
340
|
* @template T The type of the returned object.
|
|
370
341
|
* @param options The options to use.
|
|
371
342
|
*/
|
|
372
|
-
declare const unflat: <T = Record<string, unknown>>(options: UnflatOptions) => T;
|
|
373
|
-
|
|
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 };
|
|
343
|
+
export declare const unflat: <T = Record<string, unknown>>(options: UnflatOptions) => T;
|
|
344
|
+
export { get, remove, set };
|
|
375
345
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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
|
|
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,"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,EA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,CACJ,SACA,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"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["extend","merge","targets","firstTarget","copy","target","formatKeys","options","useTarget","keys","hasChildrenByKey","value","key","escapedPathDelimiter","pathDelimiter","cleanPathStartExpression","cleanPathEndExpression","subIncludeByKey","keysToFormat","include","useIncludePath","includePath","pathParts","pathKey","subExcludeByKey","exclude","keysToRemove","useExcludePath","excludePath","newKey","newValue","search","replace","newObj","dashToLowerCamelKeys","firstLetter","secondLetter","dashToSnakeKeys","get","useOptions","path","usePath","parts","first","currentElement","failWithError","currentPath","breakLoop","currentPart","FORBIDDEN_PATHS","set","useValue","result","part","last","foundInvalid","elementType","errorPath","extract","copied","failed","paths","destPath","originPath","objPath","firstKey","acc","pathInfo","withCustomProp","flat","namePrefix","prefix","name","isObject","shouldFlatten","lowerCamelToDashKeys","lowerCamelToSnakeKeys","remove","parentPath","parentObj","cleanEmptyProperties","snakeToDashKeys","snakeToLowerCamelKeys","unflat","current"],"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":"A,sBAsBA,MAAaC,GAAsB,GAAGC,IAA0B,CAC9D,GAAM,CAACC,GAAeD,EAEtB,OAAOF,EAAO,GADD,MAAM,QAAQG,CAAW,EAAI,CAAC,EAAI,CAAC,EACtB,GAAGD,CAAO,CACtC,EClBaE,EAAW,GAAiBH,EAAMI,CAAM,ECmDxCC,EACX,GACM,CACN,GAAM,CACJ,SACA,SACA,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GI1B,CACT,CCnFA,MAAa6B,EAAsB,GACjC3E,EAAc,CACZ,GAAGC,EACH,OAAQ,mBACR,SAAU,EAAG,EAAa,IAAiB,GAAG4B,EAAY,GAAGC,GAC/D,CAAC,ECLU8C,EAA4B,GACvC5E,EAAc,CACZ,GAAGC,EACH,OAAQ,mBACR,SAAU,EAAG,EAAa,IAEjB,GAAG4B,IADcC,EAAa,YACC,GAE1C,CAAC,ECMU+C,EAAuC,GAA8B,CAChF,GAAM,CAAE,SAAQ,gBAAgB,KAAQ5E,EAClCC,EAAYH,EAClB,OAAO,OAAO,KAAKG,CAAS,CAAC,CAAC,QAC3B,EAAS,IACR0C,EAAI,CAAE,OAAQkC,EAAS,KAAMxE,EAAK,MAAOJ,EAAUI,GAAM,eAAc,CAAC,EAC1E,CAAC,CACH,CACF,E"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homer0/object-utils",
|
|
3
|
-
"description": "A small collection of utility methods to work with objects
|
|
4
|
-
"version": "
|
|
3
|
+
"description": "A small collection of utility methods to work with objects",
|
|
4
|
+
"version": "7.0.1",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/homer0/packages.git",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"extend": "^3.0.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@homer0/oxlint-config": "
|
|
41
|
-
"@homer0/tsconfig": "
|
|
40
|
+
"@homer0/oxlint-config": "3.0.1",
|
|
41
|
+
"@homer0/tsconfig": "6.0.1",
|
|
42
42
|
"@types/extend": "^3.0.4",
|
|
43
43
|
"@vitest/coverage-v8": "catalog:",
|
|
44
44
|
"oxlint": "catalog:",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"engine-strict": true,
|
|
51
51
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
52
|
+
"node": ">=24"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"lint": "oxlint .",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"build": "tsdown",
|
|
60
60
|
"prepublishOnly": "pnpm run build"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "0e14c0d4519b19d9732b41e23cc0f40114ae32c6"
|
|
63
63
|
}
|