pax_global_header 0000666 0000000 0000000 00000000064 14734143520 0014515 g ustar 00root root 0000000 0000000 52 comment=ad4e4467f70f7d8da81fd30a36347b35d8c8850c
ljharb-safe-push-apply-0360d00/ 0000775 0000000 0000000 00000000000 14734143520 0016231 5 ustar 00root root 0000000 0000000 ljharb-safe-push-apply-0360d00/.eslintrc 0000664 0000000 0000000 00000000311 14734143520 0020050 0 ustar 00root root 0000000 0000000 {
"root": true,
"extends": "@ljharb",
"rules": {
"id-length": "off",
"max-lines-per-function": "off",
"new-cap": ["error", {
"capIsNewExceptions": [
"GetIntrinsic",
],
}],
},
}
ljharb-safe-push-apply-0360d00/.github/ 0000775 0000000 0000000 00000000000 14734143520 0017571 5 ustar 00root root 0000000 0000000 ljharb-safe-push-apply-0360d00/.github/FUNDING.yml 0000664 0000000 0000000 00000001112 14734143520 0021401 0 ustar 00root root 0000000 0000000 # These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/safe-push-apply
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
ljharb-safe-push-apply-0360d00/.github/workflows/ 0000775 0000000 0000000 00000000000 14734143520 0021626 5 ustar 00root root 0000000 0000000 ljharb-safe-push-apply-0360d00/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000354 14734143520 0024406 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js < 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '< 10'
type: minors
command: npm run tests-only
skip-ls-check: true
ljharb-safe-push-apply-0360d00/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000206 14734143520 0024760 0 ustar 00root root 0000000 0000000 name: 'Tests: pretest/posttest'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/pretest.yml@main
ljharb-safe-push-apply-0360d00/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000372 14734143520 0024247 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js 10 - 20'
on: [pull_request, push]
permissions:
contents: read
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 10 < 20'
type: minors
command: npm run tests-only
ljharb-safe-push-apply-0360d00/.github/workflows/node-twenties.yml 0000664 0000000 0000000 00000000363 14734143520 0025140 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js >= 20'
on: [pull_request, push]
permissions:
contents: read
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 20'
type: minors
command: npm run tests-only
ljharb-safe-push-apply-0360d00/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000257 14734143520 0023616 0 ustar 00root root 0000000 0000000 name: Automatic Rebase
on: [pull_request_target]
jobs:
_:
uses: ljharb/actions/.github/workflows/rebase.yml@main
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
ljharb-safe-push-apply-0360d00/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 14734143520 0026243 0 ustar 00root root 0000000 0000000 name: Require “Allow Edits”
on: [pull_request_target]
jobs:
_:
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- uses: ljharb/require-allow-edits@main
ljharb-safe-push-apply-0360d00/.gitignore 0000664 0000000 0000000 00000004136 14734143520 0020225 0 ustar 00root root 0000000 0000000 # Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
.npmignore
ljharb-safe-push-apply-0360d00/.npmrc 0000664 0000000 0000000 00000000067 14734143520 0017354 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
ljharb-safe-push-apply-0360d00/.nycrc 0000664 0000000 0000000 00000000330 14734143520 0017344 0 ustar 00root root 0000000 0000000 {
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"lines": 86,
"statements": 85.93,
"functions": 82.43,
"branches": 76.06,
"exclude": [
"coverage",
"test"
]
}
ljharb-safe-push-apply-0360d00/CHANGELOG.md 0000664 0000000 0000000 00000001452 14734143520 0020044 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## v1.0.0 - 2024-12-28
### Commits
- Initial implementation, tests, readme, types [`6e85f82`](https://github.com/ljharb/safe-push-apply/commit/6e85f82b116286503ff377e15708cd1584531c5f)
- Initial commit [`93928d9`](https://github.com/ljharb/safe-push-apply/commit/93928d9a1304ccc25b799528a4bbca8615f7614e)
- npm init [`5da39da`](https://github.com/ljharb/safe-push-apply/commit/5da39da33bb096e633d1e631a9374cfa0d7dc06b)
- Only apps should have lockfiles [`83fc8b4`](https://github.com/ljharb/safe-push-apply/commit/83fc8b4be29d680a27225329cc1ef5505626effa)
ljharb-safe-push-apply-0360d00/LICENSE 0000664 0000000 0000000 00000002057 14734143520 0017242 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) 2024 Jordan Harband
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
ljharb-safe-push-apply-0360d00/README.md 0000664 0000000 0000000 00000004044 14734143520 0017512 0 ustar 00root root 0000000 0000000 # safe-push-apply [![Version Badge][npm-version-svg]][package-url]
[![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
ljharb-safe-push-apply-0360d00/index.d.ts 0000664 0000000 0000000 00000000167 14734143520 0020136 0 ustar 00root root 0000000 0000000 declare function safePushApply(
target: T[],
source: ArrayLike,
): void;
export = safePushApply;
ljharb-safe-push-apply-0360d00/index.js 0000664 0000000 0000000 00000000602 14734143520 0017674 0 ustar 00root root 0000000 0000000 'use strict';
var $TypeError = require('es-errors/type');
var isArray = require('isarray');
/** @type {import('.')} */
module.exports = function safePushApply(target, source) {
if (!isArray(target)) {
throw new $TypeError('target must be an array');
}
for (var i = 0; i < source.length; i++) {
target[target.length] = source[i]; // eslint-disable-line no-param-reassign
}
};
ljharb-safe-push-apply-0360d00/package.json 0000664 0000000 0000000 00000004174 14734143520 0020525 0 ustar 00root root 0000000 0000000 {
"name": "safe-push-apply",
"version": "1.0.0",
"description": "Push an array of items into an array, while being robust against prototype modification",
"main": "index.js",
"exports": {
".": "./index.js",
"./package.json": "./package.json"
},
"sideEffects": false,
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"",
"prelint": "evalmd README.md",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc && attw -P",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prepublishOnly": "safe-publish-latest",
"pretest": "npm run lint",
"tests-only": "nyc tape test",
"test": "npm run tests-only",
"posttest": "npx npm@'>= 10.2' audit --production"
},
"keywords": [
"array",
"push",
"apply",
"pushApply",
"safe"
],
"author": "Jordan Harband ",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/ljharb/safe-push-apply.git"
},
"bugs": {
"url": "https://github.com/ljharb/safe-push-apply/issues"
},
"homepage": "https://github.com/ljharb/safe-push-apply#readme",
"dependencies": {
"es-errors": "^1.3.0",
"isarray": "^2.0.5"
},
"devDependencies": {
"@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"
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}
ljharb-safe-push-apply-0360d00/test/ 0000775 0000000 0000000 00000000000 14734143520 0017210 5 ustar 00root root 0000000 0000000 ljharb-safe-push-apply-0360d00/test/index.js 0000664 0000000 0000000 00000001332 14734143520 0020654 0 ustar 00root root 0000000 0000000 'use strict';
var test = require('tape');
var safePushApply = require('../');
test('safe-push-apply', function (t) {
t.equal(typeof safePushApply, 'function', 'is a function');
t.equal(safePushApply.length, 2, 'has a length of 2');
t['throws'](
// @ts-expect-error
function () { safePushApply({}, []); },
TypeError,
'throws if target is not an array'
);
var a = [1, 2];
var b = [3, 4];
safePushApply(a, b);
t.deepEqual(a, [1, 2, 3, 4], 'b is pushed into a');
t.deepEqual(b, [3, 4], 'b is not modified');
var c = '567';
// @ts-expect-error TS ArrayLike doesn't accept strings for some reason
safePushApply(a, c);
t.deepEqual(a, [1, 2, 3, 4, '5', '6', '7'], 'works with arraylike source');
t.end();
});
ljharb-safe-push-apply-0360d00/tsconfig.json 0000664 0000000 0000000 00000000175 14734143520 0020743 0 ustar 00root root 0000000 0000000 {
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "es2021",
},
"exclude": [
"coverage",
],
}