A lightweight JavaScript library for validating WebVTT (Web Video Text Tracks) files in the browser. This library provides a simple API for validating WebVTT content and comes with a beautiful, responsive web interface for testing.
- Demo (GitHub Pages): https://khattaksd.github.io/webvtt-validator/
- Contributing: CONTRIBUTING.md
- Security: SECURITY.md
- License: LICENSE
This package is tested against Node current LTS and the previous LTS.
- CommonJS (
require) support is best effort.
- Validates WebVTT format and syntax
- Checks for common errors in timestamps and cue formatting
- Lightweight with no external dependencies
- Beautiful and responsive web interface
- Supports file upload and direct input
- Detailed error and warning messages
# npm
npm install webvtt-validator
# pnpm
pnpm add webvtt-validator
# yarn
yarn add webvtt-validatorimport { parse, DiagnosticSeverity, formatDiagnostics } from "jsr:@khattaksd/webvtt-validator";Or add to your deno.json:
{
"imports": {
"webvtt": "jsr:@khattaksd/webvtt-validator@^0.1.0"
}
}import { parse, DiagnosticSeverity, formatDiagnostics } from "jsr:@khattaksd/webvtt-validator";
const result = parse('WEBVTT\n\n00:00:01.000 --> 00:00:05.000\nHello, world!');
const errors = result.diagnostics.filter(d => d.severity === DiagnosticSeverity.Error);
console.log(errors.length === 0);
console.log(formatDiagnostics(result.diagnostics));The dist/index.mjs bundle is browser-compatible ESM.
import { parse, DiagnosticSeverity, formatDiagnostics } from 'webvtt-validator';
const result = parse('WEBVTT\n\n00:00:01.000 --> 00:00:05.000\nHello, world!');
const errors = result.diagnostics.filter(d => d.severity === DiagnosticSeverity.Error);
console.log(errors.length === 0);
console.log(formatDiagnostics(result.diagnostics));const { parse, DiagnosticSeverity, formatDiagnostics } = require('webvtt-validator');
const result = parse('WEBVTT\n\n00:00:01.000 --> 00:00:05.000\nHello, world!');
const errors = result.diagnostics.filter(d => d.severity === DiagnosticSeverity.Error);
console.log(errors.length === 0);
console.log(formatDiagnostics(result.diagnostics));Open the demo/index.html file in your browser to use the web interface for validating WebVTT files.
Parses WebVTT input and returns cues plus a structured diagnostics list.
The validator checks for the following:
- Presence of the WEBVTT header
- Valid timestamp format (HH:MM:SS.mmm --> HH:MM:SS.mmm)
- Start time is before end time in each cue
- Proper cue separation with blank lines
- No empty cue blocks
- Clone the repository
- Install dependencies:
pnpm install
- Build the library:
pnpm run build
The built files will be available in the dist directory.
MIT. See LICENSE.
Contributions are welcome! Please feel free to submit a Pull Request. See CONTRIBUTING.md.
Try the demo by opening demo/index.html in your browser after running pnpm run build.