safe-push-apply <sup>Version Badge</sup>

github actions coverage License Downloads

npm badge

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

safe-push-apply - Installation

To install safe-push-apply via this registry, you'll need to install via the --registry parameter with your package manager.

n

NPM

npm install safe-push-apply --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Yarn

yarn config set registry https://js.registry.sudovanilla.org
yarn install safe-push-apply

Learn more about the config option.

PNPM

pnpm install safe-push-apply --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Bun Logo

Bun

bun install safe-push-apply --registry https://js.registry.sudovanilla.org

Learn more about the --registry parameter.

Learn more about setting this up in your bunfig.toml configuration.


For Deno, add the following to your .npmrc file in your directory:

registry="https://js.registry.sudovanilla.org"

Then run the deno install command.

safe-push-apply - Download

Download Tarball (v1.0.0)

Integrity sha512-iKE9w/Z7xCzUMIZqdBsp6pEQvwuEebH4vdpjcDWnyzaI6yl6O9FHvVpmGelvEHNsoY6wGblkxR6Zty/h00WiSA==
SHASUM 01850e981c1602d398c85081f360e4e6d03d27f5
Tarball https://js.registry.sudovanilla.org/safe-push-apply/-/safe-push-apply-1.0.0.tgz