Illustrations/web/static/js/source-validator.v1.js

31 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* source-validator.v1.js
Centralizes logic for deciding if a "Source" string should link to WOL.
Exposes:
- SourceValidator.isWOLSource(text) -> boolean
- SourceValidator.buildWOLSearchURL(text) -> string
*/
window.SourceValidator = (function () {
// Publications / codes that produce valid WOL links (from your template list)
const PUB_CODES = [
"wp","ws","yb","mwb","w","g","ap","apf","be","bh","br","bt","btg","cf","cl","ct","dp",
"fg","fy","gt","hb","im","ip","it","jv","ka","kj","kl","lf","lff","ll","ly","my","od",
"pe","po","pt","rr","rs","sg","sh","si","td","tp","tr","ts","un","jy"
];
function normalize(s) { return (s || "").trim().toLowerCase(); }
function isWOLSource(text) {
const t = normalize(text);
if (!t) return false;
// Keep this simple: if the string starts with any known code, treat it as WOL-capable.
return PUB_CODES.some(code => t.startsWith(code));
}
function buildWOLSearchURL(text) {
const q = encodeURIComponent(text || "");
// Same search endpoint youre already using
return `https://wol.jw.org/en/wol/l/r1/lp-e?q=${q}`;
}
return { isWOLSource, buildWOLSearchURL };
})();