npm.io
1.0.0 • Published 10 years ago

value-replace

Licence
MIT
Version
1.0.0
Deps
0
Vulns
0
Weekly
0
Stars
1

value-replace Build Status

Replace object values with String.prototype.replace

Install

$ npm install --save value-replace

Usage

const valueReplace = require('value-replace');
const obj = {
	foo: 'bar'
};

valueReplace(obj, 'bar', 'baz');
//=> {foo: 'baz'}

valueReplace(obj, 'ba', str => str.toUpperCase());
//=> {foo: 'BAr'}

API

valueReplace(input, search, replace)

Returns a new object.

input

Required
Type: object

The object which values will be replaced.

Required
Type: string or regexp

Search for matching substring that will be replaced.

replace

Required
Type: string or function

Replacing the matching substring.

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

License

MIT Andreas Gillström