From 7b06b52aa96288048868eef43422da61268cd66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=95=98=EB=8F=84=EC=98=81?= Date: Sat, 29 Jun 2019 00:33:17 +0900 Subject: [PATCH] [smpte-timecode] add new type definition (#36503) * add smpte-timecode type definitions and tests * modify reference types * set strictNullChecks to true * remove unnecessary rule --- types/smpte-timecode/index.d.ts | 41 +++++++ types/smpte-timecode/smpte-timecode-tests.ts | 109 +++++++++++++++++++ types/smpte-timecode/tsconfig.json | 23 ++++ types/smpte-timecode/tslint.json | 5 + 4 files changed, 178 insertions(+) create mode 100644 types/smpte-timecode/index.d.ts create mode 100644 types/smpte-timecode/smpte-timecode-tests.ts create mode 100644 types/smpte-timecode/tsconfig.json create mode 100644 types/smpte-timecode/tslint.json diff --git a/types/smpte-timecode/index.d.ts b/types/smpte-timecode/index.d.ts new file mode 100644 index 0000000000..a1f42b4567 --- /dev/null +++ b/types/smpte-timecode/index.d.ts @@ -0,0 +1,41 @@ +// Type definitions for smpte-timecode 1.2 +// Project: https://github.com/CrystalComputerCorp/smpte-timecode +// Definitions by: DoYoung Ha +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare const Timecode: { + (timecode?: Timecode.TIMECODE, frameRate?: Timecode.FRAMERATE, dropFrame?: boolean): Timecode.TimecodeInstance; + new (timecode?: Timecode.TIMECODE, frameRate?: Timecode.FRAMERATE, dropFrame?: boolean): Timecode.TimecodeInstance; +}; + +declare namespace Timecode { + type TIMECODE = number | string | Date | TimecodeObject; + type FRAMERATE = 23.976 | 24 | 25 | 29.97 | 30 | 50 | 59.94 | 60; + + interface TimecodeObject { + hours: number; + minutes: number; + seconds: number; + frames: number; + } + + interface TimecodeInstance { + add(timecode: TIMECODE, negative?: boolean, rollOverMaxHours?: number): TimecodeInstance; + subtract(timecode: TIMECODE, rollOverMaxHours?: number): TimecodeInstance; + toDate(): Date; + toString(options?: string): string; + valueOf(): number; + + hours: number; + minutes: number; + seconds: number; + frames: number; + dropFrame: boolean; + frameCount: number; + frameRate: number; + } +} + +export = Timecode; diff --git a/types/smpte-timecode/smpte-timecode-tests.ts b/types/smpte-timecode/smpte-timecode-tests.ts new file mode 100644 index 0000000000..9947af362a --- /dev/null +++ b/types/smpte-timecode/smpte-timecode-tests.ts @@ -0,0 +1,109 @@ +import * as Timecode from 'smpte-timecode'; + +let t: Timecode.TimecodeInstance; +let t2: Timecode.TimecodeInstance; + +// https://github.com/CrystalComputerCorp/smpte-timecode#usage +t = Timecode('00:15:10;03'); +t.add('00:02:30;00'); +t.subtract(100); + +// https://github.com/CrystalComputerCorp/smpte-timecode#creating-timecode-objects +t = new Timecode('00:01:00:00'); +t = new Timecode(800, 29.97, true); +t = new Timecode(new Date()); + +// https://github.com/CrystalComputerCorp/smpte-timecode/blob/master/test/smpte-timecode-test.js +Timecode(100); +Timecode(3); +Timecode(15); +Timecode(323.443); + +t = new Timecode('12:33:44;12'); +t.hours; +t.minutes; +t.seconds; +t.frames; +t.dropFrame; +t.frameRate; + +t = new Timecode({ hours: 12, minutes: 34, seconds: 56, frames: 2 }); +Timecode(1); +Timecode(1, 29.97); +Timecode(1, 59.94); +Timecode(1, 25); + +// https://github.com/CrystalComputerCorp/smpte-timecode/blob/84cfe22eb217f1a60cb7a7dfc1dde0353121073c/test/smpte-timecode-test.js#L75 +Timecode('00:10:00;00').frameCount; +Timecode('00:10:00;00', 59.94).frameCount; +Timecode('10:00:00;00').frameCount; +Timecode('10:00:00;00', 59.94).frameCount; +Timecode('00:02:00;02'); +Timecode('00:02:00;04', 59.94); +Timecode('00:01:59;29').frameCount; +Timecode('00:01:59;59', 59.94).frameCount; +Timecode(17982, 29.97, true).toString(); +Timecode(1078920, 29.97, true).toString(); +Timecode(3597, 29.97, true).toString(); +Timecode(17982 * 2, 59.94, true).toString(); +Timecode(1078920 * 2, 59.94, true).toString(); +Timecode(3597 * 2 + 1, 59.94, true).toString(); + +// https://github.com/CrystalComputerCorp/smpte-timecode/blob/84cfe22eb217f1a60cb7a7dfc1dde0353121073c/test/smpte-timecode-test.js#L94 +Timecode('00:10:00:00', 25).frameCount; +Timecode('10:00:00:00', 25).frameCount; +Timecode('00:02:00:00', 25).frameCount; +Timecode('00:01:59:24', 25).frameCount; +Timecode(15000, 25).toString(); +Timecode(900000, 25).toString(); +Timecode(2999, 25).toString(); + +// https://github.com/CrystalComputerCorp/smpte-timecode/blob/84cfe22eb217f1a60cb7a7dfc1dde0353121073c/test/smpte-timecode-test.js#L105 +Timecode('12:34:56;23').toString(); +Timecode('01:02:03;04').toString(); +Timecode('12:34:56;57', 59.94).toString(); +Timecode('01:02:03;04', 59.94).toString(); +Timecode('12:34:56;23').toString('field'); +Timecode('01:02:03;04').toString('field'); +Timecode('12:34:56;57', 59.94).toString('field'); +Timecode('01:02:03;04', 59.94).toString('field'); + +// https://github.com/CrystalComputerCorp/smpte-timecode/blob/84cfe22eb217f1a60cb7a7dfc1dde0353121073c/test/smpte-timecode-test.js#L139 +t = Timecode('01:23:45;06'); +t.add(60).toString(); +Timecode('23:59:40;00') + .add(Timecode('00:00:21;00')) + .toString(); + +t = Timecode('01:23:45;06'); +t.subtract(60).toString(); + +Timecode('01:23:45;06') + .add('01:23:13;01') + .toString(); + +t = Timecode('00:01:15;00'); +t2 = Timecode('00:01:15;00'); +t2.add(0); +t.frameCount; +t2.add(12345); +t.frameCount; + +new Timecode().subtract(new Timecode('23:30:00;00'), 1).toString(); +new Timecode('01:00:00;00').subtract(new Timecode('23:30:00;00'), 2).toString(); +new Timecode('00:00:00:00', 25, false).add('00:01:00:00').frameCount; + +// https://github.com/CrystalComputerCorp/smpte-timecode/blob/84cfe22eb217f1a60cb7a7dfc1dde0353121073c/test/smpte-timecode-test.js#L170 +t = new Timecode(new Date(0, 0, 0, 1, 2, 13, 200), 29.97, true); +t.frameCount; +t.toString(); + +t2 = new Timecode(new Date(0, 0, 0, 10, 40, 15, 520), 25, false); +t2.frameCount; +t2.toString(); + +const d: Date = Timecode('01:23:45;10').toDate(); +d.getHours(); +d.getMinutes(); +d.getSeconds(); +d.getMilliseconds(); diff --git a/types/smpte-timecode/tsconfig.json b/types/smpte-timecode/tsconfig.json new file mode 100644 index 0000000000..8d9646742b --- /dev/null +++ b/types/smpte-timecode/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", + "smpte-timecode-tests.ts" + ] +} diff --git a/types/smpte-timecode/tslint.json b/types/smpte-timecode/tslint.json new file mode 100644 index 0000000000..495d29983d --- /dev/null +++ b/types/smpte-timecode/tslint.json @@ -0,0 +1,5 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + } +}