Add subtitle definition

This commit is contained in:
Low Jeng Lam
2018-10-30 12:24:33 +08:00
parent 3d82362c03
commit 859cf71dfd
4 changed files with 69 additions and 0 deletions

18
types/subtitle/index.d.ts vendored Normal file
View File

@@ -0,0 +1,18 @@
// Type definitions for subtitle 2.0
// Project: https://github.com/gsantiago/subtitle.js#readme
// Definitions by: Low Jeng Lam <https://github.com/jenglamlow>
// 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<subTitleType>): string;
export function resync(captions: ReadonlyArray<subTitleType>, time: number): subTitleType[];
export function toMs(timestamp: string): number;
export function toSrtTime(timestamp: number): string;
export function toVttTime(timestamp: number): string;

View File

@@ -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);

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }