deep-replace-in-object

deep replaces a string in an object

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
deep-replace-in-object
001.1.76 years ago6 years agoMinified + gzip package size for deep-replace-in-object in KB

Readme

deep-replace-in-object
CircleCI Test Coverage
no-mutation function to deeply replace strings and numbers in nested objects/arrays.
Example:
const object = {
  key1: 'some value',
  key2: {
    key1: 'some value',
    key2: [5, 'some value', 'some other value', 10],
    key3: [
      { key1: 'some other value' },
      { key2: [10, 'some other value', 5, 'some value'] },
      { key3: 'some value' },
      { key4: 5 },
      { key5: 10 }
    ],
    key4: 10,
    key5: 5,
  },
  key3: [10, 'some other value', 'some value', 5],
  key4: 10,
  key5: 'some other value',
  key6: 5,
};
const replacedObject = deepReplaceInObject('some value', 'a new value', object);
console.log(replacedObject);
{
  key1: 'a new value',
  key2: {
    key1: 'a new value',
    key2: [5, 'a new value', 'some other value', 10],
    key3: [
      { key1: 'some other value' },
      { key2: [10, 'some other value', 5, 'a new value'] },
      { key3: 'a new value' },
      { key4: 5 },
      { key5: 10 }
    ],
    key4: 10,
    key5: 5,
  },
  key3: [10, 'some other value', 'a new value', 5],
  key4: 10,
  key5: 'some other value',
  key6: 5,
};