diff --git a/types/jquery-countdown/index.d.ts b/types/jquery-countdown/index.d.ts new file mode 100644 index 0000000000..38a411c524 --- /dev/null +++ b/types/jquery-countdown/index.d.ts @@ -0,0 +1,147 @@ +// Type definitions for jQuery Countdown 2.2 +// Project: https://github.com/hilios/jQuery.countdown +// Definitions by: Anderson Friaça +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +declare namespace jQueryCountdown { + interface Options { + /** + * Allow to continue after finishes + */ + elapse?: boolean; + + /** + * The update rate in milliseconds + */ + precision?: number; + + /** + * Deferred initialization mode + */ + defer?: boolean; + } + + interface Event extends JQuery.Event { + /** + * The namespaced event type + */ + type: string; + + /** + * The formatter function + */ + strftime: ((format: string) => string); + + /** + * The parsed final date native object + */ + finalDate: Date; + + /** + * Passed away the final date? + */ + elapsed: boolean; + + offset: OffsetEvent; + } + + interface OffsetEvent { + /** + * Seconds left for the next minute + */ + seconds: number; + + /** + * Minutes left for the next hour + */ + minutes: number; + + /** + * Hours left until next day + */ + hours: number; + + /** + * Days left until next week + */ + days: number; + + /** + * Days left until next week + */ + daysToWeek: number; + + /** + * Days left until next month + */ + daysToMonth: number; + + /** + * Weeks left until the final date + */ + weeks: number; + + /** + * Weeks left until the next month + */ + weeksToMonth: number; + + /** + * Months left until final date + */ + months: number; + + /** + * Years left until final date + */ + years: number; + + /** + * Total amount of days left until final date + */ + totalDays: number; + + /** + * Total amount of hours left until final date + */ + totalHours: number; + + /** + * Total amount of minutes left until final date + */ + totalMinutes: number; + + /** + * Total amount of seconds left until final date + */ + totalSeconds: number; + } + + type Methods = 'update.countdown' | 'finish.countdown' | 'stop.countdown'; + + type Controls = 'start' | 'stop' | 'pause' | 'resume'; +} +interface JQuery { + /** + * Initialize the countdown + */ + countdown(finalDate: string, callback?: ((event: jQueryCountdown.Event) => void)): JQuery; + + /** + * Initialize the countdown with options + */ + countdown(finalDate: string, options: jQueryCountdown.Options, callback?: ((event: jQueryCountdown.Event) => void)): JQuery; + + /** + * Methods to control the execution flow of countdown + */ + countdown(control: jQueryCountdown.Controls): JQuery; + + /** + * Trigger an event whenever some state change + */ + on(method: jQueryCountdown.Methods, callback: ((event: jQueryCountdown.Event) => void)): JQuery; +} diff --git a/types/jquery-countdown/jquery-countdown-tests.ts b/types/jquery-countdown/jquery-countdown-tests.ts new file mode 100644 index 0000000000..a93b734659 --- /dev/null +++ b/types/jquery-countdown/jquery-countdown-tests.ts @@ -0,0 +1,33 @@ +// basic usage +$(document).ready(() => { + $('#countdown').countdown('2019/01/01'); + + // with options + $('#countdown').countdown('2019/01/01', { + elapse: true + }); + + // with options and callback + $('#countdown').countdown('2019/01/01', { + elapse: true + }, event => { + $('#countdown').html(event.strftime('%w weeks %d days %H:%M:%S')); + }); + + // Methods + $('#countdown').on('update.countdown', (event => { + $('#countdown').html(event.strftime('%w weeks %d days %H:%M:%S')); + })); + $('#countdown').on('finish.countdown', (event => { + $('#countdown').html(event.strftime('%w weeks %d days %H:%M:%S')); + })); + $('#countdown').on('stop.countdown', (event => { + $('#countdown').html(event.strftime('%w weeks %d days %H:%M:%S')); + })); + + // Controls + $('#countdown').countdown('start'); + $('#countdown').countdown('stop'); + $('#countdown').countdown('pause'); + $('#countdown').countdown('resume'); +}); diff --git a/types/jquery-countdown/tsconfig.json b/types/jquery-countdown/tsconfig.json new file mode 100644 index 0000000000..48c8d25647 --- /dev/null +++ b/types/jquery-countdown/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "jquery-countdown-tests.ts" + ] +} \ No newline at end of file diff --git a/types/jquery-countdown/tslint.json b/types/jquery-countdown/tslint.json new file mode 100644 index 0000000000..d04fe2e1fa --- /dev/null +++ b/types/jquery-countdown/tslint.json @@ -0,0 +1 @@ +{"extends": "dtslint/dt.json"} \ No newline at end of file