pax_global_header00006660000000000000000000000064147341435200014515gustar00rootroot0000000000000052 comment=ad4e4467f70f7d8da81fd30a36347b35d8c8850c ljharb-safe-push-apply-0360d00/000077500000000000000000000000001473414352000162315ustar00rootroot00000000000000ljharb-safe-push-apply-0360d00/.eslintrc000066400000000000000000000003111473414352000200500ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "id-length": "off", "max-lines-per-function": "off", "new-cap": ["error", { "capIsNewExceptions": [ "GetIntrinsic", ], }], }, } ljharb-safe-push-apply-0360d00/.github/000077500000000000000000000000001473414352000175715ustar00rootroot00000000000000ljharb-safe-push-apply-0360d00/.github/FUNDING.yml000066400000000000000000000011121473414352000214010ustar00rootroot00000000000000# 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/000077500000000000000000000000001473414352000216265ustar00rootroot00000000000000ljharb-safe-push-apply-0360d00/.github/workflows/node-aught.yml000066400000000000000000000003541473414352000244060ustar00rootroot00000000000000name: '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.yml000066400000000000000000000002061473414352000247600ustar00rootroot00000000000000name: '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.yml000066400000000000000000000003721473414352000242470ustar00rootroot00000000000000name: '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.yml000066400000000000000000000003631473414352000251400ustar00rootroot00000000000000name: '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.yml000066400000000000000000000002571473414352000236160ustar00rootroot00000000000000name: 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.yml000066400000000000000000000003031473414352000262430ustar00rootroot00000000000000name: 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/.gitignore000066400000000000000000000041361473414352000202250ustar00rootroot00000000000000# 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/.npmrc000066400000000000000000000000671473414352000173540ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s ljharb-safe-push-apply-0360d00/.nycrc000066400000000000000000000003301473414352000173440ustar00rootroot00000000000000{ "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.md000066400000000000000000000014521473414352000200440ustar00rootroot00000000000000# 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/LICENSE000066400000000000000000000020571473414352000172420ustar00rootroot00000000000000MIT 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.md000066400000000000000000000040441473414352000175120ustar00rootroot00000000000000# 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.ts000066400000000000000000000001671473414352000201360ustar00rootroot00000000000000declare function safePushApply( target: T[], source: ArrayLike, ): void; export = safePushApply; ljharb-safe-push-apply-0360d00/index.js000066400000000000000000000006021473414352000176740ustar00rootroot00000000000000'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.json000066400000000000000000000041741473414352000205250ustar00rootroot00000000000000{ "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/000077500000000000000000000000001473414352000172105ustar00rootroot00000000000000ljharb-safe-push-apply-0360d00/test/index.js000066400000000000000000000013321473414352000206540ustar00rootroot00000000000000'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.json000066400000000000000000000001751473414352000207430ustar00rootroot00000000000000{ "extends": "@ljharb/tsconfig", "compilerOptions": { "target": "es2021", }, "exclude": [ "coverage", ], }