https://github.com/jonschlinkert/rename-keys
Modify/rename the keys of the own enumerable properties of an object.
https://github.com/jonschlinkert/rename-keys
javascript keys nodejs object properties rename rename-keys
Last synced: 6 months ago
JSON representation
Modify/rename the keys of the own enumerable properties of an object.
- Host: GitHub
- URL: https://github.com/jonschlinkert/rename-keys
- Owner: jonschlinkert
- License: mit
- Created: 2014-02-10T15:02:53.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2020-01-28T13:49:36.000Z (over 5 years ago)
- Last Synced: 2025-04-06T22:03:31.955Z (6 months ago)
- Topics: javascript, keys, nodejs, object, properties, rename, rename-keys
- Language: JavaScript
- Homepage: https://github.com/jonschlinkert
- Size: 24.4 KB
- Stars: 27
- Watchers: 3
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rename-keys [](https://www.npmjs.com/package/rename-keys) [](https://npmjs.org/package/rename-keys) [](https://npmjs.org/package/rename-keys) [](https://travis-ci.org/jonschlinkert/rename-keys)
> Modify the names of the own enumerable properties (keys) of an object.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save rename-keys
```## Usage
```js
var renameKeys = require('rename-keys');
```## API
**Params**
* `object` **{Object}**: The object with keys to rename.
* `fn` **{Function}**: Renaming function to use on each key in the object.
* `returns` **{Object}**: Returns a new object with renamed keys.**Example**
```js
var obj = renameKeys({a: 1, b: 2, c: 3}, function(key, val) {
return '--' + key;
});
console.log(obj);
//=> { '--a': 1, '--b': 2, '--c': 3}
```**Rename based on value**
```js
var obj = renameKeys({a: 1, b: 2, c: 3}, function(key, val) {
return val > 1 ? ('++' + key) : ('--' + key);
});
console.log(obj);
//=> {'--a': 1, '++b': 2, '++c': 3};
```## About
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 15 | [jonschlinkert](https://github.com/jonschlinkert) |
| 5 | [doowb](https://github.com/doowb) |
| 2 | [stellard](https://github.com/stellard) |
| 1 | [kof](https://github.com/kof) |
| 1 | [robinbullocks4rb](https://github.com/robinbullocks4rb) |
| 1 | [palanik](https://github.com/palanik) |### Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```### Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on October 13, 2017._