From 385faccb5a5be64acd5ca65ace26d6a7db37b64f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 16 Apr 2022 23:37:12 -0300 Subject: HSMusic REPL + supporting internal improvements --- src/util/find.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/util/find.js') diff --git a/src/util/find.js b/src/util/find.js index dd39bad9..7cedb3d2 100644 --- a/src/util/find.js +++ b/src/util/find.js @@ -124,3 +124,32 @@ const find = { }; export default find; + +// Handy utility function for binding the find.thing() functions to a complete +// wikiData object, optionally taking default options to provide to the find +// function. Note that this caches the arrays read from wikiData right when it's +// called, so if their values change, you'll have to continue with a fresh call +// to bindFind. +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', + }).map(([ key, value ]) => { + const findFn = find[key]; + const thingData = wikiData[value]; + return [key, (opts1 + ? (ref, opts2) => (opts2 + ? findFn(ref, thingData, {...opts1, ...opts2}) + : findFn(ref, thingData, opts1)) + : (ref, opts2) => (opts2 + ? findFn(ref, thingData, opts2) + : findFn(ref, thingData)))]; + })); +} -- cgit 1.3.0-6-gf8a5