UNPKG

node-csfd-api-racintom

Version:

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

69 lines (68 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseISO8601Duration = exports.getDuration = exports.addProtocol = exports.parseColor = exports.getColor = exports.parseIdFromUrl = void 0; const parseIdFromUrl = (url) => { if (url) { const idSlug = url === null || url === void 0 ? void 0 : url.split('/')[2]; const id = idSlug === null || idSlug === void 0 ? void 0 : idSlug.split('-')[0]; return +id || null; } else { return null; } }; exports.parseIdFromUrl = parseIdFromUrl; 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'; } }; exports.getColor = getColor; const parseColor = (quality) => { switch (quality) { case 'lightgrey': return 'unknown'; case 'red': return 'good'; case 'blue': return 'average'; case 'grey': return 'bad'; default: return 'unknown'; } }; exports.parseColor = parseColor; const addProtocol = (url) => { return url.startsWith('//') ? 'https:' + url : url; }; exports.addProtocol = addProtocol; const getDuration = (matches) => { return { sign: matches[1] === undefined ? '+' : '-', years: matches[2] === undefined ? 0 : matches[2], months: matches[3] === undefined ? 0 : matches[3], weeks: matches[4] === undefined ? 0 : matches[4], days: matches[5] === undefined ? 0 : matches[5], hours: matches[6] === undefined ? 0 : matches[6], minutes: matches[7] === undefined ? 0 : matches[7], seconds: matches[8] === undefined ? 0 : matches[8] }; }; exports.getDuration = getDuration; const parseISO8601Duration = (iso) => { const iso8601DurationRegex = /(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/; const matches = iso.match(iso8601DurationRegex); const duration = (0, exports.getDuration)(matches); return +duration.minutes; }; exports.parseISO8601Duration = parseISO8601Duration;