The `webvtt-parser` package provides a robust, specification-compliant parser and serializer for WebVTT (Web Video Text Tracks) files. Maintained by the W3C, it allows developers to programmatically parse WebVTT strings into a JavaScript object tree and serialize such trees back into WebVTT formatted strings. The current stable version is 2.2.0, and releases generally follow W3C specification updates or bug fixes, without a fixed cadence. Its primary differentiator is its direct adherence to the official WebVTT specification, making it a reliable choice for applications requiring strict compliance, such as browser implementations or media processing tools. It supports both Node.js environments via npm and browser environments through a UMD build.
npm install webvtt-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize WebVTTParser, parse a basic VTT string, and optionally load HTML entities for full specification compliance.
Obtain the `html-entities.json` file (typically from the `webvtt-parser` package itself or its GitHub repo) and pass its parsed content to `parser.loadHTMLSerializerEntities(entities)` after instantiation, or to the `WebVTTParser` constructor.
For CommonJS, use `const { WebVTTParser } = require('webvtt-parser');` or `const WebVTTParser = require('webvtt-parser').WebVTTParser;`. For ESM, consistently use `import { Name } from 'pkg';`.After calling `parser.parse()`, always check `tree.errors` to identify and handle any parsing issues. Example: `if (tree.errors && tree.errors.length > 0) { console.error('Parsing errors:', tree.errors); }`Ensure correct import/require syntax for your module environment. For ESM: `import { WebVTTParser } from 'webvtt-parser';`. For CommonJS: `const { WebVTTParser } = require('webvtt-parser');`Verify the import statement is present and correct at the top of your file. If in a browser, ensure `parser.js` is loaded via a `<script>` tag before your code runs. If using a bundler, confirm `webvtt-parser` is correctly resolved.
Ensure that the `html-entities.json` content is correctly read and parsed into a JavaScript object before being passed to `loadHTMLSerializerEntities` or the constructor. It should be a plain object.
No dependency data recorded yet.