A set of utilities for processing and manipulating SRT (SubRip Text) subtitle files.
npm install @srtkit/core



Core utilities for processing SRT files.
``sh✨ Auto-detect
npx nypm install @srtkit/core
Usage
$3
We provide a simple wrapper around srt-parser-2, making it smoother to process SRT files with
@srtkit/core.`ts
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 string
`$3
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:
`ts
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 text-
evenOdd`: Odd indices -> Language A, Even indices -> Language B---
_🤖 auto updated with automd_