deep-replace

0.0.8 • Public • Published

🕳 deep-replace

NPM version MIT License fliphub flipfam

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!'
 

Package Sidebar

Install

npm i deep-replace

Weekly Downloads

25

Version

0.0.8

License

none

Last publish

Collaborators

  • aretecode