@srtkit/core
v0.0.5
Published
A set of utilities for processing and manipulating SRT (SubRip Text) subtitle files.
Downloads
14
Readme
@srtkit/core
Core utilities for processing SRT files.
Installation
# ✨ Auto-detect
npx nypm install @srtkit/core
# npm
npm install @srtkit/core
# yarn
yarn add @srtkit/core
# pnpm
pnpm add @srtkit/core
# bun
bun install @srtkit/core
# deno
deno install npm:@srtkit/coreUsage
SRT Parsing and Stringifying
We provide a simple wrapper around srt-parser-2, making it smoother to process SRT files with @srtkit/core.
import { SRT, type Subtitle, type SubtitleEntry } from '@srtkit/core'
const subtitles = SRT.parse(srtString) // Parse SRT string to array of subtitle objects
const srtString = SRT.stringify(subtitles) // Stringify array of subtitle objects to SRT stringFeatures
We offer a range of utility functions for subtitle processing. Each function operates on subtitle objects, so you should first parse your SRT string into subtitle objects, apply the desired feature function(s), and then convert the processed objects back to an SRT string.
Example workflow:
import { SRT } from '@srtkit/core'
import { cleanBasic } from '@srtkit/core/features'
const subtitles = SRT.parse(srtString) // Parse SRT string to objects
const cleaned = cleanBasic(subtitles) // Apply feature function
const resultSrt = SRT.stringify(cleaned) // Convert back to SRT string
console.log(resultSrt)cleanBasic(subtitle, options?)
Clean basic subtitle issues. By default, only trims whitespace.
cleanBetween(subtitle, options?)
Clean text between specified delimiters. By default, does nothing.
cleanFormatting(subtitle, options?)
Clean formatting from subtitle cues. By default, does nothing.
mergeSubtitles(a, b, mode)
Merge two monolingual subtitles into a bilingual subtitle.
Modes:
simple: Assumes both subtitle arrays have entries aligned by time range.
Merges each pair of entries by combining their text, separated by a newline,
using the longer subtitle array as the base.
splitSubtitle(subtitle, mode)
Split a bilingual subtitle into two monolingual subtitles.
Modes:
newline: Split by the first '\n' in each entry's textevenOdd: Odd indices -> Language A, Even indices -> Language B
License
🤖 auto updated with automd
