Skip to content

Commit

Permalink
[Fix] do not use Object.prototype.toString when `Symbol.toStringTag…
Browse files Browse the repository at this point in the history
…` is shammed
  • Loading branch information
ljharb committed May 8, 2021
1 parent b25aea2 commit 83337eb
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 12 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/node-iojs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
- uses: ljharb/actions/node/matrix@main
id: set-matrix
with:
versionsAsRoot: true
preset: 'iojs'

latest:
Expand All @@ -21,7 +22,11 @@ jobs:

strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.latest) }}
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
command:
- 'tests-only'
- 'test:corejs'

steps:
- uses: actions/checkout@v2
Expand All @@ -30,7 +35,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
- run: npm run tests-only
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v1

minors:
Expand All @@ -42,7 +47,11 @@ jobs:

strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.minors) }}
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.minors) }}
command:
- 'tests-only'
- 'test:corejs'

steps:
- uses: actions/checkout@v2
Expand All @@ -51,7 +60,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
- run: npm run tests-only
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v1

node:
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/node-zero.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
- uses: ljharb/actions/node/matrix@main
id: set-matrix
with:
versionsAsRoot: true
preset: '0.x'

stable:
Expand All @@ -21,7 +22,11 @@ jobs:

strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.stable) }}
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.stable) }}
command:
- 'tests-only'
- 'test:corejs'

steps:
- uses: actions/checkout@v2
Expand All @@ -31,7 +36,7 @@ jobs:
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 tests-only
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v1

unstable:
Expand All @@ -43,7 +48,11 @@ jobs:

strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.unstable) }}
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.unstable) }}
command:
- 'tests-only'
- 'test:corejs'

steps:
- uses: actions/checkout@v2
Expand All @@ -53,7 +62,7 @@ jobs:
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 tests-only
- run: npm run ${{ matrix.command }}
- uses: codecov/codecov-action@v1

node:
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ package-lock.json
yarn.lock

.github/workflows
test-corejs.js
3 changes: 2 additions & 1 deletion .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"reporter": ["text-summary", "text", "html", "json"],
"exclude": [
"coverage",
"test"
"test",
"test-corejs.js"
]
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var tryStringObject = function tryStringObject(value) {
};
var toStr = Object.prototype.toString;
var strClass = '[object String]';
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag;

module.exports = function isString(value) {
if (typeof value === 'string') {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"prepublish": "not-in-publish || npm run prepublishOnly",
"pretest": "npm run lint",
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",
"test:corejs": "nyc tape test-corejs.js",
"test": "npm run tests-only && npm run test:corejs",
"posttest": "npx aud --production",
"lint": "eslint .",
"eccheck": "eclint check *.js **/*.js > /dev/null",
Expand All @@ -36,6 +37,7 @@
"@ljharb/eslint-config": "^17.6.0",
"aud": "^1.1.5",
"auto-changelog": "^2.2.1",
"core-js": "^3.12.0",
"eclint": "^2.8.1",
"eslint": "^7.26.0",
"foreach": "^2.0.5",
Expand Down
5 changes: 5 additions & 0 deletions test-corejs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

require('core-js');

require('./test');
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var test = require('tape');
var isString = require('../');
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('') === 'symbol';
var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator !== 'undefined';

test('not Strings', function (t) {
t.notOk(isString(), 'undefined is not String');
Expand Down

0 comments on commit 83337eb

Please sign in to comment.