« get me outta code hell

find: copy in some more common behavior - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-11-14 18:21:44 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-15 20:40:12 -0400
commit36f1a86102d622095ef2a3141cdae81770d2b70c (patch)
tree3e95f1599f608407323a4b8bece23c57781a2f9a /src
parent7360804a1d99e8665cad8977755350543a16ccfa (diff)
find: copy in some more common behavior
Diffstat (limited to 'src')
-rw-r--r--src/find.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/find.js b/src/find.js
index 2c97142f..238abda8 100644
--- a/src/find.js
+++ b/src/find.js
@@ -112,7 +112,10 @@ function findHelper({
   // 'quiet' both return null, with 'warn' logging details directly to the
   // console.
   return (fullRef, data, {mode = 'warn'} = {}) => {
+    // TODO: Factor out this validation
+
     if (!fullRef) return null;
+
     if (typeof fullRef !== 'string') {
       throw new TypeError(`Expected a string, got ${typeAppearance(fullRef)}`);
     }
@@ -268,6 +271,18 @@ function findMixedHelper(config) {
     specs = specKeys.map(specKey => findFindSpec(specKey));
 
   return (fullRef, data, {mode = 'warn'} = {}) => {
+    // TODO: Factor out this validation
+
+    if (!fullRef) return null;
+
+    if (typeof fullRef !== 'string') {
+      throw new TypeError(`Expected a string, got ${typeAppearance(fullRef)}`);
+    }
+
+    if (!data) {
+      throw new TypeError(`Expected data to be present`);
+    }
+
     // TODO: Cache stuff below by identity of data
 
     const byName = Object.create(null);