source: imaps-frontend/node_modules/safe-push-apply/README.md

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

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