« get me outta code hell

find: bring your own behavior - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/find.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-01-23 20:51:34 -0400
committer(quasar) nebula <qznebula@protonmail.com>2026-01-23 21:25:58 -0400
commit7ae13014089ef91067bafd4cec0247dc25a03496 (patch)
tree85bbbf96fe6260f39e30b08fe8e04d03e98a24b9 /src/find.js
parent9bdcf0476f4b222cb806755510b1dc3d4d545e1e (diff)
find: bring your own behavior
Diffstat (limited to 'src/find.js')
-rw-r--r--src/find.js23
1 files changed, 23 insertions, 0 deletions
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());