https://github.com/semibran/object-rename
Rename an object's keys using a map
https://github.com/semibran/object-rename
object rename
Last synced: about 1 year ago
JSON representation
Rename an object's keys using a map
- Host: GitHub
- URL: https://github.com/semibran/object-rename
- Owner: semibran
- Created: 2017-05-30T05:53:32.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-07T00:40:55.000Z (about 9 years ago)
- Last Synced: 2025-03-30T09:20:08.346Z (about 1 year ago)
- Topics: object, rename
- Language: JavaScript
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# object-rename
> Rename an object's keys using a map
```js
const rename = require('object-rename')
var object = { foo: 3, bar: 42, baz: 101 }
var keymap = { foo: 'lorem', bar: 'ipsum' }
var result = rename(object, keymap)
console.log(result) // -> { lorem: 3, ipsum: 42, baz: 101 }
```
This module exports the `rename` function, which takes two arguments:
- `object`: The object whose keys are to be renamed
- `keymap`: An map-like object whose keys correspond to the new keys to be renamed to
`rename` returns a copy of `object` with the keys renamed as described by `keymap`.
## install
```sh
npm install object-rename
```
## license
MIT