Package detail

rename-keys

jonschlinkert675.1kMIT2.0.1

Modify the names of the own enumerable properties (keys) of an object.

enumerable, keys, object, properties

readme

rename-keys NPM version NPM monthly downloads NPM total downloads Linux Build Status

Modify the names of the own enumerable properties (keys) of an object.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

Install

Install with npm:

$ npm install --save rename-keys

Usage

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

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

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.

Contributors

Commits Contributor
15 jonschlinkert
5 doowb
2 stellard
1 kof
1 robinbullocks4rb
1 palanik

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ 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:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on October 13, 2017.

changelog

Release history

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

<summary>Guiding Principles</summary> - Changelogs are for humans, not machines. - There should be an entry for every single version. - The same types of changes should be grouped. - Versions and sections should be linkable. - The latest version comes first. - The release date of each versions is displayed. - Mention whether you follow Semantic Versioning.
<summary>Types of changes</summary> Changelog entries are classified using the following labels (from keep-a-changelog): - Added for new features. - Changed for changes in existing functionality. - Deprecated for soon-to-be removed features. - Removed for now removed features. - Fixed for any bug fixes. - Security in case of vulnerabilities.

[2.0.1] - 2017-10-13

Fixed

  • Adds isobject to dependencies.

[2.0.0] - 2017-10-13

Removed

  • No longer wrapped in UMD code since it should be added by implementations.

Added

  • Now throws a TypeError when the first argument is not an object.

Misc

  • Add .verb.md template to generate readme documentation
  • update bower.json

1.2.0 - 2017-10-13

  • Merge pull request #9 from stellard/rename_on_value
  • Supports renaming a key based on the value

1.1.3 - 2017-04-03

  • Merge pull request #8 from S4RB/master
  • Fixes hasOwnProperty error when input does not inherit from Object.create

1.1.0 - 2015-01-20

  • add check for function, simplify

1.0.0 - 2015-01-20

  • Merge pull request #5 from palanik/master

[0.1.0] - 2014-02-10

  • first commit