# safe-push-apply

> Push an array of items into an array, while being robust against prototype modification

Latest version **1.0.0** (published 2024-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install safe-push-apply
pnpm add safe-push-apply
yarn add safe-push-apply
bun add safe-push-apply
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-12-29 |
| First published | 2024-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 0.4 |
| Dependencies | 2 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | array, push, apply, pushApply, safe |

## Links

- npm: https://www.npmjs.com/package/safe-push-apply
- Repository: https://github.com/ljharb/safe-push-apply
- Homepage: https://github.com/ljharb/safe-push-apply#readme
- Issues: https://github.com/ljharb/safe-push-apply/issues
- Funding: https://github.com/sponsors/ljharb
- npm.io page: https://npm.io/package/safe-push-apply

## Dependencies (2)

- [isarray](https://npm.io/package/isarray.md) ^2.0.5
- [es-errors](https://npm.io/package/es-errors.md) ^1.3.0

## Recent versions

- 1.0.0 (latest) — 2024-12-29

## README

# safe-push-apply <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

Push an array of items into an array, while being robust against prototype modification.

## Getting started

```sh
npm install --save safe-push-apply
```

## Usage/Examples

```js
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`

[package-url]: https://npmjs.org/package/safe-push-apply
[npm-version-svg]: https://versionbadg.es/ljharb/safe-push-apply.svg
[deps-svg]: https://david-dm.org/ljharb/safe-push-apply.svg
[deps-url]: https://david-dm.org/ljharb/safe-push-apply
[dev-deps-svg]: https://david-dm.org/ljharb/safe-push-apply/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/safe-push-apply#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/safe-push-apply.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/safe-push-apply.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/safe-push-apply.svg
[downloads-url]: https://npm-stat.com/charts.html?package=safe-push-apply
[codecov-image]: https://codecov.io/gh/ljharb/safe-push-apply/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/ljharb/safe-push-apply/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/safe-push-apply
[actions-url]: https://github.com/ljharb/safe-push-apply/actions

---
_Source: https://npm.io/package/safe-push-apply · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
