« get me outta code hell

real pragma, and some eslint fixes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/find.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-06-26 18:02:27 -0300
committer(quasar) nebula <qznebula@protonmail.com>2022-06-26 18:02:27 -0300
commitc75b029160248b6935e5c0f5156cc7a870311e82 (patch)
tree693c5cca195e50b048b0086e768aa06a7c1986ee /src/util/find.js
parentf65e712fe8b8b1a196da2db286ebc6a5c9bf7433 (diff)
real pragma, and some eslint fixes
Diffstat (limited to 'src/util/find.js')
-rw-r--r--src/util/find.js62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/util/find.js b/src/util/find.js
index 6ee0583..460a4fa 100644
--- a/src/util/find.js
+++ b/src/util/find.js
@@ -1,14 +1,14 @@
-// @format
+/** @format */
 
-import { color, logError, logWarn } from "./cli.js";
+import {color, logError, logWarn} from './cli.js';
 
-import { inspect } from "util";
+import {inspect} from 'util';
 
 function warnOrThrow(mode, message) {
   switch (mode) {
-    case "error":
+    case 'error':
       throw new Error(message);
-    case "warn":
+    case 'warn':
       logWarn(message);
     default:
       return null;
@@ -26,16 +26,16 @@ function findHelper(keys, findFns = {}) {
   const byName = findFns.byName || matchName;
 
   const keyRefRegex = new RegExp(
-    String.raw`^(?:(${keys.join("|")}):(?=\S))?(.*)$`
+    String.raw`^(?:(${keys.join('|')}):(?=\S))?(.*)$`
   );
 
   // The mode argument here may be 'warn', 'error', or 'quiet'. 'error' throws
   // errors for null matches (with details about the error), while 'warn' and
   // 'quiet' both return null, with 'warn' logging details directly to the
   // console.
-  return (fullRef, data, { mode = "warn" } = {}) => {
+  return (fullRef, data, {mode = 'warn'} = {}) => {
     if (!fullRef) return null;
-    if (typeof fullRef !== "string") {
+    if (typeof fullRef !== 'string') {
       throw new Error(
         `Got a reference that is ${typeof fullRef}, not string: ${fullRef}`
       );
@@ -81,19 +81,19 @@ function findHelper(keys, findFns = {}) {
 }
 
 function matchDirectory(ref, data, mode) {
-  return data.find(({ directory }) => directory === ref);
+  return data.find(({directory}) => directory === ref);
 }
 
 function matchName(ref, data, mode) {
   const matches = data.filter(
-    ({ name }) => name.toLowerCase() === ref.toLowerCase()
+    ({name}) => name.toLowerCase() === ref.toLowerCase()
   );
 
   if (matches.length > 1) {
     return warnOrThrow(
       mode,
       `Multiple matches for reference "${ref}". Please resolve:\n` +
-        matches.map((match) => `- ${inspect(match)}\n`).join("") +
+        matches.map((match) => `- ${inspect(match)}\n`).join('') +
         `Returning null for this reference.`
     );
   }
@@ -115,19 +115,19 @@ function matchName(ref, data, mode) {
 }
 
 function matchTagName(ref, data, quiet) {
-  return matchName(ref.startsWith("cw: ") ? ref.slice(4) : ref, data, quiet);
+  return matchName(ref.startsWith('cw: ') ? ref.slice(4) : ref, data, quiet);
 }
 
 const find = {
-  album: findHelper(["album", "album-commentary"]),
-  artist: findHelper(["artist", "artist-gallery"]),
-  artTag: findHelper(["tag"], { byName: matchTagName }),
-  flash: findHelper(["flash"]),
-  group: findHelper(["group", "group-gallery"]),
-  listing: findHelper(["listing"]),
-  newsEntry: findHelper(["news-entry"]),
-  staticPage: findHelper(["static"]),
-  track: findHelper(["track"]),
+  album: findHelper(['album', 'album-commentary']),
+  artist: findHelper(['artist', 'artist-gallery']),
+  artTag: findHelper(['tag'], {byName: matchTagName}),
+  flash: findHelper(['flash']),
+  group: findHelper(['group', 'group-gallery']),
+  listing: findHelper(['listing']),
+  newsEntry: findHelper(['news-entry']),
+  staticPage: findHelper(['static']),
+  track: findHelper(['track']),
 };
 
 export default find;
@@ -140,15 +140,15 @@ export default find;
 export function bindFind(wikiData, opts1) {
   return Object.fromEntries(
     Object.entries({
-      album: "albumData",
-      artist: "artistData",
-      artTag: "artTagData",
-      flash: "flashData",
-      group: "groupData",
-      listing: "listingSpec",
-      newsEntry: "newsData",
-      staticPage: "staticPageData",
-      track: "trackData",
+      album: 'albumData',
+      artist: 'artistData',
+      artTag: 'artTagData',
+      flash: 'flashData',
+      group: 'groupData',
+      listing: 'listingSpec',
+      newsEntry: 'newsData',
+      staticPage: 'staticPageData',
+      track: 'trackData',
     }).map(([key, value]) => {
       const findFn = find[key];
       const thingData = wikiData[value];
@@ -157,7 +157,7 @@ export function bindFind(wikiData, opts1) {
         opts1
           ? (ref, opts2) =>
               opts2
-                ? findFn(ref, thingData, { ...opts1, ...opts2 })
+                ? findFn(ref, thingData, {...opts1, ...opts2})
                 : findFn(ref, thingData, opts1)
           : (ref, opts2) =>
               opts2 ? findFn(ref, thingData, opts2) : findFn(ref, thingData),