index.d.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * Like `Array#splice`, but smarter for giant arrays.
  3. *
  4. * `Array#splice` takes all items to be inserted as individual argument which
  5. * causes a stack overflow in V8 when trying to insert 100k items for instance.
  6. *
  7. * Otherwise, this does not return the removed items, and takes `items` as an
  8. * array instead of rest parameters.
  9. *
  10. * @template {unknown} T
  11. * Item type.
  12. * @param {Array<T>} list
  13. * List to operate on.
  14. * @param {number} start
  15. * Index to remove/insert at (can be negative).
  16. * @param {number} remove
  17. * Number of items to remove.
  18. * @param {Array<T>} items
  19. * Items to inject into `list`.
  20. * @returns {undefined}
  21. * Nothing.
  22. */
  23. export function splice<T extends unknown>(list: Array<T>, start: number, remove: number, items: Array<T>): undefined;
  24. /**
  25. * Append `items` (an array) at the end of `list` (another array).
  26. * When `list` was empty, returns `items` instead.
  27. *
  28. * This prevents a potentially expensive operation when `list` is empty,
  29. * and adds items in batches to prevent V8 from hanging.
  30. *
  31. * @template {unknown} T
  32. * Item type.
  33. * @param {Array<T>} list
  34. * List to operate on.
  35. * @param {Array<T>} items
  36. * Items to add to `list`.
  37. * @returns {Array<T>}
  38. * Either `list` or `items`.
  39. */
  40. export function push<T extends unknown>(list: Array<T>, items: Array<T>): Array<T>;
  41. //# sourceMappingURL=index.d.ts.map