mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
Merge pull request #24652 from AndersonFriaca/jquery-countto
Types for JQuery CountTo
This commit is contained in:
57
types/jquery-countto/index.d.ts
vendored
Normal file
57
types/jquery-countto/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
29
types/jquery-countto/jquery-countto-tests.ts
Normal file
29
types/jquery-countto/jquery-countto-tests.ts
Normal 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');
|
||||
25
types/jquery-countto/tsconfig.json
Normal file
25
types/jquery-countto/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/jquery-countto/tslint.json
Normal file
1
types/jquery-countto/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{"extends": "dtslint/dt.json"}
|
||||
Reference in New Issue
Block a user