« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-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());