3fc5893ff7d91057b59c30aa501c9b435c352e2e9b90380eb373261b37a3c0038bac6502c90e44613786a0e249b9e8defc40fe4dcf6f9ed32b2944881a2201 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # safe-push-apply <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![License][license-image]][license-url]
  5. [![Downloads][downloads-image]][downloads-url]
  6. [![npm badge][npm-badge-png]][package-url]
  7. Push an array of items into an array, while being robust against prototype modification.
  8. ## Getting started
  9. ```sh
  10. npm install --save safe-push-apply
  11. ```
  12. ## Usage/Examples
  13. ```js
  14. var safePushApply = require('safe-push-apply');
  15. var assert = require('assert');
  16. var arr = [1, 2, 3];
  17. var orig = Array.prototype[Symbol.iterator];
  18. delete Array.prototype[Symbol.iterator];
  19. assert.throws(() => {
  20. try {
  21. arr.push(...[3, 4, 5]);
  22. } finally {
  23. Array.prototype[Symbol.iterator] = orig;
  24. }
  25. }, 'array is not iterable anymore');
  26. delete Array.prototype.push;
  27. safePushApply(arr, [3, 4, 5]);
  28. assert.deepEqual(arr, [1, 2, 3, 3, 4, 5]);
  29. ```
  30. ## Tests
  31. Simply clone the repo, `npm install`, and run `npm test`
  32. [package-url]: https://npmjs.org/package/safe-push-apply
  33. [npm-version-svg]: https://versionbadg.es/ljharb/safe-push-apply.svg
  34. [deps-svg]: https://david-dm.org/ljharb/safe-push-apply.svg
  35. [deps-url]: https://david-dm.org/ljharb/safe-push-apply
  36. [dev-deps-svg]: https://david-dm.org/ljharb/safe-push-apply/dev-status.svg
  37. [dev-deps-url]: https://david-dm.org/ljharb/safe-push-apply#info=devDependencies
  38. [npm-badge-png]: https://nodei.co/npm/safe-push-apply.png?downloads=true&stars=true
  39. [license-image]: https://img.shields.io/npm/l/safe-push-apply.svg
  40. [license-url]: LICENSE
  41. [downloads-image]: https://img.shields.io/npm/dm/safe-push-apply.svg
  42. [downloads-url]: https://npm-stat.com/charts.html?package=safe-push-apply
  43. [codecov-image]: https://codecov.io/gh/ljharb/safe-push-apply/branch/main/graphs/badge.svg
  44. [codecov-url]: https://app.codecov.io/gh/ljharb/safe-push-apply/
  45. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/safe-push-apply
  46. [actions-url]: https://github.com/ljharb/safe-push-apply/actions