Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rename-keys

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rename-keys

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

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

rename-keys NPM version

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

Bug? Feature request? Please create an issue.

Quickstart

npm:

npm i rename-keys --save

bower:

bower install rename-keys --save

Usage

var rename = require('rename-keys');
rename( object, function );

Arguments

  • object {Object}: the object to iterate over.
  • function {Function}: the function to use to rename each own enumerable property of object.

Example

The object to iterate over:

var pkg = require('./package.json');

and this renaming function:

var addDashes = function(str) {
  return '--' + str;
};
console.log(rename(pkg, addDashes));

results in:

{ "--name": "rename-keys",
  "--description": "Modify the names of the own enumerable properties (keys) of an object.",
  "--version": "0.1.0",
  "--homepage": "https://github.com/jonschlinkert/rename-keys",
  "--author": {
    "name": "Jon Schlinkert",
    "url": "https://github.com/jonschlinkert"
  } ... }

Rename based on value

The value can also be passed in as as a second argument.

rename({a: 1, b: 2, c: 3}, function(key, value) {
  if (value > 1) return key + 'x';
});

results in:

{a: 1, bx: 2, cx: 3});

Authors

Jon Schlinkert

License

Copyright (c) 2014-2015, Jon Schlinkert. Released under the MIT license

Keywords

FAQs

Package last updated on 13 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc