From 7ae13014089ef91067bafd4cec0247dc25a03496 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 23 Jan 2026 20:51:34 -0400 Subject: find: bring your own behavior --- src/find.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src') diff --git a/src/find.js b/src/find.js index 7b2ea7e0..ddd6ae05 100644 --- a/src/find.js +++ b/src/find.js @@ -271,6 +271,8 @@ function matchHelper(fullRef, mode, { function findHelper({ referenceTypes, + byob = undefined, + include = undefined, getMatchableNames = undefined, getMatchableDirectories = undefined, @@ -305,6 +307,27 @@ function findHelper({ throw new TypeError(`Expected data to be present`); } + if (byob) { + let match = null; + + try { + match = byob(fullRef, data, {mode, from, fuzz}); + } catch (caught) { + if (typeof caught === 'string') { + return warnOrThrow(mode, caught); + } else { + throw caught; + } + } + + if (match) { + return match; + } else { + return warnOrThrow(mode, + `Didn't match anything for ${colors.bright(fullRef)}`); + } + } + let dataSubcache = cache.get(data); if (!dataSubcache) { cache.set(data, dataSubcache = new Map()); -- cgit 1.3.0-6-gf8a5