diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-11-05 18:28:25 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-11-05 18:33:02 -0400 |
commit | 237cfda2fffef391d9a3bf0f05b9af39a170ca4d (patch) | |
tree | edad0d021ee1e7af6a0d41a4fefe578cbfab0765 | |
parent | d6672865a59a94a2acdd3ec7e827f96f8c3e67e4 (diff) |
find: support filtering which things are included for matching
-rw-r--r-- | src/find.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/find.js b/src/find.js index 8c9413b7..d8c08ec1 100644 --- a/src/find.js +++ b/src/find.js @@ -16,6 +16,8 @@ function warnOrThrow(mode, message) { } export function processAllAvailableMatches(data, { + include = thing => true, + getMatchableNames = thing => (Object.hasOwn(thing, 'name') ? [thing.name] @@ -26,6 +28,10 @@ export function processAllAvailableMatches(data, { const multipleNameMatches = Object.create(null); for (const thing of data) { + if (!include(thing)) continue; + + byDirectory[thing.directory] = thing; + for (const name of getMatchableNames(thing)) { if (typeof name !== 'string') { logWarn`Unexpected ${typeAppearance(name)} returned in names for ${inspect(thing)}`; @@ -33,6 +39,7 @@ export function processAllAvailableMatches(data, { } const normalizedName = name.toLowerCase(); + if (normalizedName in byName) { const alreadyMatchesByName = byName[normalizedName]; byName[normalizedName] = null; @@ -45,8 +52,6 @@ export function processAllAvailableMatches(data, { byName[normalizedName] = thing; } } - - byDirectory[thing.directory] = thing; } return {byName, byDirectory, multipleNameMatches}; @@ -55,6 +60,7 @@ export function processAllAvailableMatches(data, { function findHelper({ referenceTypes, + include = undefined, getMatchableNames = undefined, }) { const keyRefRegex = @@ -84,6 +90,7 @@ function findHelper({ if (!subcache) { subcache = processAllAvailableMatches(data, { + include, getMatchableNames, }); |