string/replace.js

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