UNPKG

node-csfd-api

Version:

ČSFD API in JavaScript. Amazing NPM library for scrapping csfd.cz :)

52 lines (50 loc) 1.67 kB
//#region src/helpers/global.helper.ts const parseIdFromUrl = (url) => { if (url) return +(url?.split("/")[2])?.split("-")[0] || null; else return null; }; const getColor = (cls) => { switch (cls) { case "page-lightgrey": return "unknown"; case "page-red": return "good"; case "page-blue": return "average"; case "page-grey": return "bad"; default: return "unknown"; } }; const parseColor = (quality) => { switch (quality) { case "lightgrey": return "unknown"; case "red": return "good"; case "blue": return "average"; case "grey": return "bad"; default: return "unknown"; } }; const addProtocol = (url) => { return url.startsWith("//") ? "https:" + url : url; }; const getDuration = (matches) => { return { sign: matches[1] === void 0 ? "+" : "-", years: matches[2] === void 0 ? 0 : matches[2], months: matches[3] === void 0 ? 0 : matches[3], weeks: matches[4] === void 0 ? 0 : matches[4], days: matches[5] === void 0 ? 0 : matches[5], hours: matches[6] === void 0 ? 0 : matches[6], minutes: matches[7] === void 0 ? 0 : matches[7], seconds: matches[8] === void 0 ? 0 : matches[8] }; }; const parseISO8601Duration = (iso) => { return +getDuration(iso.match(/(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/)).minutes; }; const sleep = (ms) => new Promise((res) => setTimeout(res, ms)); //#endregion exports.addProtocol = addProtocol; exports.getColor = getColor; exports.parseColor = parseColor; exports.parseISO8601Duration = parseISO8601Duration; exports.parseIdFromUrl = parseIdFromUrl; exports.sleep = sleep; //# sourceMappingURL=global.helper.js.map