Skip to content

Commit

Permalink
[Refactor] use 1 iteration instead of 2; drop flatmap dep
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 19, 2024
1 parent a0d5ebc commit c1f8dd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 8 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var hasSymbols = require('has-symbols')();
var isSymbol = require('is-symbol');
var flatMap = require('array.prototype.flatmap');
var ownKeys = require('reflect.ownkeys');
var callBound = require('call-bound');

Expand All @@ -11,19 +10,17 @@ var result;

if (hasSymbols) {
var symbolValueOf = callBound('Symbol.prototype.valueOf');
var wellKnownSymbols = hasSymbols && flatMap(
ownKeys(Symbol),
function (k) {
var v = Symbol[k];
// eslint-disable-next-line no-extra-parens
return typeof v === 'symbol' ? /** @type {[import('.').WellKnownSymbol]} */ (/** @type {unknown} */ (v)) : [];
}
);
var symKeys = ownKeys(Symbol);

/** @type {{ __proto__: null } & { [k in import('.').WellKnownSymbol]?: true }} */
var map = { __proto__: null };
for (var i = 0; i < wellKnownSymbols.length; i += 1) {
map[wellKnownSymbols[i]] = true;

for (var i = 0; i < symKeys.length; i += 1) {
var v = Symbol[symKeys[i]];
if (typeof v === 'symbol') {
// eslint-disable-next-line no-extra-parens
map[/** @type {import('.').WellKnownSymbol} */ (/** @type {unknown} */ (v))] = true;
}
}

result = /** @type {import('.')} */ function isWellKnownSymbol(sym) {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
},
"homepage": "https://github.com/inspect-js/is-well-known-symbol#readme",
"dependencies": {
"array.prototype.flatmap": "^1.3.3",
"call-bound": "^1.0.3",
"has-symbols": "^1.1.0",
"is-symbol": "^1.1.1",
Expand All @@ -52,7 +51,6 @@
"@arethetypeswrong/cli": "^0.17.1",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.2",
"@types/array.prototype.flatmap": "^1.2.6",
"@types/for-each": "^0.3.3",
"@types/object-inspect": "^1.13.0",
"@types/reflect.ownkeys": "^1.1.0",
Expand Down

0 comments on commit c1f8dd3

Please sign in to comment.