array/slice.js

  1. import { convertArrayMethod } from './convertArrayMethod'
  2. /**
  3. * Replaces an array by a slice of the former array from <code>start</code> up to, but not including, <code>end</code>.<br/>
  4. * ⚠ Due to name conflicts, this function is named <code>arraySlice</code> when imported from top level (<code>import { arraySlice } from 'immutadot'</code>).
  5. * @function
  6. * @memberof array
  7. * @param {Object} object The object to modify.
  8. * @param {Array|string} path The path of the property to set.
  9. * @param {number} [start=0] The start position.
  10. * @param {number} [end=array.length] The end position.
  11. * @return {Object} Returns the updated object.
  12. * @example slice({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', 1, 3) // => { nested: { prop: [2, 3] } }
  13. * @see {@link https://mdn.io/Array.prototype.slice|Array.prototype.slice} for more information.
  14. * @since 0.3.0
  15. */
  16. const slice = convertArrayMethod('slice', false)
  17. export { slice }