From 5f755e7938ad3da1ce7705c3b640f575e3e34f34 Mon Sep 17 00:00:00 2001 From: Gabriel JUCHAULT Date: Thu, 21 Jul 2016 15:22:00 +0200 Subject: [PATCH 1/5] Countdown.js --- countdown/countdown-tests.ts | 47 ++++++++++++++++++++++++ countdown/countdown.d.ts | 69 ++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 countdown/countdown-tests.ts create mode 100644 countdown/countdown.d.ts diff --git a/countdown/countdown-tests.ts b/countdown/countdown-tests.ts new file mode 100644 index 0000000000..900d2d6652 --- /dev/null +++ b/countdown/countdown-tests.ts @@ -0,0 +1,47 @@ +// Type definitions for countdown.js +// Project: http://countdownjs.org/ +// Definitions by: Gabriel Juchault https://github.com/gjuchault +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { countdown, Timespan, CountdownStatic, Format } from 'countdown'; + +let ts: Timespan; +let interval: number; + +ts = countdown(new Date()); +ts = countdown(150); + +interval = countdown(new Date(), + function (ts: Timespan) { + document.getElementById('pageTimer').innerHTML = ts.toHTML('strong'); + }, + countdown.HOURS | countdown.MINUTES | countdown.SECONDS, + 2, + 2 +); + +clearInterval(interval); + +ts.toString('foo'); +ts.toHTML('em', 'foo'); + +countdown.resetFormat(); +countdown.setLabels('a', 'b', 'c', 'd', 'e'); + +countdown.setLabels('a', 'b', 'c', 'd', 'e', function (value: number): string { + return 'ok'; +}, function (value: number, unit: number): string { + return 'ok'; +}); + +countdown.setLabels(null, null, null, null, 'Now.'); + +countdown.setLabels( + ' millisecond| second| minute| hour| day| week| month| year| decade| century| millennium', + ' milliseconds| seconds| minutes| hours| days| weeks| months| years| decades| centuries| millennia', + ' and ', + ', ', + '', + n => n.toString()); diff --git a/countdown/countdown.d.ts b/countdown/countdown.d.ts new file mode 100644 index 0000000000..dd604a36f8 --- /dev/null +++ b/countdown/countdown.d.ts @@ -0,0 +1,69 @@ +// Type definitions for countdown.js +// Project: http://countdownjs.org/ +// Definitions by: Gabriel Juchault +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'countdown' { + export type DateFunction = (timespan: Timespan) => void; + export type DateTime = number | Date | DateFunction; + + export interface Timespan { + start?: Date; + end?: Date; + units?: number; + value?: number; + millennia?: number; + centuries?: number; + decades?: number; + years?: number; + months?: number; + days?: number; + hours?: number; + minutes?: number; + seconds?: number; + milliseconds?: number; + toString(label?: string): string; + toHTML(tagName?: string, label?: string): string; + } + + export interface Format { + singular?: string | Array; + plural?: string | Array; + last?: string; + delim?: string; + empty?: string; + formatNumber?(value: number): string; + formatter?(value: number, unit: number): string; + } + + export interface CountdownStatic { + (start: DateTime, end?: DateTime, units?: number, max?: number, digits?: number): Timespan | number; + MILLENNIA: number; + CENTURIES: number; + DECADES: number; + YEARS: number; + MONTHS: number; + WEEKS: number; + DAYS: number; + HOURS: number; + MINUTES: number; + SECONDS: number; + MILLISECONDS: number; + ALL: number; + DEFAULTS: number; + resetLabels(): void; + setLabels( + singular?: string, + plural?: string, + last?: string, + delim?: string, + empty?: string, + formatNumber?: (value: number) => string, + formatter?: (value: number, unit: number) => string + ): void; + resetFormat(): void; + setFormat(format: Format): void; + } + + export var countdown: CountdownStatic; +} From b140e9b8f238b277469930d82353b6c5316b09fd Mon Sep 17 00:00:00 2001 From: Gabriel JUCHAULT Date: Thu, 21 Jul 2016 15:25:12 +0200 Subject: [PATCH 2/5] Remove header tags from tests --- countdown/countdown-tests.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/countdown/countdown-tests.ts b/countdown/countdown-tests.ts index 900d2d6652..c803f1acc2 100644 --- a/countdown/countdown-tests.ts +++ b/countdown/countdown-tests.ts @@ -1,8 +1,3 @@ -// Type definitions for countdown.js -// Project: http://countdownjs.org/ -// Definitions by: Gabriel Juchault https://github.com/gjuchault -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - /// import { countdown, Timespan, CountdownStatic, Format } from 'countdown'; From 125a1e48c38c78c974bed09b04b82bbfb883b9ca Mon Sep 17 00:00:00 2001 From: Gabriel JUCHAULT Date: Fri, 22 Jul 2016 15:45:21 +0200 Subject: [PATCH 3/5] fix(countdownjs): removed var --- countdown/countdown.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/countdown/countdown.d.ts b/countdown/countdown.d.ts index dd604a36f8..5b40541dd0 100644 --- a/countdown/countdown.d.ts +++ b/countdown/countdown.d.ts @@ -65,5 +65,5 @@ declare module 'countdown' { setFormat(format: Format): void; } - export var countdown: CountdownStatic; + export let countdown: CountdownStatic; } From fe5c10be966bf1949ccd2811b430b0e666ff7829 Mon Sep 17 00:00:00 2001 From: Gabriel JUCHAULT Date: Tue, 23 Aug 2016 13:27:40 +0200 Subject: [PATCH 4/5] Fix countdown types --- countdown/countdown-tests.ts | 10 +++++----- countdown/countdown.d.ts | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/countdown/countdown-tests.ts b/countdown/countdown-tests.ts index c803f1acc2..3ad8890aab 100644 --- a/countdown/countdown-tests.ts +++ b/countdown/countdown-tests.ts @@ -1,15 +1,15 @@ /// -import { countdown, Timespan, CountdownStatic, Format } from 'countdown'; +import * as countdown from 'countdown'; -let ts: Timespan; +let ts: countdown.Timespan; let interval: number; -ts = countdown(new Date()); -ts = countdown(150); +ts = countdown(new Date()); +ts = countdown(150); interval = countdown(new Date(), - function (ts: Timespan) { + function (ts: countdown.Timespan) { document.getElementById('pageTimer').innerHTML = ts.toHTML('strong'); }, countdown.HOURS | countdown.MINUTES | countdown.SECONDS, diff --git a/countdown/countdown.d.ts b/countdown/countdown.d.ts index 5b40541dd0..bcb0d07976 100644 --- a/countdown/countdown.d.ts +++ b/countdown/countdown.d.ts @@ -3,11 +3,11 @@ // Definitions by: Gabriel Juchault // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module 'countdown' { - export type DateFunction = (timespan: Timespan) => void; - export type DateTime = number | Date | DateFunction; +declare namespace countdown { + type DateFunction = (timespan: Timespan) => void; + type DateTime = number | Date | DateFunction; - export interface Timespan { + interface Timespan { start?: Date; end?: Date; units?: number; @@ -26,7 +26,7 @@ declare module 'countdown' { toHTML(tagName?: string, label?: string): string; } - export interface Format { + interface Format { singular?: string | Array; plural?: string | Array; last?: string; @@ -36,7 +36,7 @@ declare module 'countdown' { formatter?(value: number, unit: number): string; } - export interface CountdownStatic { + interface CountdownStatic { (start: DateTime, end?: DateTime, units?: number, max?: number, digits?: number): Timespan | number; MILLENNIA: number; CENTURIES: number; @@ -64,6 +64,9 @@ declare module 'countdown' { resetFormat(): void; setFormat(format: Format): void; } - - export let countdown: CountdownStatic; +} + +declare module 'countdown' { + let countdown: countdown.CountdownStatic; + export = countdown; } From a6448a411a037ecfead7ba0f4d2eb24de8efce8b Mon Sep 17 00:00:00 2001 From: Gabriel JUCHAULT Date: Tue, 23 Aug 2016 13:27:40 +0200 Subject: [PATCH 5/5] Fix countdown types --- countdown/countdown-tests.ts | 10 +++++----- countdown/countdown.d.ts | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/countdown/countdown-tests.ts b/countdown/countdown-tests.ts index c803f1acc2..3ad8890aab 100644 --- a/countdown/countdown-tests.ts +++ b/countdown/countdown-tests.ts @@ -1,15 +1,15 @@ /// -import { countdown, Timespan, CountdownStatic, Format } from 'countdown'; +import * as countdown from 'countdown'; -let ts: Timespan; +let ts: countdown.Timespan; let interval: number; -ts = countdown(new Date()); -ts = countdown(150); +ts = countdown(new Date()); +ts = countdown(150); interval = countdown(new Date(), - function (ts: Timespan) { + function (ts: countdown.Timespan) { document.getElementById('pageTimer').innerHTML = ts.toHTML('strong'); }, countdown.HOURS | countdown.MINUTES | countdown.SECONDS, diff --git a/countdown/countdown.d.ts b/countdown/countdown.d.ts index 5b40541dd0..bcb0d07976 100644 --- a/countdown/countdown.d.ts +++ b/countdown/countdown.d.ts @@ -3,11 +3,11 @@ // Definitions by: Gabriel Juchault // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module 'countdown' { - export type DateFunction = (timespan: Timespan) => void; - export type DateTime = number | Date | DateFunction; +declare namespace countdown { + type DateFunction = (timespan: Timespan) => void; + type DateTime = number | Date | DateFunction; - export interface Timespan { + interface Timespan { start?: Date; end?: Date; units?: number; @@ -26,7 +26,7 @@ declare module 'countdown' { toHTML(tagName?: string, label?: string): string; } - export interface Format { + interface Format { singular?: string | Array; plural?: string | Array; last?: string; @@ -36,7 +36,7 @@ declare module 'countdown' { formatter?(value: number, unit: number): string; } - export interface CountdownStatic { + interface CountdownStatic { (start: DateTime, end?: DateTime, units?: number, max?: number, digits?: number): Timespan | number; MILLENNIA: number; CENTURIES: number; @@ -64,6 +64,9 @@ declare module 'countdown' { resetFormat(): void; setFormat(format: Format): void; } - - export let countdown: CountdownStatic; +} + +declare module 'countdown' { + let countdown: countdown.CountdownStatic; + export = countdown; }