Skip to content

Commit

Permalink
[patch] add types
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 1, 2024
1 parent 07f3eaf commit 9276414
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 36 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/node-10-11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

minors:
needs: [matrix, latest]
Expand All @@ -55,13 +55,13 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

node:
name: 'node v10 - v11'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/node-12-13.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

minors:
needs: [matrix, latest]
Expand All @@ -55,13 +55,13 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

node:
name: 'node v12 - v13'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/node-14-15.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

minors:
needs: [matrix, latest]
Expand All @@ -55,13 +55,13 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

node:
name: 'node v14 - v15'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/node-16+.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

minors:
needs: [matrix, latest]
Expand All @@ -53,13 +53,13 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

node:
name: 'node v16+'
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/node-4-6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

minors:
needs: [matrix, latest]
Expand All @@ -55,13 +56,14 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

node:
name: 'node v4 - v6'
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/node-7-9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

minors:
needs: [matrix, latest]
Expand All @@ -55,13 +56,14 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

node:
name: 'node v7 - v9'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/node-iojs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

minors:
needs: [matrix, latest]
Expand All @@ -56,14 +56,14 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

node:
name: 'io.js'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/node-zero.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }}
skip-ls-check: true
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

unstable:
needs: [matrix, stable]
Expand All @@ -59,15 +59,15 @@ jobs:
- test:shams:getownpropertysymbols

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: ${{ matrix.node-version }}
cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }}
skip-ls-check: true
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3

node:
name: 'node 0.x'
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare function hasToStringTag(): boolean;

export = hasToStringTag;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var hasSymbols = require('has-symbols');

/** @type {import('.')} */
module.exports = function hasToStringTag() {
return hasSymbols() && typeof Symbol.toStringTag === 'symbol';
};
22 changes: 19 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@
"description": "Determine if the JS environment has `Symbol.toStringTag` support. Supports spec, or shams.",
"license": "MIT",
"main": "index.js",
"types": "./index.d.ts",
"exports": {
".": "./index.js",
"./shams": "./shams.js",
".": [
{
"types": "./index.d.ts",
"default": "./index.js"
},
"./index.js"
],
"./shams": [
{
"types": "./shams.d.ts",
"default": "./shams.js"
},
"./shams.js"
],
"./package.json": "./package.json"
},
"scripts": {
Expand Down Expand Up @@ -59,6 +72,8 @@
],
"devDependencies": {
"@ljharb/eslint-config": "^21.1.0",
"@types/has-symbols": "^1.0.2",
"@types/tape": "^5.6.4",
"aud": "^2.0.4",
"auto-changelog": "^2.4.0",
"core-js": "^2.6.12",
Expand All @@ -69,7 +84,8 @@
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.7.4"
"tape": "^5.7.4",
"typescript": "next"
},
"engines": {
"node": ">= 0.4"
Expand Down
3 changes: 3 additions & 0 deletions shams.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare function hasToStringTagShams(): boolean;

export = hasToStringTagShams;
1 change: 1 addition & 0 deletions shams.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var hasSymbols = require('has-symbols/shams');

/** @type {import('.')} */
module.exports = function hasToStringTagShams() {
return hasSymbols() && !!Symbol.toStringTag;
};
3 changes: 3 additions & 0 deletions test/shams/core-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol') {
t.equal(typeof Symbol.toStringTag, 'symbol');
t.end();
});
// @ts-expect-error CJS has top-level return
return;
}

Expand All @@ -16,7 +17,9 @@ var hasSymbolToStringTag = require('../../shams');
test('polyfilled Symbols', function (t) {
/* eslint-disable global-require */
t.equal(hasSymbolToStringTag(), false, 'hasSymbolToStringTag is false before polyfilling');
// @ts-expect-error no types defined
require('core-js/fn/symbol');
// @ts-expect-error no types defined
require('core-js/fn/symbol/to-string-tag');

require('../tests')(t);
Expand Down
2 changes: 2 additions & 0 deletions test/shams/get-own-property-symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (typeof Symbol === 'function' && typeof Symbol() === 'symbol') {
t.equal(typeof Symbol(), 'symbol');
t.end();
});
// @ts-expect-error CJS has top-level return
return;
}

Expand All @@ -17,6 +18,7 @@ test('polyfilled Symbols', function (t) {
/* eslint-disable global-require */
t.equal(hasSymbolToStringTag(), false, 'hasSymbolToStringTag is false before polyfilling');

// @ts-expect-error no types defined
require('get-own-property-symbols');

require('../tests')(t);
Expand Down
3 changes: 2 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

// eslint-disable-next-line consistent-return
module.exports = function runSymbolTests(t) {
module.exports = /** @type {(t: import('tape').Test) => void | false} */ function runSymbolTests(t) {
t.equal(typeof Symbol, 'function', 'global Symbol is a function');
t.ok(Symbol.toStringTag, 'Symbol.toStringTag exists');

if (typeof Symbol !== 'function' || !Symbol.toStringTag) { return false; }

/** @type {{ [Symbol.toStringTag]?: 'test'}} */
var obj = {};
obj[Symbol.toStringTag] = 'test';

Expand Down
Loading

0 comments on commit 9276414

Please sign in to comment.