Merge pull request #24652 from AndersonFriaca/jquery-countto

Types for JQuery CountTo
This commit is contained in:
Paul van Brenk
2018-04-03 12:40:19 -07:00
committed by GitHub
4 changed files with 112 additions and 0 deletions

57
types/jquery-countto/index.d.ts vendored Normal file
View File

@@ -0,0 +1,57 @@
// Type definitions for JQuery CountTo 1.2
// Project: https://github.com/mhuggins/jquery-countTo
// Definitions by: Anderson Friaça <https://github.com/AndersonFriaca>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="jquery" />
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;
}
}

View File

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

View File

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

View File

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