pax_global_header00006660000000000000000000000064147530174470014526gustar00rootroot0000000000000052 comment=6d2fbe1c017a4e6f31c8d856675f4fea06cd26e0 ljharb-es-shim-unscopables-5bfdfc0/000077500000000000000000000000001475301744700174225ustar00rootroot00000000000000ljharb-es-shim-unscopables-5bfdfc0/.eslintrc000066400000000000000000000011111475301744700212400ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "env": { "es6": true, "es2017": true, "es2020": true, "es2021": true, "es2022": true, }, "rules": { "array-bracket-newline": 0, "complexity": 0, "eqeqeq": [2, "allow-null"], "func-name-matching": 0, "id-length": 0, "max-lines-per-function": [2, 80], "max-params": [2, 4], "max-statements": 0, "max-statements-per-line": [2, { "max": 2 }], "multiline-comment-style": 0, "no-magic-numbers": 0, "sort-keys": 0, }, "overrides": [ { "files": "test/**", "rules": { "new-cap": 0, }, }, ], } ljharb-es-shim-unscopables-5bfdfc0/.github/000077500000000000000000000000001475301744700207625ustar00rootroot00000000000000ljharb-es-shim-unscopables-5bfdfc0/.github/FUNDING.yml000066400000000000000000000011161475301744700225760ustar00rootroot00000000000000# 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/es-shim-unscopables 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-es-shim-unscopables-5bfdfc0/.github/workflows/000077500000000000000000000000001475301744700230175ustar00rootroot00000000000000ljharb-es-shim-unscopables-5bfdfc0/.github/workflows/node-aught.yml000066400000000000000000000005161475301744700255770ustar00rootroot00000000000000name: '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 node: name: 'node < 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' ljharb-es-shim-unscopables-5bfdfc0/.github/workflows/node-pretest.yml000066400000000000000000000002061475301744700261510ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main ljharb-es-shim-unscopables-5bfdfc0/.github/workflows/node-tens.yml000066400000000000000000000005211475301744700254340ustar00rootroot00000000000000name: '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 node: name: 'node >= 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' ljharb-es-shim-unscopables-5bfdfc0/.github/workflows/rebase.yml000066400000000000000000000007001475301744700250000ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] permissions: contents: read jobs: _: permissions: contents: write # for ljharb/rebase to push code to rebase pull-requests: read # for ljharb/rebase to get info about PR name: "Automatic Rebase" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: ljharb/rebase@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ljharb-es-shim-unscopables-5bfdfc0/.github/workflows/require-allow-edits.yml000066400000000000000000000003031475301744700274340ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main ljharb-es-shim-unscopables-5bfdfc0/.gitignore000066400000000000000000000032511475301744700214130ustar00rootroot00000000000000# Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* lerna-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/ # TypeScript v1 declaration files typings/ # TypeScript cache *.tsbuildinfo # Optional npm cache directory .npm # Optional eslint cache .eslintcache # 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 variables file .env .env.test # parcel-bundler cache (https://parceljs.org/) .cache # Next.js build output .next # 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 # Serverless directories .serverless/ # FuseBox cache .fusebox/ # DynamoDB Local files .dynamodb/ # TernJS port file .tern-port # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .npmignore ljharb-es-shim-unscopables-5bfdfc0/.npmrc000066400000000000000000000000671475301744700205450ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s ljharb-es-shim-unscopables-5bfdfc0/.nycrc000066400000000000000000000002131475301744700205350ustar00rootroot00000000000000{ "all": true, "check-coverage": false, "reporter": ["text-summary", "text", "html", "json"], "exclude": [ "coverage", "test" ] } ljharb-es-shim-unscopables-5bfdfc0/CHANGELOG.md000066400000000000000000000040041475301744700212310ustar00rootroot00000000000000### Changelog All notable changes to this project will be documented in this file. Dates are displayed in UTC. Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### [v1.1.0](https://github.com/ljharb/es-shim-unscopables/compare/v1.0.2...v1.1.0) > 11 February 2025 - [New] add types [`2b94d6d`](https://github.com/ljharb/es-shim-unscopables/commit/2b94d6da58c272944de33f7e5b601a56dbb025fe) - [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `es-value-fixtures`, `for-each`, `npmignore`, `object-inspect`, `tape` [`bc42bcf`](https://github.com/ljharb/es-shim-unscopables/commit/bc42bcf1901ad9c3e6427c8f39d1ac22e7e98310) - [meta] add missing `engines.node` [`9ffcc49`](https://github.com/ljharb/es-shim-unscopables/commit/9ffcc491132ae0f7681694630910e1c4eb2cd548) #### [v1.0.2](https://github.com/ljharb/es-shim-unscopables/compare/v1.0.1...v1.0.2) > 20 October 2023 - [Deps] remove unused `has` [`f9fc3ba`](https://github.com/ljharb/es-shim-unscopables/commit/f9fc3bad9a291450ef1d1470347d0faffc937e14) #### [v1.0.1](https://github.com/ljharb/es-shim-unscopables/compare/v1.0.0...v1.0.1) > 20 October 2023 - [meta] use `npmignore` to autogenerate an npmignore file [`4f29eb9`](https://github.com/ljharb/es-shim-unscopables/commit/4f29eb9cfa28cbc08519446027accf8f7e3c472e) - [Refactor] use `hasown` instead of `has` [`9d2577b`](https://github.com/ljharb/es-shim-unscopables/commit/9d2577b8bf6354d68111a8c20f020303370ef85f) - [actions] update checkout action [`4525257`](https://github.com/ljharb/es-shim-unscopables/commit/45252572bf21dc5aab948c99ae0397e90f357718) #### v1.0.0 > 11 April 2022 - Initial implementation, tests [`0313267`](https://github.com/ljharb/es-shim-unscopables/commit/03132672560a06df8a36685c1688793d445ea034) - Initial commit [`5a68e27`](https://github.com/ljharb/es-shim-unscopables/commit/5a68e27e8f11d8b453c00e9239b35ec8795c850e) - [meta] do not publish workflow files [`4e29785`](https://github.com/ljharb/es-shim-unscopables/commit/4e2978541c25ce590589d5f23f311af6ca3618a7) ljharb-es-shim-unscopables-5bfdfc0/LICENSE000066400000000000000000000020571475301744700204330ustar00rootroot00000000000000MIT License Copyright (c) 2022 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-es-shim-unscopables-5bfdfc0/README.md000066400000000000000000000043121475301744700207010ustar00rootroot00000000000000# es-shim-unscopables [![Version Badge][npm-version-svg]][package-url] [![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![dependency status][deps-svg]][deps-url] [![dev dependency status][dev-deps-svg]][dev-deps-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][npm-badge-png]][package-url] Helper package to shim a method into `Array.prototype[Symbol.unscopables]` ## Example ```js const assert = require('assert'); const shimUnscopables = require('es-shim-unscopables'); let copyWithin; let concat; with ([]) { assert.equal(concat, Array.prototype.concat); assert.notEqual(copyWithin, Array.prototype.copyWithin); } shimUnscopables('concat'); with ([]) { assert.notEqual(concat, Array.prototype.concat); assert.notEqual(copyWithin, Array.prototype.copyWithin); } ``` ## Tests Simply clone the repo, `npm install`, and run `npm test` ## Security Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report. [package-url]: https://npmjs.org/package/es-shim-unscopables [npm-version-svg]: https://versionbadg.es/ljharb/es-shim-unscopables.svg [deps-svg]: https://david-dm.org/ljharb/es-shim-unscopables.svg [deps-url]: https://david-dm.org/ljharb/es-shim-unscopables [dev-deps-svg]: https://david-dm.org/ljharb/es-shim-unscopables/dev-status.svg [dev-deps-url]: https://david-dm.org/ljharb/es-shim-unscopables#info=devDependencies [npm-badge-png]: https://nodei.co/npm/es-shim-unscopables.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/es-shim-unscopables.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/es-shim-unscopables.svg [downloads-url]: https://npm-stat.com/charts.html?package=es-shim-unscopables [codecov-image]: https://codecov.io/gh/ljharb/es-shim-unscopables/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/ljharb/es-shim-unscopables/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/es-shim-unscopables [actions-url]: https://github.com/ljharb/es-shim-unscopables/actions ljharb-es-shim-unscopables-5bfdfc0/index.d.ts000066400000000000000000000004051475301744700213220ustar00rootroot00000000000000type Unscopableable = string & { [K in keyof typeof Array.prototype]: typeof Array.prototype[K] extends Function ? K : never }[keyof typeof Array.prototype]; declare function shimUnscopables(method: Unscopableable): void; export = shimUnscopables;ljharb-es-shim-unscopables-5bfdfc0/index.js000066400000000000000000000011151475301744700210650ustar00rootroot00000000000000'use strict'; var hasOwn = require('hasown'); var hasUnscopables = typeof Symbol === 'function' && typeof Symbol.unscopables === 'symbol'; var map = hasUnscopables && Array.prototype[Symbol.unscopables]; var $TypeError = TypeError; /** @type {import('.')} */ module.exports = function shimUnscopables(method) { if (typeof method !== 'string' || !method) { throw new $TypeError('method must be a non-empty string'); } if (!hasOwn(Array.prototype, method)) { throw new $TypeError('method must be on Array.prototype'); } if (hasUnscopables && map) { map[method] = true; } }; ljharb-es-shim-unscopables-5bfdfc0/package.json000066400000000000000000000036261475301744700217170ustar00rootroot00000000000000{ "name": "es-shim-unscopables", "version": "1.1.0", "description": "Helper package to shim a method into `Array.prototype[Symbol.unscopables]`", "main": "index.js", "exports": { ".": "./index.js", "./package.json": "./package.json" }, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublish": "not-in-publish || npm run prepublishOnly", "prepublishOnly": "safe-publish-latest", "prelint-disabled": "evalmd README.md", "lint": "eslint --ext=.js,.mjs .", "postlint": "tsc && attw -P", "pretest": "npm run lint", "tests-only": "nyc tape 'test/**/*.js'", "test": "npm run tests-only", "posttest": "npx npm@\">= 10.2\" audit --production", "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)\")\"" }, "repository": { "type": "git", "url": "git+https://github.com/ljharb/es-shim-unscopables.git" }, "author": "Jordan Harband ", "license": "MIT", "bugs": { "url": "https://github.com/ljharb/es-shim-unscopables/issues" }, "homepage": "https://github.com/ljharb/es-shim-unscopables#readme", "devDependencies": { "@arethetypeswrong/cli": "^0.17.3", "@ljharb/eslint-config": "^21.1.1", "@ljharb/tsconfig": "^0.2.3", "@types/object-inspect": "^1.13.0", "@types/tape": "^5.8.1", "auto-changelog": "^2.5.0", "encoding": "^0.1.13", "es-value-fixtures": "^1.7.1", "eslint": "=8.8.0", "evalmd": "^0.0.19", "for-each": "^0.3.5", "in-publish": "^2.0.1", "npmignore": "^0.3.1", "nyc": "^10.3.2", "object-inspect": "^1.13.4", "safe-publish-latest": "^2.0.0", "tape": "^5.9.0", "typescript": "^5.8.0-dev.20250211" }, "dependencies": { "hasown": "^2.0.2" }, "publishConfig": { "ignore": [ ".github/workflows" ] }, "engines": { "node": ">= 0.4" } } ljharb-es-shim-unscopables-5bfdfc0/test/000077500000000000000000000000001475301744700204015ustar00rootroot00000000000000ljharb-es-shim-unscopables-5bfdfc0/test/index.js000066400000000000000000000036511475301744700220530ustar00rootroot00000000000000'use strict'; var test = require('tape'); var inspect = require('object-inspect'); var v = require('es-value-fixtures'); var forEach = require('for-each'); var hasOwn = require('hasown'); var shimUnscopables = require('../'); /** @type {(a: symbol, b: symbol) => number} */ var sortSymbols = function (a, b) { return inspect(a).localeCompare(inspect(b)); }; test('shimUnscopables', function (t) { t.equal(typeof shimUnscopables, 'function', 'is a function'); forEach(v.nonStrings, function (notNonEmptyString) { t['throws']( // @ts-expect-error function () { shimUnscopables(notNonEmptyString); }, TypeError, inspect(notNonEmptyString) + ' is not a non-empty String' ); }); t['throws']( // @ts-expect-error function () { shimUnscopables('x'); }, TypeError, inspect('x') + ' is not on Array.prototype' ); t.test('no symbols', { skip: typeof Symbol === 'function' }, function (st) { st.doesNotThrow(function () { shimUnscopables('forEach'); }); st.end(); }); t.test('symbols, no unscopables', { skip: typeof Symbol !== 'function' || !!Symbol.unscopables }, function (st) { st.deepEqual(Object.getOwnPropertySymbols(Array.prototype), [Symbol.iterator]); shimUnscopables('forEach'); st.deepEqual(Object.getOwnPropertySymbols(Array.prototype), [Symbol.iterator]); st.end(); }); t.test('Symbol.unscopables', { skip: typeof Symbol !== 'function' || !Symbol.unscopables }, function (st) { st.deepEqual( Object.getOwnPropertySymbols(Array.prototype).sort(sortSymbols), [Symbol.iterator, Symbol.unscopables] ); st.notOk(hasOwn(Array.prototype[Symbol.unscopables], 'forEach'), 'unscopables map lacks forEach'); shimUnscopables('forEach'); st.deepEqual( Object.getOwnPropertySymbols(Array.prototype).sort(sortSymbols), [Symbol.iterator, Symbol.unscopables] ); st.equal(Array.prototype[Symbol.unscopables].forEach, true, 'unscopables map has forEach'); st.end(); }); t.end(); }); ljharb-es-shim-unscopables-5bfdfc0/test/with.js000066400000000000000000000024541475301744700217170ustar00rootroot00000000000000/* eslint no-restricted-syntax: 0, no-with: 0, strict: 0 */ var test = require('tape'); var shimUnscopables = require('../'); test('`with` statement', { skip: typeof Symbol !== 'function' || !Symbol.unscopables }, function (t) { // @ts-expect-error this variable is declared in case unscopables doesn't work var entries; // @ts-expect-error this variable is declared in case unscopables doesn't work var concat; // @ts-expect-error `with` unsupported with ([]) { t.equal(concat, Array.prototype.concat, 'concat is dynamically bound'); t.notEqual(entries, Array.prototype.entries, 'entries is not dynamically bound'); } /** @type {Record} */ var obj = { foo: 1, bar: 2 }; // @ts-expect-error this variable is declared in case unscopables doesn't work var foo; // @ts-expect-error this variable is declared in case unscopables doesn't work var bar; obj[Symbol.unscopables] = { foo: true }; // @ts-expect-error `with` unsupported with (obj) { t.equal(foo, undefined); t.equal(bar, obj.bar); } shimUnscopables('concat'); // @ts-expect-error `with` unsupported with ([]) { t.notEqual(concat, Array.prototype.concat, 'concat is no longer dynamically bound'); t.notEqual(entries, Array.prototype.entries, 'entries is still not dynamically bound'); } t.end(); }); ljharb-es-shim-unscopables-5bfdfc0/tsconfig.json000066400000000000000000000002121475301744700221240ustar00rootroot00000000000000{ "extends": "@ljharb/tsconfig", "compilerOptions": { "target": "es2021", }, "exclude": [ "coverage", "test/list-exports" ], }