diff --git a/package.json b/package.json index 969cd2b..a5edb85 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.9.4", "description": "WebVTT parser, compiler, and segmenter with HLS support", "main": "index.js", + "types": "types.d.ts", "scripts": { "eslint": "eslint *.js **/*.js", "test": "npm run eslint -s && nyc mocha -R dot" diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 0000000..a2879a9 --- /dev/null +++ b/types.d.ts @@ -0,0 +1,79 @@ +export type ParseOptions = { + /** + * if true, will parse the WebVTT metadata. + * + * if false, will throw if the WebVTT metadata exists. + */ + meta?: boolean; + strict?: boolean; +}; + +export type Cue = { + identifier: string; + start: number; + end: number; + text: string; + styles: string; +}; + +export type Meta = Record; + +export type ParseOutput = { + valid: boolean; + strict: T["strict"] extends boolean ? T["strict"] : boolean; + cues: Cue[]; + errors: unknown[]; +} & (T extends { meta: true } ? Meta : {}); + +export function parse( + input: string, + options?: O +): ParseOutput; + +export type CompileInput = { + valid: boolean; + meta?: Meta; + cues: Cue[]; +}; + +export function compile(input: CompileInput): string; + +type Segment = { + cues: Cue[]; + duration: number; +}; + +export function segment( + input: string, + segmentLength?: number | undefined +): Segment[]; + +type HlsSegment = { + filename: string; + content: string; +}; + +declare function hlsSegment( + input: string, + segmentLength?: number | undefined, + startOffset?: string | undefined +): HlsSegment[]; + +declare function hlsSegmentPlaylist( + input: string, + segmentLength?: number | undefined +): string; + +export const hls: { + hlsSegment: typeof hlsSegment; + hlsSegmentPlaylist: typeof hlsSegmentPlaylist; +}; + +declare const _default: { + parse: typeof parse; + compile: typeof compile; + segment: typeof segment; + hls: typeof hls; +}; + +export default _default;