string/slice.js

  1. import { applyStringMethod } from './applyStringMethod'
  2. /**
  3. * Replaces by a slice of former string starting at <code>beginIndex</code> and ending at <code>endIndex</code> or end of the string.<br/>
  4. * ⚠ Due to name conflicts, this function is named <code>stringSlice</code> when imported from top level (<code>import { stringSlice } from 'immutadot'</code>).
  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 {number} beginIndex Beginning index of slice.
  10. * @param {number?} endIndex Ending index of slice.
  11. * @return {Object} Returns the updated object.
  12. * @example slice({ nested: { a: 'Hello World !' } }, 6) // => { nested: { a: 'World !' } }
  13. * @example slice({ nested: { a: 'Hello World !' } }, 6, 11) // => { nested: { a: 'World' } }
  14. * @see {@link https://mdn.io/String.prototype.slice|String.prototype.slice} for more information.
  15. * @since 1.0.0
  16. */
  17. const slice = applyStringMethod(String.prototype.slice, { arity: 1 })
  18. export { slice }