New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

is-symbol

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-symbol - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

index.d.ts

22

CHANGELOG.md

@@ -8,2 +8,24 @@ # Changelog

## [v1.1.0](https://github.com/inspect-js/is-symbol/compare/v1.0.4...v1.1.0) - 2024-12-02
### Commits
- [actions] reuse common workflows [`acf85f0`](https://github.com/inspect-js/is-symbol/commit/acf85f027ec6ea70a7023646c47f9324ff9a5e25)
- [meta] use `npmignore` to autogenerate an npmignore file [`77c818e`](https://github.com/inspect-js/is-symbol/commit/77c818ebf4dc1107d945854185071ca76ef94d31)
- [Tests] use `for-each` and `es-value-fixtures` [`93dfed0`](https://github.com/inspect-js/is-symbol/commit/93dfed0de6c1da2946d83017cc0f44f8f7d15ded)
- [New] add types [`ed6a057`](https://github.com/inspect-js/is-symbol/commit/ed6a057e9595fb14c7d322ed4aba3433386d07bb)
- [actions] split out node 10-20, and 20+ [`7f81ccc`](https://github.com/inspect-js/is-symbol/commit/7f81ccc8bb2c667e6975f278c9dec7310a923749)
- [Robustness] use `call-bind` and `safe-regex-test` [`dc7e142`](https://github.com/inspect-js/is-symbol/commit/dc7e142724e9dce678b1ead151c7fedd02411a03)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `object-inspect`, `tape` [`70f87c2`](https://github.com/inspect-js/is-symbol/commit/70f87c2715ad4cc8e66ce0eb4a4d2c4034b8e19c)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `object-inspect`, `safe-publish-latest`, `tape` [`3f02ff4`](https://github.com/inspect-js/is-symbol/commit/3f02ff4459ec96e22be4ef8cda0c966fafb5509a)
- [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `has-tostringtag`, `npmignore`, `object-inspect`, `tape` [`9588872`](https://github.com/inspect-js/is-symbol/commit/95888727f109c7e9d2fdfe7ed419cc8452505503)
- [actions] update rebase action to use reusable workflow [`59e2f68`](https://github.com/inspect-js/is-symbol/commit/59e2f680992f630eb1d76dd8e009d7fa074e3055)
- [actions] update codecov uploader [`e4759f8`](https://github.com/inspect-js/is-symbol/commit/e4759f8bea3b66d6d70f8b7b2656cc9b987ca874)
- [Dev Deps] update `eslint`, `auto-changelog`, `object-inspect`, `tape` [`33990c0`](https://github.com/inspect-js/is-symbol/commit/33990c0d76db7f44bcf177f7f5b602747b159a35)
- [Tests] use `has-tostringtag` for more robust Symbol.toStringTag detection [`d6154e1`](https://github.com/inspect-js/is-symbol/commit/d6154e10f79b572630fd309543160c446d7e46ef)
- [Tests] replace `aud` with `npm audit` [`3215a60`](https://github.com/inspect-js/is-symbol/commit/3215a60cf4ffce688e3911025cf2ccca95e259d0)
- [Refactor] avoid an expensive check, for primitives [`59f1a42`](https://github.com/inspect-js/is-symbol/commit/59f1a428ae625b59b618493c2454096900451d84)
- [Deps] update `has-symbols` [`06be1a9`](https://github.com/inspect-js/is-symbol/commit/06be1a9d1bf57181e35b1ffe446196243cc8becc)
- [Dev Deps] add missing peer dep [`799b0da`](https://github.com/inspect-js/is-symbol/commit/799b0da1902dfa5b02456fcf32887ead6e332358)
## [v1.0.4](https://github.com/inspect-js/is-symbol/compare/v1.0.3...v1.0.4) - 2021-05-08

@@ -10,0 +32,0 @@

17

index.js
'use strict';
var toStr = Object.prototype.toString;
var callBound = require('call-bind/callBound');
var $toString = callBound('Object.prototype.toString');
var hasSymbols = require('has-symbols')();
var safeRegexTest = require('safe-regex-test');
if (hasSymbols) {
var symToStr = Symbol.prototype.toString;
var symStringRegex = /^Symbol\(.*\)$/;
var $symToStr = callBound('Symbol.prototype.toString');
var isSymString = safeRegexTest(/^Symbol\(.*\)$/);
/** @type {(value: object) => value is Symbol} */
var isSymbolObject = function isRealSymbolObject(value) {

@@ -13,5 +17,6 @@ if (typeof value.valueOf() !== 'symbol') {

}
return symStringRegex.test(symToStr.call(value));
return isSymString($symToStr(value));
};
/** @type {import('.')} */
module.exports = function isSymbol(value) {

@@ -21,3 +26,3 @@ if (typeof value === 'symbol') {

}
if (toStr.call(value) !== '[object Symbol]') {
if (!value || typeof value !== 'object' || $toString(value) !== '[object Symbol]') {
return false;

@@ -32,3 +37,3 @@ }

} else {
/** @type {import('.')} */
module.exports = function isSymbol(value) {

@@ -35,0 +40,0 @@ // this environment does not support Symbols.

{
"name": "is-symbol",
"version": "1.0.4",
"version": "1.1.0",
"description": "Determine if a value is an ES6 Symbol or not.",
"main": "index.js",
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublishOnly": "safe-publish-latest",

@@ -12,4 +13,5 @@ "prepublish": "not-in-publish || npm run prepublishOnly",

"test": "npm run tests-only",
"posttest": "npx aud --production",
"lint": "eslint .",
"posttest": "npx npm@'>=10.2' audit --production",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc -p . && attw -P",
"version": "auto-changelog && git add CHANGELOG.md",

@@ -37,13 +39,29 @@ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""

"dependencies": {
"has-symbols": "^1.0.2"
"call-bind": "^1.0.7",
"has-symbols": "^1.0.3",
"safe-regex-test": "^1.0.3"
},
"devDependencies": {
"@ljharb/eslint-config": "^17.6.0",
"aud": "^1.1.5",
"auto-changelog": "^2.2.1",
"eslint": "^7.26.0",
"@arethetypeswrong/cli": "^0.17.0",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.0",
"@types/call-bind": "^1.0.5",
"@types/for-each": "^0.3.3",
"@types/has-symbols": "^1.0.2",
"@types/object-inspect": "^1.13.0",
"@types/safe-regex-test": "^1.0.2",
"@types/tape": "^5.6.5",
"auto-changelog": "^2.5.0",
"encoding": "^0.1.13",
"es-value-fixtures": "^1.5.0",
"eslint": "=8.8.0",
"for-each": "^0.3.3",
"has-tostringtag": "^1.0.2",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"object-inspect": "^1.10.3",
"safe-publish-latest": "^1.1.4",
"tape": "^5.2.2"
"object-inspect": "^1.13.3",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0",
"typescript": "next"
},

@@ -78,3 +96,9 @@ "testling": {

"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows",
".nvmrc"
]
}
}
'use strict';
var test = require('tape');
var forEach = require('for-each');
var v = require('es-value-fixtures');
var isSymbol = require('../index');
var forEach = function (arr, func) {
var i;
for (i = 0; i < arr.length; ++i) {
func(arr[i], i, arr);
}
};
var hasSymbols = require('has-symbols')();
var hasToStringTag = require('has-tostringtag/shams')();
var inspect = require('object-inspect');
var debug = function (v, m) { return inspect(v) + ' ' + m; };
test('non-symbol values', function (t) {
var nonSymbols = [
true,
false,
var nonSymbols = v.nonSymbolPrimitives.concat(
Object(true),
Object(false),
null,
undefined,
// @ts-expect-error TS sucks with concat
{},
[],
/a/g,
'string',
42,
new Date(),
function () {},
NaN
];
);
t.plan(nonSymbols.length);
forEach(nonSymbols, function (nonSymbol) {
t.equal(false, isSymbol(nonSymbol), debug(nonSymbol, 'is not a symbol'));
t.equal(isSymbol(nonSymbol), false, inspect(nonSymbol) + ' is not a symbol');
});

@@ -44,13 +35,16 @@ t.end();

var fakeSymbol = { valueOf: function () { return Symbol('foo'); } };
st.equal(false, isSymbol(fakeSymbol), 'object with valueOf returning a symbol is not a symbol');
st.equal(isSymbol(fakeSymbol), false, 'object with valueOf returning a symbol is not a symbol');
st.end();
});
t.test('faked @@toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (st) {
t.test('faked @@toStringTag', { skip: !hasToStringTag }, function (st) {
/** @type {{ valueOf(): unknown; [Symbol.toStringTag]?: unknown }} */
var fakeSymbol = { valueOf: function () { return Symbol('foo'); } };
fakeSymbol[Symbol.toStringTag] = 'Symbol';
st.equal(false, isSymbol(fakeSymbol), 'object with fake Symbol @@toStringTag and valueOf returning a symbol is not a symbol');
st.equal(isSymbol(fakeSymbol), false, 'object with fake Symbol @@toStringTag and valueOf returning a symbol is not a symbol');
/** @type {{ valueOf(): unknown; [Symbol.toStringTag]?: unknown }} */
var notSoFakeSymbol = { valueOf: function () { return 42; } };
notSoFakeSymbol[Symbol.toStringTag] = 'Symbol';
st.equal(false, isSymbol(notSoFakeSymbol), 'object with fake Symbol @@toStringTag and valueOf not returning a symbol is not a symbol');
st.equal(isSymbol(notSoFakeSymbol), false, 'object with fake Symbol @@toStringTag and valueOf not returning a symbol is not a symbol');
st.end();

@@ -60,3 +54,3 @@ });

var fakeSymbolString = { toString: function () { return 'Symbol(foo)'; } };
t.equal(false, isSymbol(fakeSymbolString), 'object with toString returning Symbol(foo) is not a symbol');
t.equal(isSymbol(fakeSymbolString), false, 'object with toString returning Symbol(foo) is not a symbol');

@@ -68,2 +62,3 @@ t.end();

t.test('well-known Symbols', function (st) {
/** @type {(name: string) => name is Exclude<keyof SymbolConstructor, 'for' | 'keyFor'>} */
var isWellKnown = function filterer(name) {

@@ -74,4 +69,5 @@ return name !== 'for' && name !== 'keyFor' && !(name in filterer);

wellKnownSymbols.forEach(function (name) {
var sym = Symbol[name];
st.equal(true, isSymbol(sym), debug(sym, ' is a symbol'));
// eslint-disable-next-line no-extra-parens
var sym = Symbol[/** @type {keyof SymbolConstructor} */ (name)];
st.equal(isSymbol(sym), true, inspect(sym) + ' is a symbol');
});

@@ -82,3 +78,3 @@ st.end();

t.test('user-created symbols', function (st) {
var symbols = [
var symbols = v.symbols.concat(
Symbol(),

@@ -88,5 +84,5 @@ Symbol('foo'),

Object(Symbol('object'))
];
);
symbols.forEach(function (sym) {
st.equal(true, isSymbol(sym), debug(sym, ' is a symbol'));
st.equal(isSymbol(sym), true, inspect(sym) + ' is a symbol');
});

@@ -93,0 +89,0 @@ st.end();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc