Skip to content

Commit dd5bffe

Browse files
committed
adding parse tests, lint, build
1 parent d51a196 commit dd5bffe

File tree

8 files changed

+104
-39
lines changed

8 files changed

+104
-39
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Or tinker with CountUp in [Stackblitz](https://stackblitz.com/edit/countup-types
4242
On npm as `countup.js`. You can import as a module, or include the UMD script and access CountUp as a global. See [detailed instructions](#including-countup) on including CountUp.
4343

4444
**Params**:
45-
- `target: string | HTMLElement | HTMLInputElement` - id of html element, input, svg text element, or DOM element reference where counting occurs
46-
- `endVal: number` - the value you want to arrive at
45+
- `target: string | HTMLElement | HTMLInputElement` - id of html element, input, svg text element, or DOM element reference where counting occurs.
46+
- `endVal: number | null` - the value you want to arrive at. Leave null to use the number in the target element.
4747
- `options?: CountUpOptions` - optional configuration object for fine-grain control
4848

4949
**Options** (defaults in parentheses): <a name="options"></a>

dist/countUp.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export declare interface CountUpPlugin {
2525
render(elem: HTMLElement, formatted: string): void;
2626
}
2727
export declare class CountUp {
28-
private endVal;
28+
private endVal?;
2929
options?: CountUpOptions;
3030
version: string;
3131
private defaults;
@@ -44,7 +44,7 @@ export declare class CountUp {
4444
paused: boolean;
4545
frameVal: number;
4646
once: boolean;
47-
constructor(target: string | HTMLElement | HTMLInputElement, endVal: number, options?: CountUpOptions);
47+
constructor(target: string | HTMLElement | HTMLInputElement, endVal?: number | null, options?: CountUpOptions);
4848
handleScroll(self: CountUp): void;
4949
/**
5050
* Smart easing works by breaking the animation into 2 parts, the second part being the
@@ -64,4 +64,5 @@ export declare class CountUp {
6464
private resetDuration;
6565
formatNumber: (num: number) => string;
6666
easeOutExpo: (t: number, b: number, c: number, d: number) => number;
67+
parse(number: string): number;
6768
}

dist/countUp.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var CountUp = /** @class */ (function () {
1515
var _this = this;
1616
this.endVal = endVal;
1717
this.options = options;
18-
this.version = '2.8.1';
18+
this.version = '2.9.0';
1919
this.defaults = {
2020
startVal: 0,
2121
decimalPlaces: 0,
@@ -120,6 +120,8 @@ var CountUp = /** @class */ (function () {
120120
this.options.formattingFn : this.formatNumber;
121121
this.easingFn = (this.options.easingFn) ?
122122
this.options.easingFn : this.easeOutExpo;
123+
this.el = (typeof target === 'string') ? document.getElementById(target) : target;
124+
endVal = endVal == null ? this.parse(this.el.innerHTML) : endVal;
123125
this.startVal = this.validateValue(this.options.startVal);
124126
this.frameVal = this.startVal;
125127
this.endVal = this.validateValue(endVal);
@@ -130,7 +132,6 @@ var CountUp = /** @class */ (function () {
130132
if (this.options.separator === '') {
131133
this.options.useGrouping = false;
132134
}
133-
this.el = (typeof target === 'string') ? document.getElementById(target) : target;
134135
if (this.el) {
135136
this.printValue(this.startVal);
136137
}
@@ -298,6 +299,14 @@ var CountUp = /** @class */ (function () {
298299
this.duration = Number(this.options.duration) * 1000;
299300
this.remaining = this.duration;
300301
};
302+
CountUp.prototype.parse = function (number) {
303+
// eslint-disable-next-line no-irregular-whitespace
304+
var escapeRegExp = function (s) { return s.replace(/([.,'  ])/g, '\\$1'); };
305+
var sep = escapeRegExp(this.options.separator);
306+
var dec = escapeRegExp(this.options.decimal);
307+
var num = number.replace(new RegExp(sep, 'g'), '').replace(new RegExp(dec, 'g'), '.');
308+
return parseFloat(num);
309+
};
301310
return CountUp;
302311
}());
303312
export { CountUp };

dist/countUp.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)