simple-subtitle-parser
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Simple Subtitle Parser

(previously, subtitle-parsing-tool)

license version tests

Zero-dependency, subtitle parser written in TypeScript. Parses subtitle files and generates a collection of timed objects.

Now includes typings!

Supported subtitle files

  • SRT
  • WebVTT

Installation

npm i simple-subtitle-parser

Importing the parser

ES6

import { parser } from 'simple-subtitle-parser

With types

import { parser, Cue, Format } from 'simple-subtitle-parser';

CommonJS

const parser = require('simple-subtitle-parser');

Usage

parser(format: Format, rawText: string)
Arguments

format

Denotes the format of the subtitles to be parsed. Accepts 2 values:

  • SRT
  • WEBVTT

rawText

The raw data for the subtitles to parse.

Return value

A Promise that resolves to an array of Cue type objects

Exported Helpers

extractFormatFromFileName(fileName: string);
Arguments

fileName

The filename

Return value

An object of the following shape:

{
    extension: string;
    format: Format
}

Exported Types

The following types are available:

Formats

An exported object of strings which correspond to the supported formats

enum Format

Format.Srt
Format.WebVtt
Format.Unsupported

interface Cue

A subtitle time encoded object of the following shape:

{
    sequence: number;
    startTime: Time;
    endTime: Time;
    text: string[];
}

interface Time

Each time formatted object is encoded in the following way:

{
  hours: number;
  minutes: number;
  seconds: number;
  ms: number;
  totals: {
    inSeconds: number;
  };
}

Package Sidebar

Install

npm i simple-subtitle-parser

Weekly Downloads

1,070

Version

2.0.0

License

GPL-3.0

Unpacked Size

41.1 kB

Total Files

24

Last publish

Collaborators

  • francospeziali