UNPKG

identify-media

Version:

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

33 lines (27 loc) 981 B
import {findSeason, findSeasonEpisode} from "./analyseString"; export const stripParenthesis = (name: string): string => { return name.replace(/(\([^)]*\))?({[^}]*})?(\[[^\]]*])?/g, ''); } export const trimEnd = (name?: string): string => { if (!name) return ''; return name.replace(/^[\W]?\s*$/, '').replace(/\s+[\W]?\s*$/, ''); } export const stripEnd = (name: string): string => { return name.slice(0, name.lastIndexOf('.')); } export const stripSeasons = (name?: string): string|undefined => { if (!name) return undefined; const data = (findSeasonEpisode(name) || findSeason(name)); if (data) { return data.restName; } return name.replace(/s[0-9]+[\s-](s[0-9]+)?/i, ''); } const ellipsis = '…'; export const setSpaces = (name: string): string => { return name .replace(/\.{5}/g, ' ' + ellipsis + ' ') .replace(/\.{3}/g, ellipsis) .replace(/[._-]/g, ' ') .replace(ellipsis, '...').trim(); }