diff --git a/types/subtitle/index.d.ts b/types/subtitle/index.d.ts new file mode 100644 index 0000000000..f6048acc4a --- /dev/null +++ b/types/subtitle/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for subtitle 2.0 +// Project: https://github.com/gsantiago/subtitle.js#readme +// Definitions by: Low Jeng Lam +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface subTitleType { + start: number | string; + end: number | string; + text: string; + setting?: string; +} + +export function parse(srtOrVtt: string): subTitleType[]; +export function stringify(captions: ReadonlyArray): string; +export function resync(captions: ReadonlyArray, time: number): subTitleType[]; +export function toMs(timestamp: string): number; +export function toSrtTime(timestamp: number): string; +export function toVttTime(timestamp: number): string; diff --git a/types/subtitle/subtitle-tests.ts b/types/subtitle/subtitle-tests.ts new file mode 100644 index 0000000000..2f733b4a54 --- /dev/null +++ b/types/subtitle/subtitle-tests.ts @@ -0,0 +1,27 @@ +import * as Subtitle from 'subtitle'; + +Subtitle.parse(""); + +const subtitles = [ + { + start: '00:00:20,000', + end: '00:00:24,400', + text: 'Bla Bla Bla Bla' + }, + { + start: 24600, + end: 27800, + text: 'Bla Bla Bla Bla', + settings: 'align:middle line:90%' + } + ]; + +const srt = Subtitle.stringify(subtitles); + +const newSubtitles: Subtitle.subTitleType[] = Subtitle.resync(subtitles, 1000); + +Subtitle.toMs('00:00:24,400'); + +Subtitle.toSrtTime(24400); + +Subtitle.toVttTime(24400); diff --git a/types/subtitle/tsconfig.json b/types/subtitle/tsconfig.json new file mode 100644 index 0000000000..b4463890d2 --- /dev/null +++ b/types/subtitle/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "subtitle-tests.ts" + ] +} diff --git a/types/subtitle/tslint.json b/types/subtitle/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/subtitle/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }