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

@qgustavor/srt-parser

v2.0.0

Published

Parse SRT into array

Downloads

403

Readme

@qgustavor/srt-parser

Just other SRT parser for JavaScript: it reads an .srt file into an array! Also, a fork of srt-parser-2 with so many changes that it will never be merged!

Usage

If you are using Node or a bundler you need to install using the following command:

npm install @qgustavor/srt-parser

If you are not using npm but yarn, or pnpm or something else you probably know how to convert the npm command to the one your tool uses.

import SrtParser from '@qgustavor/srt-parser'

const srt = `
1
00:00:11,544 --> 00:00:12,682
Hello
`

const parser = new SrtParser()
const parsed = parser.fromSrt(srt)
console.log(parsed)

If you are using Deno just add the npm: prefix to the import.

It will return something like this:

[{
  id: '1',
  startTime: '00:00:11,544',
  endTime: '00:00:12,682',
  text: 'Hello'
}]

To turn array back to SRT string, do the following:

const stringified = parser.toSrt(parsed)
console.log(stringified)

If you want timestamps as numbers (in seconds) instead of strings use the following:

const parser = new SrtParser({
  numericTimestamps: true
})

Environment support

Since it only process text, it should work in most JavaScript environments.

CLI

npx @qgustavor/srt-parser -i input.srt -o output.json --minify

Options:

| Option | Required | Default | | -------------- | -------- | ----------- | | --input or -i | Yes | | | --output or -o | No | output.json | | --minify | No | false |

License

MIT

Why?

Besides the issues on other SRT parsers listed by srt-parser-2, srt-parser-2 also have some issues:

  • The developer does not have time to work on the project.
  • The way it handles numeric timestamps is not clear, leads to foot guns and it's hard to fix without a major breaking change.
  • I don't like the typos in the README, nor the mixed snake and camel cases, nor semicolons.
  • I don't like the docs folder (looks like it came from a template, some of it was in Chinese), neither the examples folder (they differ from the README).
  • I don't like the use of var neither the lack of a code style linter.
  • To be fair I don't like the use of constructors since the parser is not stateful, but rewritting it is hard, so fixing it will be left as a task to the next fork.