deep-replace
v0.0.8
Published
deep replace objects using property string, regex, fn match
Downloads
147
Maintainers
Readme
🕳 deep-replace
deep replace objects using property string, regex, fn match
📦 usage
yarn add deep-replace
npm i deep-replace --save
const deepReplace = require('deep-replace')
📘 examples
const {match} = require('deep-replace')
// obj, valueTest, propertyTest, decoratorFn
const fixture = {
value: 'string',
nested: {
again: {
again: 'string',
object: {},
array: [],
},
},
}
const valueTest = (value) => typeof value === 'string'
const propertyTest = null
const decorator = ({val, obj, prop}) => {
obj[prop] = val + ' added me!'
}
match(object, valueTest, propertyTest, decorator)
// comes out as
// fixture.nested.again.again === 'string added me!'
// fixture.value === 'string added me!'