/** * Hachette querying page settings with regard to wildcard records * * Copyright (C) 2021 Wojtek Kosior * Redistribution terms are gathered in the `copyright' file. */ /* * IMPORTS_START * IMPORT TYPE_PREFIX * IMPORT for_each_possible_pattern * IMPORTS_END */ function check_pattern(storage, pattern, multiple, matched) { const settings = storage.get(TYPE_PREFIX.PAGE, pattern); if (settings === undefined) return; matched.push([pattern, settings]); if (!multiple) return false; } function query(storage, url, multiple) { const matched = []; const cb = p => check_pattern(storage, p, multiple, matched); for_each_possible_pattern(url, cb); return multiple ? matched : (matched[0] || [undefined, undefined]); } function query_best(storage, url) { return query(storage, url, false); } function query_all(storage, url) { return query(storage, url, true); } /* * EXPORTS_START * EXPORT query_best * EXPORT query_all * EXPORTS_END */