1.0.0 • Published 8 years ago

key-replace v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

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 => {
	return 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 mathching substring that will be replaced.

replace

Required
Type: string or function

Replacing the mathing substring.

License

MIT © Andreas Gillström