Creates a deep clone of a JSON data structure with keys transformed by a provided function.
Install the package:
npm i @cocopina/transform-keys
Returns a new, transformed object.
import transformKeys from '@cocopina/transform-keys';
const transformFn = (value) => `_${value}`;
const object = {
key: 1
};
const transformed = transformKeys(object, transformFn);
console.log(transformed); // {_key: 1}
The object which keys' you wish to transform.
The transformation function you wish to use on the object's keys.
Additional options:
Option | Type | What It Does | Default |
---|---|---|---|
deep |
Boolean |
Whether or not to transform the object's keys recursively | true |
recursionLevel |
Number |
How deep should the transformation go | - |