Function replaceDeep

Replaces all occurrences of search with value in source object/array. Comparison is done with Object.is. If source is exactly the search a value will be returned. It does not do a substring replacements.

Warnings:

  • By default, it does not mutate the source/deep objects/arrays, but it can be enabled with mutate option.
  • By default, it does not go into instances for replacement, only plain objects.
  • If your instances are cross-referenced, you may end up in an infinite loop.

TypeScript users: This is way too dynamic to type properly, therefore, typing assumes the most basic form of replacement where search and value are of the same type. If that's not the case for you - you'll have to typecast.

  • Type Parameters

    • T

    Parameters

    • source: T

      source object/array/value

    • search: unknown

      value to search for

    • value: unknown

      value to replace with

    • Optionaloptions: Options

      optional options

    Returns T