Skip to content

KR-onae/srt-parse-to

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Srt-Parse-To

This is Srt Parser from KRonae (Github KR-onae). Using this, convert the srt file to JSON, Again you can turn JSON into srt file.

How to use

1. Installation

After installing npm, running the following code will install srt-parse-to.

npm install srt-parse-to

Alternatively, you can also use the code below.

npm i srt-parse-to

2. Usage - To JSON

The following code converts the srt code called srtFileSource into JSON and outputs it.

const srt = require("srt-parse-to");

var srtFileSource = `1
00:00:00,500 --> 00:00:03,400
Hello!

2
00:00:03,500 --> 00:00:06,200
World!`;

console.log(srt.toJSON(srtFileSource));

However, the code below is shorter and more concise than the code above.

const srt = require("srt-parse-to");

var srtFileSource = `1
00:00:00,500 --> 00:00:03,400
Hello!

2
00:00:03,500 --> 00:00:06,200
World!`;

console.log(srtFileSource.srtToJSON());

Parse the Srt code into JSON using 'String.prototype.srtToJSON()' or 'Buffer.prototype.srtToJSON()'.

2. Usage - To Srt

The following code converts the srt code called srtFileSource into JSON and outputs it.

const srt = require("srt-parse-to");

var srtFileSource = `1
00:00:00,500 --> 00:00:03,400
Hello!

2
00:00:03,500 --> 00:00:06,200
World!`;

var json = srtFileSource.srtToJSON();
console.log(srt.toSrt(json));

You can shorten this code too.

const srt = require("srt-parse-to");

var srtFileSource = `1
00:00:00,500 --> 00:00:03,400
Hello!

2
00:00:03,500 --> 00:00:06,200
World!`;

var json = srtFileSource.srtToJSON();
console.log(json.JSONToSrt());

Parse JSON into Srt code using 'Object.prototype.JSONToSrt()' .