@homer0/object-utils 1.1.1 → 2.0.0
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/README.md +2 -2
- package/dist/esm/index.js +32 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +36 -22
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -235,9 +235,9 @@ There are also a few "shorthand implementations" of `formatKeys`:
|
|
|
235
235
|
|
|
236
236
|
### 🤘 Development
|
|
237
237
|
|
|
238
|
-
As this project is part of the `packages` monorepo,
|
|
238
|
+
As this project is part of the `packages` monorepo, some of the tooling, like ESLint and Husky, are installed on the root's `package.json`.
|
|
239
239
|
|
|
240
|
-
####
|
|
240
|
+
#### NPM tasks
|
|
241
241
|
|
|
242
242
|
| Task | Description |
|
|
243
243
|
| ------- | -------------------- |
|
package/dist/esm/index.js
CHANGED
|
@@ -200,7 +200,9 @@ function set(options, path, value) {
|
|
|
200
200
|
} else {
|
|
201
201
|
const errorPath = currentPath.substring(pathDelimiter.length);
|
|
202
202
|
if (failWithError) {
|
|
203
|
-
throw new Error(
|
|
203
|
+
throw new Error(
|
|
204
|
+
`There's already an element of type '${elementType}' on '${errorPath}'`
|
|
205
|
+
);
|
|
204
206
|
} else {
|
|
205
207
|
foundInvalid = true;
|
|
206
208
|
}
|
|
@@ -220,24 +222,27 @@ var extract = (options) => {
|
|
|
220
222
|
const copied = copy(target);
|
|
221
223
|
let result = {};
|
|
222
224
|
let failed = false;
|
|
223
|
-
(Array.isArray(paths) ? paths : [paths]).reduce(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
225
|
+
(Array.isArray(paths) ? paths : [paths]).reduce(
|
|
226
|
+
(acc, objPath) => {
|
|
227
|
+
let destPath;
|
|
228
|
+
let originPath;
|
|
229
|
+
if (typeof objPath === "string") {
|
|
230
|
+
destPath = objPath;
|
|
231
|
+
originPath = objPath;
|
|
232
|
+
} else {
|
|
233
|
+
const [firstKey] = Object.keys(objPath);
|
|
234
|
+
destPath = firstKey;
|
|
235
|
+
originPath = objPath[destPath];
|
|
236
|
+
}
|
|
237
|
+
acc.push({
|
|
238
|
+
origin: originPath,
|
|
239
|
+
customDest: destPath.includes(pathDelimiter),
|
|
240
|
+
dest: destPath
|
|
241
|
+
});
|
|
242
|
+
return acc;
|
|
243
|
+
},
|
|
244
|
+
[]
|
|
245
|
+
).some((pathInfo) => {
|
|
241
246
|
let breakLoop = false;
|
|
242
247
|
const value = get({
|
|
243
248
|
target: copied,
|
|
@@ -283,7 +288,10 @@ var flat = (options) => {
|
|
|
283
288
|
const valueType = typeof value;
|
|
284
289
|
const isObject = valueType === "object" && value !== null;
|
|
285
290
|
if (isObject && (!shouldFlatten || shouldFlatten(key, value))) {
|
|
286
|
-
result = merge(
|
|
291
|
+
result = merge(
|
|
292
|
+
result,
|
|
293
|
+
flat({ target: value, pathDelimiter, prefix: name, shouldFlatten })
|
|
294
|
+
);
|
|
287
295
|
} else {
|
|
288
296
|
result[name] = isObject ? copy(value) : value;
|
|
289
297
|
}
|
|
@@ -380,7 +388,10 @@ var snakeToLowerCamelKeys = (options) => formatKeys({
|
|
|
380
388
|
var unflat = (options) => {
|
|
381
389
|
const { target, pathDelimiter = "." } = options;
|
|
382
390
|
const useTarget = target;
|
|
383
|
-
return Object.keys(useTarget).reduce(
|
|
391
|
+
return Object.keys(useTarget).reduce(
|
|
392
|
+
(current, key) => set({ target: current, path: key, value: useTarget[key], pathDelimiter }),
|
|
393
|
+
{}
|
|
394
|
+
);
|
|
384
395
|
};
|
|
385
396
|
export {
|
|
386
397
|
copy,
|
package/dist/esm/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';\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';\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';\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';\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 result[usePath] = useValue;\n return result as T;\n }\n\n const parts = usePath.split(pathDelimiter);\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 if (result && last) {\n currentElement[last] = useValue;\n }\n\n return result as T | undefined;\n}\n\nexport { set };\n","import { get } from './get';\nimport { set } from './set';\nimport { copy } from './copy';\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';\nimport { merge } from './merge';\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';\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';\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';\nimport { get } from './get';\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';\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';\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';\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;AAwBO,IAAM,QAAQ,IAAiB,YAA0B;AAC9D,QAAM,CAAC,eAAe;AACtB,QAAM,OAAO,MAAM,QAAQ,WAAW,IAAI,CAAC,IAAI,CAAC;AAChD,SAAO,OAAO,MAAM,MAAM,GAAG,OAAO;AACtC;;;ACnBO,IAAM,OAAO,CAAI,WAAiB,MAAM,MAAM;;;ACwD9C,IAAM,aAAa,CACxB,YACM;AACN,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,CAAC;AAAA,IACX,UAAU,CAAC;AAAA,IACX,gBAAgB;AAAA,MACd;AAEJ,QAAM,YAAY;AAElB,QAAM,OAAO,OAAO,KAAK,MAAiC;AAW1D,QAAM,mBAA4C,CAAC;AACnD,OAAK,QAAQ,CAAC,QAAQ;AACpB,UAAM,QAAQ,UAAU;AACxB,qBAAiB,OAAO,CAAC,CACvB,UACA,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,QAAQ,KAAK,KACpB,O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Aa,iBAAiB;AACzC,UAAM,kBAAkB,aAAa,YAAY;AACjD,WAAO,GAAG,cAAc;AAAA,EAC1B;AACF,CAAC;;;ACWI,IAAM,SAAS,CAA8B,YAA8B;AAChF,QAAM,EAAE,QAAQ,gBAAgB,QAAQ;AACxC,QAAM,YAAY;AAClB,SAAO,OAAO,KAAK,SAAS,EAAE,OAC5B,CAAC,SAAS,QACR,IAAI,EAAE,QAAQ,SAAS,MAAM,KAAK,OAAO,UAAU,MAAM,cAAc,CAAC,GAC1E,CAAC,CACH;AACF;","names":[]}
|
|
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';\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';\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';\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';\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 result[usePath] = useValue;\n return result as T;\n }\n\n const parts = usePath.split(pathDelimiter);\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 if (result && last) {\n currentElement[last] = useValue;\n }\n\n return result as T | undefined;\n}\n\nexport { set };\n","import { get } from './get';\nimport { set } from './set';\nimport { copy } from './copy';\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';\nimport { merge } from './merge';\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';\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';\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';\nimport { get } from './get';\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';\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';\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';\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,OAAO,YAAY;AAwBZ,IAAM,QAAQ,IAAiB,YAA0B;AAC9D,QAAM,CAAC,WAAW,IAAI;AACtB,QAAM,OAAO,MAAM,QAAQ,WAAW,IAAI,CAAC,IAAI,CAAC;AAChD,SAAO,OAAO,MAAM,MAAM,GAAG,OAAO;AACtC;;;ACnBO,IAAM,OAAO,CAAI,WAAiB,MAAM,MAAM;;;ACwD9C,IAAM,aAAa,CACxB,YACM;AACN,QAAM;AAAA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SAAO,UAAU;AACjB,MAAI,wBAAwB,CAAC,OAAO,KAAK,SAAS,EAAE,QAAQ;AAC1D,WAAO,OAAO;AAAA,MACZ,QAAQ;AAAA,MACR,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;AC1FO,IAAM,kBAAkB,CAAI,YACjC,WAAc;AAAA,EACZ,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,SAAS,CAAC,GAAG,aAAa,iBAAiB,GAAG,eAAe;AAC/D,CAAC;;;ACLI,IAAM,wBAAwB,CAAI,YACvC,WAAc;AAAA,EACZ,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,SAAS,CAAC,GAAG,aAAa,iBAAiB;AACzC,UAAM,kBAAkB,aAAa,YAAY;AACjD,WAAO,GAAG,cAAc;AAAA,EAC1B;AACF,CAAC;;;ACWI,IAAM,SAAS,CAA8B,YAA8B;AAChF,QAAM,EAAE,QAAQ,gBAAgB,IAAI,IAAI;AACxC,QAAM,YAAY;AAClB,SAAO,OAAO,KAAK,SAAS,EAAE;AAAA,IAC5B,CAAC,SAAS,QACR,IAAI,EAAE,QAAQ,SAAS,MAAM,KAAK,OAAO,UAAU,MAAM,cAAc,CAAC;AAAA,IAC1E,CAAC;AAAA,EACH;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ declare const copy: <T>(target: T) => T;
|
|
|
13
13
|
* @param substring The captured string to replace.
|
|
14
14
|
* @param args The list of groups captured by the expression.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
type FormatKeysReplaceFn = (substring: string, ...args: string[]) => string;
|
|
17
|
+
type FormatKeysOptions = {
|
|
18
18
|
/**
|
|
19
19
|
* The object to transform.
|
|
20
20
|
*/
|
|
@@ -42,7 +42,7 @@ declare type FormatKeysOptions = {
|
|
|
42
42
|
*/
|
|
43
43
|
pathDelimiter?: string;
|
|
44
44
|
};
|
|
45
|
-
|
|
45
|
+
type FormatKeysExtensionOptions = Omit<FormatKeysOptions, 'search' | 'replace'>;
|
|
46
46
|
/**
|
|
47
47
|
* Formats all the keys on an object using a way similar to `.replace(regexp, ...)` but
|
|
48
48
|
* that also works recursively and with _"object paths"_.
|
|
@@ -93,8 +93,8 @@ declare const dashToSnakeKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
|
93
93
|
* Used in the {@link extract} function to specify a path for a property, or an "origin path"
|
|
94
94
|
* and an "extraction path".
|
|
95
95
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
type extractionPath = string | Record<string, string>;
|
|
97
|
+
type ExtractOptions = {
|
|
98
98
|
/**
|
|
99
99
|
* The object from where the property/properties will be extracted.
|
|
100
100
|
*/
|
|
@@ -149,8 +149,8 @@ declare const extract: <T = Record<string, unknown>>(options: ExtractOptions) =>
|
|
|
149
149
|
* @param key The key to check inside its parent.
|
|
150
150
|
* @param value The value of the key.
|
|
151
151
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
type ShouldFlattenFn = (key: string, value: unknown) => boolean;
|
|
153
|
+
type FlatOptions = {
|
|
154
154
|
/**
|
|
155
155
|
* The object to transform.
|
|
156
156
|
*/
|
|
@@ -190,7 +190,7 @@ declare type FlatOptions = {
|
|
|
190
190
|
*/
|
|
191
191
|
declare const flat: <T = Record<string, unknown>>(options: FlatOptions) => T;
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
type GetOptions = {
|
|
194
194
|
/**
|
|
195
195
|
* The object from where the property will be read.
|
|
196
196
|
*/
|
|
@@ -272,7 +272,7 @@ declare const lowerCamelToSnakeKeys: <T>(options: FormatKeysExtensionOptions) =>
|
|
|
272
272
|
*/
|
|
273
273
|
declare const merge: <T = unknown>(...targets: unknown[]) => T;
|
|
274
274
|
|
|
275
|
-
|
|
275
|
+
type RemoveOptions = {
|
|
276
276
|
/**
|
|
277
277
|
* The object from where the property will be removed.
|
|
278
278
|
*/
|
|
@@ -316,7 +316,7 @@ declare type RemoveOptions = {
|
|
|
316
316
|
declare function remove<T = unknown>(options: RemoveOptions): T | undefined;
|
|
317
317
|
declare function remove<T = unknown>(options: unknown, path: string): T | undefined;
|
|
318
318
|
|
|
319
|
-
|
|
319
|
+
type SetOptions = {
|
|
320
320
|
/**
|
|
321
321
|
* The object where the property will be set.
|
|
322
322
|
*/
|
|
@@ -375,7 +375,7 @@ declare const snakeToDashKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
|
375
375
|
*/
|
|
376
376
|
declare const snakeToLowerCamelKeys: <T>(options: FormatKeysExtensionOptions) => T;
|
|
377
377
|
|
|
378
|
-
|
|
378
|
+
type UnflatOptions = {
|
|
379
379
|
/**
|
|
380
380
|
* The object to transform.
|
|
381
381
|
*/
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
|
|
23
26
|
// src/index.ts
|
|
@@ -243,7 +246,9 @@ function set(options, path, value) {
|
|
|
243
246
|
} else {
|
|
244
247
|
const errorPath = currentPath.substring(pathDelimiter.length);
|
|
245
248
|
if (failWithError) {
|
|
246
|
-
throw new Error(
|
|
249
|
+
throw new Error(
|
|
250
|
+
`There's already an element of type '${elementType}' on '${errorPath}'`
|
|
251
|
+
);
|
|
247
252
|
} else {
|
|
248
253
|
foundInvalid = true;
|
|
249
254
|
}
|
|
@@ -263,24 +268,27 @@ var extract = (options) => {
|
|
|
263
268
|
const copied = copy(target);
|
|
264
269
|
let result = {};
|
|
265
270
|
let failed = false;
|
|
266
|
-
(Array.isArray(paths) ? paths : [paths]).reduce(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
271
|
+
(Array.isArray(paths) ? paths : [paths]).reduce(
|
|
272
|
+
(acc, objPath) => {
|
|
273
|
+
let destPath;
|
|
274
|
+
let originPath;
|
|
275
|
+
if (typeof objPath === "string") {
|
|
276
|
+
destPath = objPath;
|
|
277
|
+
originPath = objPath;
|
|
278
|
+
} else {
|
|
279
|
+
const [firstKey] = Object.keys(objPath);
|
|
280
|
+
destPath = firstKey;
|
|
281
|
+
originPath = objPath[destPath];
|
|
282
|
+
}
|
|
283
|
+
acc.push({
|
|
284
|
+
origin: originPath,
|
|
285
|
+
customDest: destPath.includes(pathDelimiter),
|
|
286
|
+
dest: destPath
|
|
287
|
+
});
|
|
288
|
+
return acc;
|
|
289
|
+
},
|
|
290
|
+
[]
|
|
291
|
+
).some((pathInfo) => {
|
|
284
292
|
let breakLoop = false;
|
|
285
293
|
const value = get({
|
|
286
294
|
target: copied,
|
|
@@ -326,7 +334,10 @@ var flat = (options) => {
|
|
|
326
334
|
const valueType = typeof value;
|
|
327
335
|
const isObject = valueType === "object" && value !== null;
|
|
328
336
|
if (isObject && (!shouldFlatten || shouldFlatten(key, value))) {
|
|
329
|
-
result = merge(
|
|
337
|
+
result = merge(
|
|
338
|
+
result,
|
|
339
|
+
flat({ target: value, pathDelimiter, prefix: name, shouldFlatten })
|
|
340
|
+
);
|
|
330
341
|
} else {
|
|
331
342
|
result[name] = isObject ? copy(value) : value;
|
|
332
343
|
}
|
|
@@ -423,7 +434,10 @@ var snakeToLowerCamelKeys = (options) => formatKeys({
|
|
|
423
434
|
var unflat = (options) => {
|
|
424
435
|
const { target, pathDelimiter = "." } = options;
|
|
425
436
|
const useTarget = target;
|
|
426
|
-
return Object.keys(useTarget).reduce(
|
|
437
|
+
return Object.keys(useTarget).reduce(
|
|
438
|
+
(current, key) => set({ target: current, path: key, value: useTarget[key], pathDelimiter }),
|
|
439
|
+
{}
|
|
440
|
+
);
|
|
427
441
|
};
|
|
428
442
|
// Annotate the CommonJS export names for ESM import in node:
|
|
429
443
|
0 && (module.exports = {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../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":["export * from './fns/copy';\nexport * from './fns/dashToLowerCamelKeys';\nexport * from './fns/dashToSnakeKeys';\nexport * from './fns/extract';\nexport * from './fns/flat';\nexport * from './fns/formatKeys';\nexport * from './fns/get';\nexport * from './fns/lowerCamelToDashKeys';\nexport * from './fns/lowerCamelToSnakeKeys';\nexport * from './fns/merge';\nexport * from './fns/remove';\nexport * from './fns/set';\nexport * from './fns/snakeToDashKeys';\nexport * from './fns/snakeToLowerCamelKeys';\nexport * from './fns/unflat';\n","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';\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';\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';\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';\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 result[usePath] = useValue;\n return result as T;\n }\n\n const parts = usePath.split(pathDelimiter);\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 if (result && last) {\n currentElement[last] = useValue;\n }\n\n return result as T | undefined;\n}\n\nexport { set };\n","import { get } from './get';\nimport { set } from './set';\nimport { copy } from './copy';\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';\nimport { merge } from './merge';\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';\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';\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';\nimport { get } from './get';\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';\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';\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';\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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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":["export * from './fns/copy';\nexport * from './fns/dashToLowerCamelKeys';\nexport * from './fns/dashToSnakeKeys';\nexport * from './fns/extract';\nexport * from './fns/flat';\nexport * from './fns/formatKeys';\nexport * from './fns/get';\nexport * from './fns/lowerCamelToDashKeys';\nexport * from './fns/lowerCamelToSnakeKeys';\nexport * from './fns/merge';\nexport * from './fns/remove';\nexport * from './fns/set';\nexport * from './fns/snakeToDashKeys';\nexport * from './fns/snakeToLowerCamelKeys';\nexport * from './fns/unflat';\n","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';\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';\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';\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';\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 result[usePath] = useValue;\n return result as T;\n }\n\n const parts = usePath.split(pathDelimiter);\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 if (result && last) {\n currentElement[last] = useValue;\n }\n\n return result as T | undefined;\n}\n\nexport { set };\n","import { get } from './get';\nimport { set } from './set';\nimport { copy } from './copy';\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';\nimport { merge } from './merge';\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';\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';\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';\nimport { get } from './get';\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';\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';\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';\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAmB;AAwBZ,IAAM,QAAQ,IAAiB,YAA0B;AAC9D,QAAM,CAAC,WAAW,IAAI;AACtB,QAAM,OAAO,MAAM,QAAQ,WAAW,IAAI,CAAC,IAAI,CAAC;AAChD,aAAO,cAAAA,SAAO,MAAM,MAAM,GAAG,OAAO;AACtC;;;ACnBO,IAAM,OAAO,CAAI,WAAiB,MAAM,MA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MAAI,OAAO,cAAc,aAAa;AACpC,WAAO;AAAA,EACT;AAEA,SAAO,UAAU;AACjB,MAAI,wBAAwB,CAAC,OAAO,KAAK,SAAS,EAAE,QAAQ;AAC1D,WAAO,OAAO;AAAA,MACZ,QAAQ;AAAA,MACR,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;AC1FO,IAAM,kBAAkB,CAAI,YACjC,WAAc;AAAA,EACZ,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,SAAS,CAAC,GAAG,aAAa,iBAAiB,GAAG,eAAe;AAC/D,CAAC;;;ACLI,IAAM,wBAAwB,CAAI,YACvC,WAAc;AAAA,EACZ,GAAG;AAAA,EACH,QAAQ;AAAA,EACR,SAAS,CAAC,GAAG,aAAa,iBAAiB;AACzC,UAAM,kBAAkB,aAAa,YAAY;AACjD,WAAO,GAAG,cAAc;AAAA,EAC1B;AACF,CAAC;;;ACWI,IAAM,SAAS,CAA8B,YAA8B;AAChF,QAAM,EAAE,QAAQ,gBAAgB,IAAI,IAAI;AACxC,QAAM,YAAY;AAClB,SAAO,OAAO,KAAK,SAAS,EAAE;AAAA,IAC5B,CAAC,SAAS,QACR,IAAI,EAAE,QAAQ,SAAS,MAAM,KAAK,OAAO,UAAU,MAAM,cAAc,CAAC;AAAA,IAC1E,CAAC;AAAA,EACH;AACF;","names":["extend"]}
|
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": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/homer0/packages.git",
|
|
@@ -27,23 +27,24 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/extend": "^3.0.1",
|
|
30
|
-
"jest": "^
|
|
31
|
-
"ts-jest": "^
|
|
32
|
-
"tsup": "^6.
|
|
33
|
-
"typescript": "^4.
|
|
30
|
+
"jest": "^29.3.1",
|
|
31
|
+
"ts-jest": "^29.0.3",
|
|
32
|
+
"tsup": "^6.5.0",
|
|
33
|
+
"typescript": "^4.9.4"
|
|
34
34
|
},
|
|
35
35
|
"engine-strict": true,
|
|
36
36
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
37
|
+
"node": ">=16"
|
|
38
38
|
},
|
|
39
39
|
"main": "./dist/index.js",
|
|
40
40
|
"module": "./dist/esm/index.js",
|
|
41
41
|
"types": "./dist/index.d.ts",
|
|
42
42
|
"scripts": {
|
|
43
|
+
"lint": "eslint .",
|
|
43
44
|
"test": "jest -c ./.jestrc.js",
|
|
44
45
|
"types:check": "tsc --noEmit && tsc --noEmit --project ./tests/tsconfig.json",
|
|
45
46
|
"build": "tsup src/index.ts",
|
|
46
47
|
"prepublishOnly": "npm run build"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "86d8723fd11c969e334d58c4e6bc4d290311fe26"
|
|
49
50
|
}
|