From b4e6e495f88fae0937aeb1b48524220a1a1dc61e Mon Sep 17 00:00:00 2001 From: AndersonFriaca Date: Sat, 31 Mar 2018 01:28:40 -0400 Subject: [PATCH 1/3] Types for JQuery CountTo --- types/jquery-countto/index.d.ts | 57 ++++++++++++++++++++ types/jquery-countto/jquery.countto-tests.ts | 29 ++++++++++ types/jquery-countto/tsconfig.json | 25 +++++++++ types/jquery-countto/tslint.json | 1 + 4 files changed, 112 insertions(+) create mode 100644 types/jquery-countto/index.d.ts create mode 100644 types/jquery-countto/jquery.countto-tests.ts create mode 100644 types/jquery-countto/tsconfig.json create mode 100644 types/jquery-countto/tslint.json diff --git a/types/jquery-countto/index.d.ts b/types/jquery-countto/index.d.ts new file mode 100644 index 0000000000..a215abb7d4 --- /dev/null +++ b/types/jquery-countto/index.d.ts @@ -0,0 +1,57 @@ +// Type definitions for JQuery CountTo 1.2 +// Project: https://github.com/mhuggins/jquery-countTo +// Definitions by: Anderson Friaça +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +/// + +export interface Options { + /** + * The number to start counting from + */ + from?: number; + + /** + * The number to stop counting at + */ + to?: number; + + /** + * The number of milliseconds it should take to finish counting + */ + speed?: number; + + /** + * he number of milliseconds to wait between refreshing the counter + */ + refreshInterval?: number; + + /** + * The number of decimal places to show when using the default formatter + */ + decimals?: number; + + /** + * A handler that is used to format the current value before rendering to the DOM + */ + formatter: (value: number, options: Options) => string; + + /** + * A callback function that is triggered for every iteration that the counter updates + */ + onUpdate?: (value: number) => void; + + /** + * A callback function that is triggered when counting finishes + */ + onComplete?: (value: number) => void; +} + +export type Method = 'start' | 'stop' | 'toggle' | 'restart'; + +declare global { + interface JQuery { + countTo(methodOrOptions?: Method | Options): JQuery; + } +} diff --git a/types/jquery-countto/jquery.countto-tests.ts b/types/jquery-countto/jquery.countto-tests.ts new file mode 100644 index 0000000000..0bc7998f56 --- /dev/null +++ b/types/jquery-countto/jquery.countto-tests.ts @@ -0,0 +1,29 @@ +import { Options } from "jquery-countto"; + +// Basic usage +$('.timer').countTo(); + +// With options +const options: Options = { + from: 50, + to: 2500, + speed: 1000, + refreshInterval: 50, + formatter: (value: number, options: Options) => { + return value.toFixed(options.decimals); + }, + onUpdate: (value: number) => { + console.log(value); + }, + onComplete: (value: number) => { + console.log(value); + } + }; + +$('.timer').countTo(options); + +// Controls +$('.timer').countTo('start'); +$('.timer').countTo('stop'); +$('.timer').countTo('restart'); +$('.timer').countTo('toggle'); diff --git a/types/jquery-countto/tsconfig.json b/types/jquery-countto/tsconfig.json new file mode 100644 index 0000000000..855047ba62 --- /dev/null +++ b/types/jquery-countto/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.countto-tests.ts" + ] +} \ No newline at end of file diff --git a/types/jquery-countto/tslint.json b/types/jquery-countto/tslint.json new file mode 100644 index 0000000000..d04fe2e1fa --- /dev/null +++ b/types/jquery-countto/tslint.json @@ -0,0 +1 @@ +{"extends": "dtslint/dt.json"} \ No newline at end of file From 4fab9de846d523cebe95f91e0c2b65837e0a981a Mon Sep 17 00:00:00 2001 From: AndersonFriaca Date: Sat, 31 Mar 2018 01:40:25 -0400 Subject: [PATCH 2/3] Adjustments --- .../{jquery.countto-tests.ts => jquery-countto-tests.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename types/jquery-countto/{jquery.countto-tests.ts => jquery-countto-tests.ts} (100%) diff --git a/types/jquery-countto/jquery.countto-tests.ts b/types/jquery-countto/jquery-countto-tests.ts similarity index 100% rename from types/jquery-countto/jquery.countto-tests.ts rename to types/jquery-countto/jquery-countto-tests.ts From cd5f204c1143c8dc63055ca32e596f5544fe35b1 Mon Sep 17 00:00:00 2001 From: AndersonFriaca Date: Sat, 31 Mar 2018 01:49:26 -0400 Subject: [PATCH 3/3] Adjustments --- types/jquery-countto/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/jquery-countto/tsconfig.json b/types/jquery-countto/tsconfig.json index 855047ba62..3d5cf520dd 100644 --- a/types/jquery-countto/tsconfig.json +++ b/types/jquery-countto/tsconfig.json @@ -20,6 +20,6 @@ }, "files": [ "index.d.ts", - "jquery.countto-tests.ts" + "jquery-countto-tests.ts" ] } \ No newline at end of file