UNPKG

unified-video-framework

Version:

Cross-platform video player framework supporting iOS, Android, Web, Smart TVs (Samsung/LG), Roku, and more

30 lines 1.05 kB
export class SrtConverter { static convertToVtt(srtContent) { let vtt = 'WEBVTT\n\n'; const blocks = srtContent .replace(/^\uFEFF/, '') .replace(/\r\n/g, '\n') .replace(/\r/g, '\n') .trim() .split(/\n\n+/); for (const block of blocks) { const lines = block.split('\n'); if (lines.length < 2) continue; let timestampLineIndex = 0; if (/^\d+$/.test(lines[0])) { timestampLineIndex = 1; } if (lines[timestampLineIndex] && lines[timestampLineIndex].includes(' --> ')) { const vttTimestamp = lines[timestampLineIndex].replace(/,/g, '.'); vtt += vttTimestamp + '\n'; for (let i = timestampLineIndex + 1; i < lines.length; i++) { vtt += lines[i] + '\n'; } vtt += '\n'; } } return vtt; } } //# sourceMappingURL=SrtConverter.js.map