npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

srtparse

v0.0.8

Published

Easy parsing of .srt ([SubRip Text](https://wikipedia.org/wiki/SubRip)) subtitle files.

Downloads

2

Readme

srtparse

Easy parsing of .srt (SubRip Text) subtitle files.

Usage

  • Import the module and you can get access to the FileParser class.
  • Initialise a FileParser with the path to your subtitle file and call parse().
  • You get a promise which resolves when parsing is complete, at which point your FileParser will be populated with subtitles, accessible via getSubtitles().
// Require FileParser
var srt = require('srtparse');

// Create a new FileParser
var fp = new srt.FileParser('/path/to/my/file.srt');
// Parse file
fp.parse().then(function () {
  console.log('Parsed ' + fp.getSubtitles().length + ' subtitles!');
}).catch(console.error);

Reference

FileParser

FileParser(String pathToSRT)

Initialise a new FileParser with a path to your SRT file.

getFilePath() -> String

Return the file path you initialised the FileParser with.

getSubtitles() -> [Subtitle]

Return the list of parsed Subtitle instances after parsing.

parse() -> Promise([Subtitle])

Promises to parse the entire file which you gave the FileParser on initialisation. Also resolves with the parsed Subtitles for ease of access.

Subtitle

Subtitle()

Initialise a new empty Subtitle instance.

getEndTime() -> Time

Return this subtitle's start time as a Time instance.

getIndex() -> Number

Return this subtitle's index number.

getText() -> [String]

Return this subtitle's text as an array of strings, each representing one line in the SRT.

getTextAsString() -> String

Return this subtitle's text list as a newline-joined string.

getEndTime() -> Time

Return this subtitle's end time as a Time instance.

addText(String textLine)

Add a line of text to this subtitle's text list.

setText([String] textLines)

Set this subtitle's text list to the given one.

setEndTime(Time endTime)

Set this subtitle's end time to the given Time.

setIndex(Number index)

Set this subtitle's index number to the given one.

setStartTime(Time startTime)

Set this subtitle's start time to the given Time.

toSRTString() -> String

Returns a representation of this subtitle ready for insertion into a .srt file.

zero() -> Subtitle

Return a new Subtitle instance which is a duplicate of this one, but with start time at 00:00:00,000, end time adjusted accordingly to keep the same duration, and index set to 1. Does not modify this instance.

Time

Time(Number|String hour, Number|String minute, Number|String second, Number|String milli)

Initialise a new Time instance with the given values.

[static] Time.fromSeconds(Number seconds) -> Time

Create a new Time instance from a given number of seconds. For example, Time.fromSeconds(3661.111) would give the time 01:01:01,111.

getHour() -> Number

Return this Time instance's hour.

getMilli() -> Number

Return this Time instance's milliseconds.

getMinute() -> Number

Return this Time instance's minute.

getSecond() -> Number

Return this Time instance's second.

toSeconds() -> Number

Return this Time as an absolute number of seconds (including milliseconds).

toSRTString() -> String

Return this time in its SRT representation (eg 12:34:56,789).