Skip to content

afeiship/map-keys

Repository files navigation

map-keys

Recursively rename or copy object keys with full control.

version license size download

installation

yarn add @jswork/map-keys

usage

import mapKeys from '@jswork/map-keys';

// Basic key renaming
const data = { oldKey: 'value', keepKey: 'another' };
const result = mapKeys(data, { oldKey: 'newKey' });
// { newKey: 'value', keepKey: 'another' }

// Copy mode: keep both original and new keys
const result2 = mapKeys(data, { oldKey: 'newKey' }, { mode: 'copy' });
// { oldKey: 'value', keepKey: 'another', newKey: 'value' }

// Deep nested transformation
const nested = {
  users: [{ firstName: 'John', lastName: 'Doe' }]
};
const result3 = mapKeys(nested, {
  firstName: 'first_name',
  lastName: 'last_name'
});
// { users: [{ first_name: 'John', last_name: 'Doe' }] }

license

Code released under the MIT license.

About

Recursively rename or copy object keys with full control.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published