safe-push-apply (1.0.0)
Published 2026-02-24 14:04:40 +00:00 by atheaadmin
Installation
registry=npm install safe-push-apply@1.0.0"safe-push-apply": "1.0.0"About this package
safe-push-apply 
Push an array of items into an array, while being robust against prototype modification.
Getting started
npm install --save safe-push-apply
Usage/Examples
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]);
Tests
Simply clone the repo, npm install, and run npm test
Dependencies
Dependencies
| ID | Version |
|---|---|
| es-errors | ^1.3.0 |
| isarray | ^2.0.5 |
Development Dependencies
| ID | Version |
|---|---|
| @arethetypeswrong/cli | ^0.17.1 |
| @ljharb/eslint-config | ^21.1.1 |
| @ljharb/tsconfig | ^0.2.2 |
| @types/isarray | ^2.0.3 |
| @types/tape | ^5.6.5 |
| auto-changelog | ^2.5.0 |
| encoding | ^0.1.13 |
| eslint | =8.8.0 |
| evalmd | ^0.0.19 |
| in-publish | ^2.0.1 |
| npmignore | ^0.3.1 |
| nyc | ^10.3.2 |
| safe-publish-latest | ^2.0.0 |
| tape | ^5.9.0 |
| typescript | next |
Keywords
array
push
apply
pushApply
safe
