<h1 align="center">SrtValidator</h1>
npm install srt-validator[![npm][npm]][npm-url]
[![node][node]][node-url]
[![issues][issues]][issues-url]
[![license][license]][license-url]
[![jest][jest]][jest-url]
[![codecov][codecov]][codecov-url]
[![code-style][code-style]][code-style-url]
[![build-and-test][build-and-test]][build-and-test-url]
[![publish-to-npm][publish-to-npm]][publish-to-npm-url]
``bash`
yarn add srt-validator
Or
`bash`
npm install srt-validator --save
SRT file (also known as SubRip Subtitle file) is a plain-text file that contains subtitles with the start and end timecodes of the text to ensure the subtitles match the audio. It also inclues the sequential number of subtitles. A sample SRT looks like this:
`srt
1
00:02:17,440 --> 00:02:20,375
Senator, we're making
our final approach into Coruscant.
2
00:02:20,476 --> 00:02:22,501
Very good, Lieutenant.
`
This library only exposes a single util function srtValidator(input) which takes a string as an input and validates it against the [SRT spec][srt-spec]. The output of this function is an array of error objects. If the array is empty then there are no errors and the SRT is valid.
`js
import srtValidator from 'srt-validator';
const srtString = 1
00:02:17,440 --> 00:02:20,375
Senator, we're making
our final approach into Coruscant.
2
00:02:20,476 --> 00:02:22,501
Very good, Lieutenant.;
srtValidator(srtString);
`
This will return:
`js`
[];
`js
import srtValidator from 'srt-validator';
const srtString = 1
02:01:17,440 --> 02:00:20,375
Forget it, Jake.
It's Chinatown.;
srtValidator(srtString);
`
This will return:
`js``
[
{
errorCode: 'validatorErrorStartTime',
lineNumber: 2,
message: 'start time should be less than end time',
validator: 'CaptionTimeSpanValidator',
},
];
- [Type of Errors][types-of-errors]
- [How to debug][how-to-debug]
- _The SRT icon in this file is made by iconixar from Flaticon_
[npm]: https://img.shields.io/npm/v/srt-validator.svg
[npm-url]: https://www.npmjs.com/package/srt-validator
[node]: https://img.shields.io/node/v/srt-validator.svg
[node-url]: https://nodejs.org
[issues]: https://img.shields.io/github/issues/taoning2014/srt-validator
[issues-url]: https://github.com/taoning2014/srt-validator/issues
[license]: https://img.shields.io/github/license/taoning2014/srt-validator
[license-url]: ./LICENSE
[jest]: https://img.shields.io/badge/tested_with-jest-99424f.svg
[jest-url]: https://github.com/facebook/jest
[codecov]: https://codecov.io/gh/taoning2014/srt-validator/branch/master/graph/badge.svg?token=rnNON8Fd6g
[codecov-url]: https://app.codecov.io/gh/taoning2014/srt-validator
[build-and-test]: https://github.com/taoning2014/srt-validator/actions/workflows/build-and-test.yaml/badge.svg
[publish-to-npm]: https://github.com/taoning2014/srt-validator/actions/workflows/publish-to-npm.yaml/badge.svg
[build-and-test-url]: https://github.com/taoning2014/srt-validator/actions/workflows/build-and-test.yaml
[publish-to-npm-url]: https://github.com/taoning2014/srt-validator/actions/workflows/publish-to-npm.yaml
[code-style]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg
[code-style-url]: https://github.com/prettier/prettier
[srt-spec]: ./doc/srt-spec.md
[types-of-errors]: ./doc/types-of-errors.md
[how-to-debug]: ./doc/how-to-debug.md