Merge pull request #29266 from shermendev/countup.js

Added type definitions for countup.js
This commit is contained in:
Andrew Casey
2018-09-28 12:49:43 -07:00
committed by GitHub
4 changed files with 183 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
const b = new CountUp(".foo", 0, 100);
const options: CountUp.CountUpOptions = {
decimal: ",",
useGrouping: true,
suffix: "-",
prefix: "=",
separator: "/",
useEasing: true,
formattingFn: number => number + "-",
easingFn: (t, b, c, d) => t + b + c + d,
numerals: ["q", 2, "e", [3], "t", 0, "u", 7, "o", "p"]
};
const element = document.getElementById("#id");
if (element) {
const instance2 = new CountUp(element, 2, "3", 0, "5", options);
}
const instance = new CountUp(".js-target", 2, "3", 0, "5", options);
instance.start();
instance.start(() => {
console.log(instance.version());
});
instance.update(999);
instance.pauseResume();
if (instance.paused) instance.reset();
+124
View File
@@ -0,0 +1,124 @@
// Type definitions for countup.js 1.9
// Project: https://github.com/inorganik/CountUp.js
// Definitions by: Rostislav Shermenyov <https://github.com/shermendev>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class CountUp {
/**
* @param target Id of html element or var of previously selected html element where counting occurs
* @param startVal The value you want to begin at
* @param endVal The value you want to arrive at
* @param decimals Number of decimal places, default 0
* @param duration Duration of animation in seconds, default 2
* @param options Object of options
*/
constructor(
target: string | HTMLElement,
startVal: number | string,
endVal: number | string,
decimals?: number | string,
duration?: number | string,
options?: CountUp.CountUpOptions
);
// #region Dynamic params
// Will appear(or not) in the CountUpInstance object once the other functions fire
// i.e. paused will return undefined instead of boolean unless the pauseResume() was called before
countDown?: boolean;
d?: any;
dec?: number;
decimals?: number;
duration?: number;
endVal?: number;
error?: string;
frameVal?: number;
initialized?: boolean;
options?: CountUp.CountUpOptions;
paused?: boolean;
rAF?: number;
remaining?: number;
startTime?: number;
startVal?: number;
timestamp?: number;
callback?(): void;
// #endregion
/**
* @param timestamp
*/
count(timestamp: number): void;
initialize(): boolean;
/**
* Toggles pause/resume animation.
*/
pauseResume(): void;
/**
* Print value to target.
* @param value number that will be passed to formattingFn and then printed to the target
*/
printValue(value: number): void;
/**
* Reset to startVal so animation can be run again.
*/
reset(): void;
/**
* Start your animation.
* @param callback Option callback to run on animation end
*/
start(callback?: () => void): void;
/**
* Pass a new endVal and start animation.
* @param newEndVal new value
*/
update(newEndVal: number | string): void;
version(): string;
}
declare namespace CountUp {
interface CountUpOptions {
/**
* Character to use as a decimal
*/
decimal?: string;
/**
* Optional custom easing function, default is Robert Penner's easeOutExpo
* @param t current time
* @param b start value
* @param c change in value
* @param d duration
* @return calculated value
*/
easingFn?(t: number, b: number, c: number, d: number): number;
/**
* Optional custom formatting function
* @param num
* @return
*/
formattingFn?(num: number): string;
/**
* Optionally pass an array of custom numerals for 0-9
*/
numerals?: any[];
/**
* Optional text before the result
*/
prefix?: string;
/**
* Character to use as a separator
*/
separator?: string;
/**
* Optional text after the result
*/
suffix?: string;
/**
* Toggle easing
*/
useEasing?: boolean;
/**
* 1,000,000 vs 1000000
*/
useGrouping?: boolean;
}
}
export = CountUp;
export as namespace CountUp;
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"countup.js-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}