simple-subtitle-parser
v2.0.0
Published
_(previously, subtitle-parsing-tool)_
Downloads
5,062
Maintainers
Readme
Simple Subtitle Parser
(previously, subtitle-parsing-tool)
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;
};
}