pax_global_header00006660000000000000000000000064147354146270014527gustar00rootroot0000000000000052 comment=90e506fbfe24630e6fe3871639000d2f0ba09d6f es-shims-es-set-tostringtag-79227f9/000077500000000000000000000000001473541462700173135ustar00rootroot00000000000000es-shims-es-set-tostringtag-79227f9/.eslintrc000066400000000000000000000002121473541462700211320ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "new-cap": [2, { "capIsNewExceptions": [ "GetIntrinsic", ], }], }, } es-shims-es-set-tostringtag-79227f9/.github/000077500000000000000000000000001473541462700206535ustar00rootroot00000000000000es-shims-es-set-tostringtag-79227f9/.github/workflows/000077500000000000000000000000001473541462700227105ustar00rootroot00000000000000es-shims-es-set-tostringtag-79227f9/.github/workflows/node-aught.yml000066400000000000000000000005331473541462700254670ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] permissions: contents: read 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: true es-shims-es-set-tostringtag-79227f9/.github/workflows/node-pretest.yml000066400000000000000000000002451473541462700260450ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main es-shims-es-set-tostringtag-79227f9/.github/workflows/node-tens.yml000066400000000000000000000005471473541462700253350ustar00rootroot00000000000000name: '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 node: name: 'node 10 - 20' needs: [tests] runs-on: ubuntu-latest steps: - run: true es-shims-es-set-tostringtag-79227f9/.github/workflows/node-twenties.yml000066400000000000000000000005361473541462700262240ustar00rootroot00000000000000name: '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 node: name: 'node >= 20' needs: [tests] runs-on: ubuntu-latest steps: - run: true es-shims-es-set-tostringtag-79227f9/.github/workflows/rebase.yml000066400000000000000000000002571473541462700247000ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] jobs: _: uses: ljharb/actions/.github/workflows/rebase.yml@main secrets: token: ${{ secrets.GITHUB_TOKEN }} es-shims-es-set-tostringtag-79227f9/.github/workflows/require-allow-edits.yml000066400000000000000000000005151473541462700273320ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] permissions: contents: read jobs: _: permissions: pull-requests: read # for ljharb/require-allow-edits to check 'allow edits' on PR name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main es-shims-es-set-tostringtag-79227f9/.gitignore000066400000000000000000000032501473541462700213030ustar00rootroot00000000000000# 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 .npmignorees-shims-es-set-tostringtag-79227f9/.npmrc000066400000000000000000000000671473541462700204360ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s es-shims-es-set-tostringtag-79227f9/.nycrc000066400000000000000000000002131473541462700204260ustar00rootroot00000000000000{ "all": true, "check-coverage": false, "reporter": ["text-summary", "text", "html", "json"], "exclude": [ "coverage", "test" ] } es-shims-es-set-tostringtag-79227f9/CHANGELOG.md000066400000000000000000000115501473541462700211260ustar00rootroot00000000000000# 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). ## [v2.1.0](https://github.com/es-shims/es-set-tostringtag/compare/v2.0.3...v2.1.0) - 2025-01-01 ### Commits - [actions] split out node 10-20, and 20+ [`ede033c`](https://github.com/es-shims/es-set-tostringtag/commit/ede033cc4e506c3966d2d482d4ac5987e329162a) - [types] use shared config [`28ef164`](https://github.com/es-shims/es-set-tostringtag/commit/28ef164ad7c5bc21837c79f7ef25542a1f258ade) - [New] add `nonConfigurable` option [`3bee3f0`](https://github.com/es-shims/es-set-tostringtag/commit/3bee3f04caddd318f3932912212ed20b2d62aad7) - [Fix] validate boolean option argument [`3c8a609`](https://github.com/es-shims/es-set-tostringtag/commit/3c8a609c795a305ccca163f0ff6956caa88cdc0e) - [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `@ljharb/tsconfig`, `@types/get-intrinsic`, `@types/tape`, `auto-changelog`, `tape` [`501a969`](https://github.com/es-shims/es-set-tostringtag/commit/501a96998484226e07f5ffd447e8f305a998f1d8) - [Tests] add coverage [`18af289`](https://github.com/es-shims/es-set-tostringtag/commit/18af2897b4e937373c9b8c8831bc338932246470) - [readme] document `force` option [`bd446a1`](https://github.com/es-shims/es-set-tostringtag/commit/bd446a107b71a2270278442e5124f45590d3ee64) - [Tests] use `@arethetypeswrong/cli` [`7c2c2fa`](https://github.com/es-shims/es-set-tostringtag/commit/7c2c2fa3cca0f4d263603adb75426b239514598f) - [Tests] replace `aud` with `npm audit` [`9e372d7`](https://github.com/es-shims/es-set-tostringtag/commit/9e372d7e6db3dab405599a14d9074a99a03b8242) - [Deps] update `get-intrinsic` [`7df1216`](https://github.com/es-shims/es-set-tostringtag/commit/7df12167295385c2a547410e687cb0c04f3a34b9) - [Deps] update `hasown` [`993a7d2`](https://github.com/es-shims/es-set-tostringtag/commit/993a7d200e2059fd857ec1a25d0a49c2c34ae6e2) - [Dev Deps] add missing peer dep [`148ed8d`](https://github.com/es-shims/es-set-tostringtag/commit/148ed8db99a7a94f9af3823fd083e6e437fa1587) ## [v2.0.3](https://github.com/es-shims/es-set-tostringtag/compare/v2.0.2...v2.0.3) - 2024-02-20 ### Commits - add types [`d538513`](https://github.com/es-shims/es-set-tostringtag/commit/d5385133592a32a0a416cb535327918af7fbc4ad) - [Deps] update `get-intrinsic`, `has-tostringtag`, `hasown` [`d129b29`](https://github.com/es-shims/es-set-tostringtag/commit/d129b29536bccc8a9d03a47887ca4d1f7ad0c5b9) - [Dev Deps] update `aud`, `npmignore`, `tape` [`132ed23`](https://github.com/es-shims/es-set-tostringtag/commit/132ed23c964a41ed55e4ab4a5a2c3fe185e821c1) - [Tests] fix hasOwn require [`f89c831`](https://github.com/es-shims/es-set-tostringtag/commit/f89c831fe5f3edf1f979c597b56fee1be6111f56) ## [v2.0.2](https://github.com/es-shims/es-set-tostringtag/compare/v2.0.1...v2.0.2) - 2023-10-20 ### Commits - [Refactor] use `hasown` instead of `has` [`0cc6c4e`](https://github.com/es-shims/es-set-tostringtag/commit/0cc6c4e61fd13e8f00b85424ae6e541ebf289e74) - [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`70e447c`](https://github.com/es-shims/es-set-tostringtag/commit/70e447cf9f82b896ddf359fda0a0498c16cf3ed2) - [Deps] update `get-intrinsic` [`826aab7`](https://github.com/es-shims/es-set-tostringtag/commit/826aab76180392871c8efa99acc0f0bbf775c64e) ## [v2.0.1](https://github.com/es-shims/es-set-tostringtag/compare/v2.0.0...v2.0.1) - 2023-01-05 ### Fixed - [Fix] move `has` to prod deps [`#2`](https://github.com/es-shims/es-set-tostringtag/issues/2) ### Commits - [Dev Deps] update `@ljharb/eslint-config` [`b9eecd2`](https://github.com/es-shims/es-set-tostringtag/commit/b9eecd23c10b7b43ba75089ac8ff8cc6b295798b) ## [v2.0.0](https://github.com/es-shims/es-set-tostringtag/compare/v1.0.0...v2.0.0) - 2022-12-21 ### Commits - [Tests] refactor tests [`168dcfb`](https://github.com/es-shims/es-set-tostringtag/commit/168dcfbb535c279dc48ccdc89419155125aaec18) - [Breaking] do not set toStringTag if it is already set [`226ab87`](https://github.com/es-shims/es-set-tostringtag/commit/226ab874192c625d9e5f0e599d3f60d2b2aa83b5) - [New] add `force` option to set even if already set [`1abd4ec`](https://github.com/es-shims/es-set-tostringtag/commit/1abd4ecb282f19718c4518284b0293a343564505) ## v1.0.0 - 2022-12-21 ### Commits - Initial implementation, tests, readme [`a0e1147`](https://github.com/es-shims/es-set-tostringtag/commit/a0e11473f79a233b46374525c962ea1b4d42418a) - Initial commit [`ffd4aff`](https://github.com/es-shims/es-set-tostringtag/commit/ffd4afffbeebf29aff0d87a7cfc3f7844e09fe68) - npm init [`fffe5bd`](https://github.com/es-shims/es-set-tostringtag/commit/fffe5bd1d1146d084730a387a9c672371f4a8fff) - Only apps should have lockfiles [`d363871`](https://github.com/es-shims/es-set-tostringtag/commit/d36387139465623e161a15dbd39120537f150c62) es-shims-es-set-tostringtag-79227f9/LICENSE000066400000000000000000000020611473541462700203170ustar00rootroot00000000000000MIT License Copyright (c) 2022 ECMAScript Shims 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. es-shims-es-set-tostringtag-79227f9/README.md000066400000000000000000000042711473541462700205760ustar00rootroot00000000000000# es-set-tostringtag [![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] A helper to optimistically set Symbol.toStringTag, when possible. ## Example Most common usage: ```js var assert = require('assert'); var setToStringTag = require('es-set-tostringtag'); var obj = {}; assert.equal(Object.prototype.toString.call(obj), '[object Object]'); setToStringTag(obj, 'tagged!'); assert.equal(Object.prototype.toString.call(obj), '[object tagged!]'); ``` ## Options An optional options argument can be provided as the third argument. The available options are: ### `force` If the `force` option is set to `true`, the toStringTag will be set even if it is already set. ### `nonConfigurable` If the `nonConfigurable` option is set to `true`, the toStringTag will be defined as non-configurable when possible. ## Tests Simply clone the repo, `npm install`, and run `npm test` [package-url]: https://npmjs.com/package/es-set-tostringtag [npm-version-svg]: https://versionbadg.es/es-shims/es-set-tostringtag.svg [deps-svg]: https://david-dm.org/es-shims/es-set-tostringtag.svg [deps-url]: https://david-dm.org/es-shims/es-set-tostringtag [dev-deps-svg]: https://david-dm.org/es-shims/es-set-tostringtag/dev-status.svg [dev-deps-url]: https://david-dm.org/es-shims/es-set-tostringtag#info=devDependencies [npm-badge-png]: https://nodei.co/npm/es-set-tostringtag.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/es-set-tostringtag.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/es-set-tostringtag.svg [downloads-url]: https://npm-stat.com/charts.html?package=es-set-tostringtag [codecov-image]: https://codecov.io/gh/es-shims/es-set-tostringtag/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/es-shims/es-set-tostringtag/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/es-set-tostringtag [actions-url]: https://github.com/es-shims/es-set-tostringtag/actions es-shims-es-set-tostringtag-79227f9/index.d.ts000066400000000000000000000003541473541462700212160ustar00rootroot00000000000000declare function setToStringTag( object: object & { [Symbol.toStringTag]?: unknown }, value: string | unknown, options?: { force?: boolean; nonConfigurable?: boolean; }, ): void; export = setToStringTag;es-shims-es-set-tostringtag-79227f9/index.js000066400000000000000000000022751473541462700207660ustar00rootroot00000000000000'use strict'; var GetIntrinsic = require('get-intrinsic'); var $defineProperty = GetIntrinsic('%Object.defineProperty%', true); var hasToStringTag = require('has-tostringtag/shams')(); var hasOwn = require('hasown'); var $TypeError = require('es-errors/type'); var toStringTag = hasToStringTag ? Symbol.toStringTag : null; /** @type {import('.')} */ module.exports = function setToStringTag(object, value) { var overrideIfSet = arguments.length > 2 && !!arguments[2] && arguments[2].force; var nonConfigurable = arguments.length > 2 && !!arguments[2] && arguments[2].nonConfigurable; if ( (typeof overrideIfSet !== 'undefined' && typeof overrideIfSet !== 'boolean') || (typeof nonConfigurable !== 'undefined' && typeof nonConfigurable !== 'boolean') ) { throw new $TypeError('if provided, the `overrideIfSet` and `nonConfigurable` options must be booleans'); } if (toStringTag && (overrideIfSet || !hasOwn(object, toStringTag))) { if ($defineProperty) { $defineProperty(object, toStringTag, { configurable: !nonConfigurable, enumerable: false, value: value, writable: false }); } else { object[toStringTag] = value; // eslint-disable-line no-param-reassign } } }; es-shims-es-set-tostringtag-79227f9/package.json000066400000000000000000000042211473541462700216000ustar00rootroot00000000000000{ "name": "es-set-tostringtag", "version": "2.1.0", "description": "A helper to optimistically set Symbol.toStringTag, when possible.", "main": "index.js", "exports": { ".": "./index.js", "./package.json": "./package.json" }, "sideEffects": false, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublishOnly": "safe-publish-latest", "prepublish": "not-in-publish || npm run prepublishOnly", "prelint": "evalmd README.md", "lint": "eslint --ext=js,mjs .", "postlint": "tsc -p . && 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/es-shims/es-set-tostringtag.git" }, "author": "Jordan Harband ", "license": "MIT", "bugs": { "url": "https://github.com/es-shims/es-set-tostringtag/issues" }, "homepage": "https://github.com/es-shims/es-set-tostringtag#readme", "devDependencies": { "@arethetypeswrong/cli": "^0.17.2", "@ljharb/eslint-config": "^21.1.1", "@ljharb/tsconfig": "^0.2.3", "@types/get-intrinsic": "^1.2.3", "@types/has-symbols": "^1.0.2", "@types/tape": "^5.8.0", "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" }, "dependencies": { "es-errors": "^1.3.0", "get-intrinsic": "^1.2.6", "has-tostringtag": "^1.0.2", "hasown": "^2.0.2" }, "engines": { "node": ">= 0.4" }, "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "testling": { "files": "./test/index.js" }, "publishConfig": { "ignore": [ ".github/workflows" ] } } es-shims-es-set-tostringtag-79227f9/test/000077500000000000000000000000001473541462700202725ustar00rootroot00000000000000es-shims-es-set-tostringtag-79227f9/test/index.js000066400000000000000000000042731473541462700217450ustar00rootroot00000000000000'use strict'; var test = require('tape'); var hasToStringTag = require('has-tostringtag/shams')(); var hasOwn = require('hasown'); var setToStringTag = require('../'); test('setToStringTag', function (t) { t.equal(typeof setToStringTag, 'function', 'is a function'); /** @type {{ [Symbol.toStringTag]?: typeof sentinel }} */ var obj = {}; var sentinel = {}; setToStringTag(obj, sentinel); t['throws']( // @ts-expect-error function () { setToStringTag(obj, sentinel, { force: 'yes' }); }, TypeError, 'throws if options is not an object' ); t.test('has Symbol.toStringTag', { skip: !hasToStringTag }, function (st) { st.ok(hasOwn(obj, Symbol.toStringTag), 'has toStringTag property'); st.equal(obj[Symbol.toStringTag], sentinel, 'toStringTag property is as expected'); st.equal(String(obj), '[object Object]', 'toStringTag works'); /** @type {{ [Symbol.toStringTag]?: string }} */ var tagged = {}; tagged[Symbol.toStringTag] = 'already tagged'; st.equal(String(tagged), '[object already tagged]', 'toStringTag works'); setToStringTag(tagged, 'new tag'); st.equal(String(tagged), '[object already tagged]', 'toStringTag is unchanged'); setToStringTag(tagged, 'new tag', { force: true }); st.equal(String(tagged), '[object new tag]', 'toStringTag is changed with force: true'); st.deepEqual( Object.getOwnPropertyDescriptor(tagged, Symbol.toStringTag), { configurable: true, enumerable: false, value: 'new tag', writable: false }, 'has expected property descriptor' ); setToStringTag(tagged, 'new tag', { force: true, nonConfigurable: true }); st.deepEqual( Object.getOwnPropertyDescriptor(tagged, Symbol.toStringTag), { configurable: false, enumerable: false, value: 'new tag', writable: false }, 'is nonconfigurable' ); st.end(); }); t.test('does not have Symbol.toStringTag', { skip: hasToStringTag }, function (st) { var passed = true; for (var key in obj) { // eslint-disable-line no-restricted-syntax if (hasOwn(obj, key)) { st.fail('object has own key ' + key); passed = false; } } if (passed) { st.ok(true, 'object has no enumerable own keys'); } st.end(); }); t.end(); }); es-shims-es-set-tostringtag-79227f9/tsconfig.json000066400000000000000000000001641473541462700220230ustar00rootroot00000000000000{ "extends": "@ljharb/tsconfig", "compilerOptions": { "target": "es2021", }, "exclude": [ "coverage", ], }