UNPKG

identify-media

Version:

Analyse file path and content to make search criteria for media APIs

38 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setSpaces = exports.stripSeasons = exports.stripEnd = exports.trimEnd = exports.stripParenthesis = void 0; const analyseString_1 = require("./analyseString"); const stripParenthesis = (name) => { return name.replace(/(\([^)]*\))?({[^}]*})?(\[[^\]]*])?/g, ''); }; exports.stripParenthesis = stripParenthesis; const trimEnd = (name) => { if (!name) return ''; return name.replace(/^[\W]?\s*$/, '').replace(/\s+[\W]?\s*$/, ''); }; exports.trimEnd = trimEnd; const stripEnd = (name) => { return name.slice(0, name.lastIndexOf('.')); }; exports.stripEnd = stripEnd; const stripSeasons = (name) => { if (!name) return undefined; const data = ((0, analyseString_1.findSeasonEpisode)(name) || (0, analyseString_1.findSeason)(name)); if (data) { return data.restName; } return name.replace(/s[0-9]+[\s-](s[0-9]+)?/i, ''); }; exports.stripSeasons = stripSeasons; const ellipsis = '…'; const setSpaces = (name) => { return name .replace(/\.{5}/g, ' ' + ellipsis + ' ') .replace(/\.{3}/g, ellipsis) .replace(/[._-]/g, ' ') .replace(ellipsis, '...').trim(); }; exports.setSpaces = setSpaces; //# sourceMappingURL=cleanString.js.map