An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# rename-keys [![NPM version](https://img.shields.io/npm/v/rename-keys.svg?style=flat)](https://www.npmjs.com/package/rename-keys) [![NPM monthly downloads](https://img.shields.io/npm/dm/rename-keys.svg?style=flat)](https://npmjs.org/package/rename-keys) [![NPM total downloads](https://img.shields.io/npm/dt/rename-keys.svg?style=flat)](https://npmjs.org/package/rename-keys) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/rename-keys.svg?style=flat&label=Travis)](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._