string/replace.js

  1. import _replace from 'lodash/replace'
  2. import { convert } from 'util/convert'
  3. /**
  4. * Replaces matches for pattern in string with replacement.
  5. * @function
  6. * @memberof string
  7. * @param {Object} object The object to modify.
  8. * @param {Array|string} path The path of the property to set.
  9. * @param {RegExp|string} pattern The pattern to replace.
  10. * @param {Function|string} replacement The match replacement.
  11. * @return {Object} Returns the updated object.
  12. * @example replace({ nested: { a: "Hi Nico" } }, 'nested.a', 'Nico', 'Yvo') // => { nested: { a: "Hi Yvo" } }
  13. * @see {@link https://lodash.com/docs#replace|lodash.replace} for more information.
  14. * @since 0.3.0
  15. */
  16. const replace = convert(_replace)
  17. export { replace, replace as default }