Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add type definitions #157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
79 changes: 79 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>;

export type ParseOutput<T extends ParseOptions> = {
valid: boolean;
strict: T["strict"] extends boolean ? T["strict"] : boolean;
cues: Cue[];
errors: unknown[];
} & (T extends { meta: true } ? Meta : {});

export function parse<O extends ParseOptions>(
input: string,
options?: O
): ParseOutput<O>;

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;