Skip to content

gillstrom/key-replace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

key-replace Build Status

Replace object keys with String.prototype.replace

Install

$ npm install --save key-replace

Usage

const keyReplace = require('key-replace');
const obj = {
	foo: 'bar'
};

keyReplace(obj, 'fo', 'y');
//=> {yo: 'bar'}

keyReplace(obj, 'fo', str => str.toUpperCase());
//=> {FOo: 'bar'}

API

keyReplace(input, search, replace)

Returns a new object.

input

Required
Type: object

The object which keys will be replaced.

search

Required
Type: string or regexp

Search for matching substring that will be replaced.

replace

Required
Type: string or function

Replacing the matching substring.

Related

  • array-replace - Replace array values with String.prototype.replace
  • value-replace - Replace object values with String.prototype.replace

License

MIT © Andreas Gillström

About

Replace object keys with String.prototype.replace

Resources

License

Stars

Watchers

Forks

Packages

No packages published