|
|
2 týždňov pred | |
|---|---|---|
| .. | ||
| .github | 2 týždňov pred | |
| node_modules | 2 týždňov pred | |
| test | 2 týždňov pred | |
| .eslintrc | 2 týždňov pred | |
| .nycrc | 2 týždňov pred | |
| CHANGELOG.md | 2 týždňov pred | |
| LICENSE | 2 týždňov pred | |
| README.md | 2 týždňov pred | |
| index.d.ts | 2 týždňov pred | |
| index.js | 2 týždňov pred | |
| package.json | 2 týždňov pred | |
| tsconfig.json | 2 týždňov pred | |
Push an array of items into an array, while being robust against prototype modification.
npm install --save safe-push-apply
var safePushApply = require('safe-push-apply');
var assert = require('assert');
var arr = [1, 2, 3];
var orig = Array.prototype[Symbol.iterator];
delete Array.prototype[Symbol.iterator];
assert.throws(() => {
try {
arr.push(...[3, 4, 5]);
} finally {
Array.prototype[Symbol.iterator] = orig;
}
}, 'array is not iterable anymore');
delete Array.prototype.push;
safePushApply(arr, [3, 4, 5]);
assert.deepEqual(arr, [1, 2, 3, 3, 4, 5]);
Simply clone the repo, npm install, and run npm test