1.1.7 • Published 7 years ago

deep-replace-in-object v1.1.7

Weekly downloads
721
License
Apache-2.0
Repository
github
Last release
7 years ago

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,
};
1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago