Skip to content

Commit

Permalink
[New] add types
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 25, 2024
1 parent 1fac324 commit 6f63623
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
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 isRegisteredSymbol(sym: unknown): boolean;

export = isRegisteredSymbol;
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
var isSymbol = require('is-symbol');
var callBound = require('call-bind/callBound');

/** @type {typeof Symbol.keyFor} */
var keyFor = callBound('Symbol.keyFor', true);
/** @type {(receiver: ThisParameterType<typeof Symbol.prototype.valueOf>, ...args: Parameters<typeof Symbol.prototype.valueOf>) => ReturnType<typeof Symbol.prototype.valueOf>} */
var symbolValueOf = callBound('Symbol.prototype.valueOf', true);

/** @type {import('.')} */
module.exports = function isRegisteredSymbol(sym) {
if (!isSymbol(sym)) {
return false;
Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"posttest": "npx npm@'>=10.2' audit --production",
"prelint": "evalmd README.md",
"lint": "eslint --ext=js,mjs .",
"postlint": "tsc -p . && attw -P",
"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)\")\""
},
Expand Down Expand Up @@ -47,7 +48,15 @@
"is-symbol": "^1.0.4"
},
"devDependencies": {
"@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/is-symbol": "^1.0.2",
"@types/object-inspect": "^1.13.0",
"@types/tape": "^5.6.4",
"auto-changelog": "^2.5.0",
"encoding": "^0.1.13",
"es-value-fixtures": "^1.5.0",
Expand All @@ -60,7 +69,8 @@
"nyc": "^10.3.2",
"object-inspect": "^1.13.3",
"safe-publish-latest": "^2.0.0",
"tape": "^5.9.0"
"tape": "^5.9.0",
"typescript": "^5.8.0-dev.20241125"
},
"testling": {
"files": "test/index.js"
Expand Down
6 changes: 5 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ test('isRegisteredSymbol', function (t) {
t.equal(typeof isRegisteredSymbol, 'function', 'is a function');

t.test('non-symbols', function (st) {
forEach(v.nonSymbolPrimitives.concat(v.objects), function (nonSymbol) {
forEach([].concat(
// @ts-expect-error TS sucks with concat
v.nonSymbolPrimitives,
v.objects
), function (nonSymbol) {
st.equal(isRegisteredSymbol(nonSymbol), false, inspect(nonSymbol) + ' is not a Symbol');
});

Expand Down
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "@ljharb/tsconfig",
"compilerOptions": {
"target": "ES2021",
},
"exclude": [
"coverage"
]
}

0 comments on commit 6f63623

Please sign in to comment.