Replace object keys with String.prototype.replace
$ npm install --save key-replace
const keyReplace = require('key-replace');
const obj = {
foo: 'bar'
};
keyReplace(obj, 'fo', 'y');
//=> {yo: 'bar'}
keyReplace(obj, 'fo', str => str.toUpperCase());
//=> {FOo: 'bar'}
Returns a new object.
Required
Type: object
The object which keys will be replaced.
Required
Type: string
or regexp
Search for matching substring that will be replaced.
Required
Type: string
or function
Replacing the matching substring.
- array-replace - Replace array values with
String.prototype.replace
- value-replace - Replace object values with
String.prototype.replace
MIT © Andreas Gillström