ass-compiler
Version:
Parses and compiles ASS subtitle format to easy-to-use data structure.
17 lines (16 loc) • 406 B
JavaScript
export function parseDrawing(text) {
if (!text) return [];
return text
.toLowerCase()
// numbers
.replace(/([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)/g, ' $1 ')
// commands
.replace(/([mnlbspc])/g, ' $1 ')
.trim()
.replace(/\s+/g, ' ')
.split(/\s(?=[mnlbspc])/)
.map((cmd) => (
cmd.split(' ')
.filter((x, i) => !(i && Number.isNaN(x * 1)))
));
}