Skip to content

Function: parseWebVtt() ​

ts
function parseWebVtt(text, options?): Promise<WebVttParseResult>;

Defined in: libs/webvtt/src/parseWebVtt.ts:20

Parse a WebVTT string into a WebVttParseResult.

Parameters ​

text ​

string

The WebVTT string to parse.

options? ​

WebVttParserOptions

The options to use for the parser.

Returns ​

Promise<WebVttParseResult>

The parsed WebVttParseResult.

Example ​

ts
const vtt = `WEBVTT\n\nREGION\nid:test\n\nSTYLE\n::cue {}\n\nCUE_1\n00:00:00.000 --> 00:00:35.000\nWevVTT Sample\n`

const { cues, errors, regions, styles } = await parseWebVtt(vtt)

assert(cues[0].id === 'CUE_1')
assert(cues[0].text === 'WevVTT Sample')
assert(errors.length === 0)
assert(regions[0].id === 'test')
assert(styles.length === 1)

A Streaming Video Technology Alliance project.