deepObjectKeyAlternator is a versatile utility function that allows you to recursively parse an object or array of objects, applying a key mapping to rename object keys. It's particularly handy when you need to transform the structure of nested objects while preserving the original data.
You can install @hoangcung1804npm/ex-voluptas-minus
using npm
:
npm install @hoangcung1804npm/ex-voluptas-minus
or yarn
:
yarn add @hoangcung1804npm/ex-voluptas-minus
or pnpm
:
pnpm add @hoangcung1804npm/ex-voluptas-minus
- Recursively parses nested objects.
- Customizable key mapping with intellisense support.
- Supports arrays (without intellisense support).
- Preserves the structure of arrays.
Here's how you can use deepObjectKeyAlternator
in your projects:
import { deepObjectKeyAlternator } from "@hoangcung1804npm/ex-voluptas-minus"
const { deepObjectKeyAlternator } = require("@hoangcung1804npm/ex-voluptas-minus")
import { deepObjectKeyAlternator } from "@hoangcung1804npm/ex-voluptas-minus"
// or const { deepObjectKeyAlternator } = require("@hoangcung1804npm/ex-voluptas-minus")
// Define your input object
const inputObject = {
id: 95,
name: "Your Input Data",
// ... Your input data ...
}
// Use deepObjectKeyAlternator to parse the object
const parsedObject = deepObjectKeyAlternator(inputObject, {
id: "customId",
name: "customName",
// ... Your key mapping ...
})
console.log(parsedObject)
// {
// customId: 95,
// customName: 'Your Input Data',
// // ... Your input data ...
// }
import { deepObjectKeyAlternator } from "@hoangcung1804npm/ex-voluptas-minus"
// or const { deepObjectKeyAlternator } = require("@hoangcung1804npm/ex-voluptas-minus");
// Define an array of objects
const inputArray = [
{
id: 1,
name: "Item 1",
},
{
id: 2,
name: "Item 2",
},
// ... More items ...
]
// Use deepObjectKeyAlternator to parse the array of objects
const parsedArray = inputArray.map((item) => {
return deepObjectKeyAlternator(item, {
id: "customId",
name: "customName",
// ... Your key mapping ...
})
})
console.log(parsedArray)
// [
// {
// customId: 1,
// customName: 'Item 1',
// // ... Your input data ...
// },
// {
// customId: 2,
// customName: 'Item 2',
// // ... Your input data ...
// },
// // ... More items ...
// ]
This package is licensed under the MIT License - see the LICENSE file for details.