countup.js
Advanced tools
Comparing version 2.3.2 to 2.4.1
@@ -100,3 +100,5 @@ // same as demo.js but with a different instantiation of CountUp, | ||
var stringifyArray = function (arr) { return '[\'' + arr.join('\', \'') + '\']'; }; | ||
// COUNTUP AND CODE VISUALIZER | ||
function createCountUp() { | ||
@@ -133,2 +135,3 @@ establishOptionsFromInputs(); | ||
useGrouping: el('useGrouping').checked, | ||
useIndianSeparators: el('useIndianSeparators').checked, | ||
easingFn: typeof getEasingFn() === 'undefined' ? null : getEasingFn(), | ||
@@ -174,2 +177,3 @@ separator: el('separator').value, | ||
opts += (options.useGrouping) ? '' : indentedLine("useGrouping: " + options.useGrouping); | ||
opts += (options.useIndianSeparators) ? indentedLine("useIndianSeparators: " + options.useIndianSeparators) : ''; | ||
opts += (options.separator !== ',') ? indentedLine("separator: '" + options.separator + "'") : ''; | ||
@@ -176,0 +180,0 @@ opts += (options.decimal !== '.') ? indentedLine("decimal: '" + options.decimal + "'") : ''; |
@@ -97,3 +97,5 @@ import { CountUp } from '../dist/countUp.js'; | ||
var stringifyArray = function (arr) { return '[\'' + arr.join('\', \'') + '\']'; }; | ||
// COUNTUP AND CODE VISUALIZER | ||
function createCountUp() { | ||
@@ -136,2 +138,3 @@ establishOptionsFromInputs(); | ||
useGrouping: el('useGrouping').checked, | ||
useIndianSeparators: el('useIndianSeparators').checked, | ||
easingFn: typeof getEasingFn() === 'undefined' ? null : getEasingFn(), | ||
@@ -177,2 +180,3 @@ separator: el('separator').value, | ||
opts += (options.useGrouping) ? '' : indentedLine("useGrouping: " + options.useGrouping); | ||
opts += (options.useIndianSeparators) ? indentedLine("useIndianSeparators: " + options.useIndianSeparators) : ''; | ||
opts += (options.separator !== ',') ? indentedLine("separator: '" + options.separator + "'") : ''; | ||
@@ -179,0 +183,0 @@ opts += (options.decimal !== '.') ? indentedLine("decimal: '" + options.decimal + "'") : ''; |
@@ -6,2 +6,3 @@ export interface CountUpOptions { | ||
useGrouping?: boolean; | ||
useIndianSeparators?: boolean; | ||
useEasing?: boolean; | ||
@@ -8,0 +9,0 @@ smartEasingThreshold?: number; |
@@ -18,3 +18,3 @@ var __assign = (this && this.__assign) || function () { | ||
this.options = options; | ||
this.version = '2.3.2'; | ||
this.version = '2.4.1'; | ||
this.defaults = { | ||
@@ -26,2 +26,3 @@ startVal: 0, | ||
useGrouping: true, | ||
useIndianSeparators: false, | ||
smartEasingThreshold: 999, | ||
@@ -94,6 +95,12 @@ smartEasingAmount: 333, | ||
x3 = ''; | ||
var factor = 3, j = 0; | ||
for (var i = 0, len = x1.length; i < len; ++i) { | ||
if (i !== 0 && (i % 3) === 0) { | ||
if (_this.options.useIndianSeparators && i === 4) { | ||
factor = 2; | ||
j = 1; | ||
} | ||
if (i !== 0 && (j % factor) === 0) { | ||
x3 = _this.options.separator + x3; | ||
} | ||
j++; | ||
x3 = x1[len - i - 1] + x3; | ||
@@ -254,2 +261,4 @@ } | ||
var result = this.formattingFn(val); | ||
if (!this.el) | ||
return; | ||
if (this.el.tagName === 'INPUT') { | ||
@@ -256,0 +265,0 @@ var input = this.el; |
@@ -1,1 +0,1 @@ | ||
var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var i,n=1,s=arguments.length;n<s;n++)for(var a in i=arguments[n])Object.prototype.hasOwnProperty.call(i,a)&&(t[a]=i[a]);return t}).apply(this,arguments)},CountUp=function(){function t(t,i,n){var s=this;this.endVal=i,this.options=n,this.version="2.3.2",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,smartEasingThreshold:999,smartEasingAmount:333,separator:",",decimal:".",prefix:"",suffix:"",enableScrollSpy:!1,scrollSpyDelay:200,scrollSpyOnce:!1},this.finalEndVal=null,this.useEasing=!0,this.countDown=!1,this.error="",this.startVal=0,this.paused=!0,this.once=!1,this.count=function(t){s.startTime||(s.startTime=t);var i=t-s.startTime;s.remaining=s.duration-i,s.useEasing?s.countDown?s.frameVal=s.startVal-s.easingFn(i,0,s.startVal-s.endVal,s.duration):s.frameVal=s.easingFn(i,s.startVal,s.endVal-s.startVal,s.duration):s.frameVal=s.startVal+(s.endVal-s.startVal)*(i/s.duration);var n=s.countDown?s.frameVal<s.endVal:s.frameVal>s.endVal;s.frameVal=n?s.endVal:s.frameVal,s.frameVal=Number(s.frameVal.toFixed(s.options.decimalPlaces)),s.printValue(s.frameVal),i<s.duration?s.rAF=requestAnimationFrame(s.count):null!==s.finalEndVal?s.update(s.finalEndVal):s.callback&&s.callback()},this.formatNumber=function(t){var i,n,a,e,r=t<0?"-":"";i=Math.abs(t).toFixed(s.options.decimalPlaces);var o=(i+="").split(".");if(n=o[0],a=o.length>1?s.options.decimal+o[1]:"",s.options.useGrouping){e="";for(var l=0,h=n.length;l<h;++l)0!==l&&l%3==0&&(e=s.options.separator+e),e=n[h-l-1]+e;n=e}return s.options.numerals&&s.options.numerals.length&&(n=n.replace(/[0-9]/g,function(t){return s.options.numerals[+t]}),a=a.replace(/[0-9]/g,function(t){return s.options.numerals[+t]})),r+s.options.prefix+n+a+s.options.suffix},this.easeOutExpo=function(t,i,n,s){return n*(1-Math.pow(2,-10*t/s))*1024/1023+i},this.options=__assign(__assign({},this.defaults),n),this.formattingFn=this.options.formattingFn?this.options.formattingFn:this.formatNumber,this.easingFn=this.options.easingFn?this.options.easingFn:this.easeOutExpo,this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.endVal=this.validateValue(i),this.options.decimalPlaces=Math.max(this.options.decimalPlaces),this.resetDuration(),this.options.separator=String(this.options.separator),this.useEasing=this.options.useEasing,""===this.options.separator&&(this.options.useGrouping=!1),this.el="string"==typeof t?document.getElementById(t):t,this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined","undefined"!=typeof window&&this.options.enableScrollSpy&&(this.error?console.error(this.error,t):(window.onScrollFns=window.onScrollFns||[],window.onScrollFns.push(function(){return s.handleScroll(s)}),window.onscroll=function(){window.onScrollFns.forEach(function(t){return t()})},this.handleScroll(this)))}return t.prototype.handleScroll=function(t){if(t&&window&&!t.once){var i=window.innerHeight+window.scrollY,n=t.el.getBoundingClientRect(),s=n.top+n.height+window.pageYOffset;s<i&&s>window.scrollY&&t.paused?(t.paused=!1,setTimeout(function(){return t.start()},t.options.scrollSpyDelay),t.options.scrollSpyOnce&&(t.once=!0)):window.scrollY>s&&!t.paused&&t.reset()}},t.prototype.determineDirectionAndSmartEasing=function(){var t=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>t;var i=t-this.startVal;if(Math.abs(i)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=t;var n=this.countDown?1:-1;this.endVal=t+n*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=t,this.finalEndVal=null;null!==this.finalEndVal?this.useEasing=!1:this.useEasing=this.options.useEasing},t.prototype.start=function(t){this.error||(this.callback=t,this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},t.prototype.pauseResume=function(){this.paused?(this.startTime=null,this.duration=this.remaining,this.startVal=this.frameVal,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count)):cancelAnimationFrame(this.rAF),this.paused=!this.paused},t.prototype.reset=function(){cancelAnimationFrame(this.rAF),this.paused=!0,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},t.prototype.update=function(t){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(t),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,null==this.finalEndVal&&this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},t.prototype.printValue=function(t){var i=this.formattingFn(t);"INPUT"===this.el.tagName?this.el.value=i:"text"===this.el.tagName||"tspan"===this.el.tagName?this.el.textContent=i:this.el.innerHTML=i},t.prototype.ensureNumber=function(t){return"number"==typeof t&&!isNaN(t)},t.prototype.validateValue=function(t){var i=Number(t);return this.ensureNumber(i)?i:(this.error="[CountUp] invalid start or end value: ".concat(t),null)},t.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},t}();export{CountUp}; | ||
var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var i,n=1,s=arguments.length;n<s;n++)for(var a in i=arguments[n])Object.prototype.hasOwnProperty.call(i,a)&&(t[a]=i[a]);return t}).apply(this,arguments)},CountUp=function(){function t(t,i,n){var s=this;this.endVal=i,this.options=n,this.version="2.4.1",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,useIndianSeparators:!1,smartEasingThreshold:999,smartEasingAmount:333,separator:",",decimal:".",prefix:"",suffix:"",enableScrollSpy:!1,scrollSpyDelay:200,scrollSpyOnce:!1},this.finalEndVal=null,this.useEasing=!0,this.countDown=!1,this.error="",this.startVal=0,this.paused=!0,this.once=!1,this.count=function(t){s.startTime||(s.startTime=t);var i=t-s.startTime;s.remaining=s.duration-i,s.useEasing?s.countDown?s.frameVal=s.startVal-s.easingFn(i,0,s.startVal-s.endVal,s.duration):s.frameVal=s.easingFn(i,s.startVal,s.endVal-s.startVal,s.duration):s.frameVal=s.startVal+(s.endVal-s.startVal)*(i/s.duration);var n=s.countDown?s.frameVal<s.endVal:s.frameVal>s.endVal;s.frameVal=n?s.endVal:s.frameVal,s.frameVal=Number(s.frameVal.toFixed(s.options.decimalPlaces)),s.printValue(s.frameVal),i<s.duration?s.rAF=requestAnimationFrame(s.count):null!==s.finalEndVal?s.update(s.finalEndVal):s.callback&&s.callback()},this.formatNumber=function(t){var i,n,a,e,r=t<0?"-":"";i=Math.abs(t).toFixed(s.options.decimalPlaces);var o=(i+="").split(".");if(n=o[0],a=o.length>1?s.options.decimal+o[1]:"",s.options.useGrouping){e="";for(var l=3,h=0,u=0,p=n.length;u<p;++u)s.options.useIndianSeparators&&4===u&&(l=2,h=1),0!==u&&h%l==0&&(e=s.options.separator+e),h++,e=n[p-u-1]+e;n=e}return s.options.numerals&&s.options.numerals.length&&(n=n.replace(/[0-9]/g,function(t){return s.options.numerals[+t]}),a=a.replace(/[0-9]/g,function(t){return s.options.numerals[+t]})),r+s.options.prefix+n+a+s.options.suffix},this.easeOutExpo=function(t,i,n,s){return n*(1-Math.pow(2,-10*t/s))*1024/1023+i},this.options=__assign(__assign({},this.defaults),n),this.formattingFn=this.options.formattingFn?this.options.formattingFn:this.formatNumber,this.easingFn=this.options.easingFn?this.options.easingFn:this.easeOutExpo,this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.endVal=this.validateValue(i),this.options.decimalPlaces=Math.max(this.options.decimalPlaces),this.resetDuration(),this.options.separator=String(this.options.separator),this.useEasing=this.options.useEasing,""===this.options.separator&&(this.options.useGrouping=!1),this.el="string"==typeof t?document.getElementById(t):t,this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined","undefined"!=typeof window&&this.options.enableScrollSpy&&(this.error?console.error(this.error,t):(window.onScrollFns=window.onScrollFns||[],window.onScrollFns.push(function(){return s.handleScroll(s)}),window.onscroll=function(){window.onScrollFns.forEach(function(t){return t()})},this.handleScroll(this)))}return t.prototype.handleScroll=function(t){if(t&&window&&!t.once){var i=window.innerHeight+window.scrollY,n=t.el.getBoundingClientRect(),s=n.top+n.height+window.pageYOffset;s<i&&s>window.scrollY&&t.paused?(t.paused=!1,setTimeout(function(){return t.start()},t.options.scrollSpyDelay),t.options.scrollSpyOnce&&(t.once=!0)):window.scrollY>s&&!t.paused&&t.reset()}},t.prototype.determineDirectionAndSmartEasing=function(){var t=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>t;var i=t-this.startVal;if(Math.abs(i)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=t;var n=this.countDown?1:-1;this.endVal=t+n*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=t,this.finalEndVal=null;null!==this.finalEndVal?this.useEasing=!1:this.useEasing=this.options.useEasing},t.prototype.start=function(t){this.error||(this.callback=t,this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},t.prototype.pauseResume=function(){this.paused?(this.startTime=null,this.duration=this.remaining,this.startVal=this.frameVal,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count)):cancelAnimationFrame(this.rAF),this.paused=!this.paused},t.prototype.reset=function(){cancelAnimationFrame(this.rAF),this.paused=!0,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},t.prototype.update=function(t){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(t),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,null==this.finalEndVal&&this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},t.prototype.printValue=function(t){var i=this.formattingFn(t);this.el&&("INPUT"===this.el.tagName?this.el.value=i:"text"===this.el.tagName||"tspan"===this.el.tagName?this.el.textContent=i:this.el.innerHTML=i)},t.prototype.ensureNumber=function(t){return"number"==typeof t&&!isNaN(t)},t.prototype.validateValue=function(t){var i=Number(t);return this.ensureNumber(i)?i:(this.error="[CountUp] invalid start or end value: ".concat(t),null)},t.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},t}();export{CountUp}; |
@@ -24,3 +24,3 @@ (function (global, factory) { | ||
this.options = options; | ||
this.version = '2.3.2'; | ||
this.version = '2.4.1'; | ||
this.defaults = { | ||
@@ -32,2 +32,3 @@ startVal: 0, | ||
useGrouping: true, | ||
useIndianSeparators: false, | ||
smartEasingThreshold: 999, | ||
@@ -100,6 +101,12 @@ smartEasingAmount: 333, | ||
x3 = ''; | ||
var factor = 3, j = 0; | ||
for (var i = 0, len = x1.length; i < len; ++i) { | ||
if (i !== 0 && (i % 3) === 0) { | ||
if (_this.options.useIndianSeparators && i === 4) { | ||
factor = 2; | ||
j = 1; | ||
} | ||
if (i !== 0 && (j % factor) === 0) { | ||
x3 = _this.options.separator + x3; | ||
} | ||
j++; | ||
x3 = x1[len - i - 1] + x3; | ||
@@ -260,2 +267,4 @@ } | ||
var result = this.formattingFn(val); | ||
if (!this.el) | ||
return; | ||
if (this.el.tagName === 'INPUT') { | ||
@@ -262,0 +271,0 @@ var input = this.el; |
@@ -1,1 +0,1 @@ | ||
!function(){for(var t=0,i=["webkit","moz","ms","o"],n=0;n<i.length&&!window.requestAnimationFrame;++n)window.requestAnimationFrame=window[i[n]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[i[n]+"CancelAnimationFrame"]||window[i[n]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(i){var n=(new Date).getTime(),a=Math.max(0,16-(n-t)),s=window.setTimeout(function(){return i(n+a)},a);return t=n+a,s}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)})}();var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var i,n=1,a=arguments.length;n<a;n++)for(var s in i=arguments[n])Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s]);return t}).apply(this,arguments)},CountUp=function(){function t(t,i,n){var a=this;this.endVal=i,this.options=n,this.version="2.3.2",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,smartEasingThreshold:999,smartEasingAmount:333,separator:",",decimal:".",prefix:"",suffix:"",enableScrollSpy:!1,scrollSpyDelay:200,scrollSpyOnce:!1},this.finalEndVal=null,this.useEasing=!0,this.countDown=!1,this.error="",this.startVal=0,this.paused=!0,this.once=!1,this.count=function(t){a.startTime||(a.startTime=t);var i=t-a.startTime;a.remaining=a.duration-i,a.useEasing?a.countDown?a.frameVal=a.startVal-a.easingFn(i,0,a.startVal-a.endVal,a.duration):a.frameVal=a.easingFn(i,a.startVal,a.endVal-a.startVal,a.duration):a.frameVal=a.startVal+(a.endVal-a.startVal)*(i/a.duration);var n=a.countDown?a.frameVal<a.endVal:a.frameVal>a.endVal;a.frameVal=n?a.endVal:a.frameVal,a.frameVal=Number(a.frameVal.toFixed(a.options.decimalPlaces)),a.printValue(a.frameVal),i<a.duration?a.rAF=requestAnimationFrame(a.count):null!==a.finalEndVal?a.update(a.finalEndVal):a.callback&&a.callback()},this.formatNumber=function(t){var i,n,s,e,o=t<0?"-":"";i=Math.abs(t).toFixed(a.options.decimalPlaces);var r=(i+="").split(".");if(n=r[0],s=r.length>1?a.options.decimal+r[1]:"",a.options.useGrouping){e="";for(var l=0,u=n.length;l<u;++l)0!==l&&l%3==0&&(e=a.options.separator+e),e=n[u-l-1]+e;n=e}return a.options.numerals&&a.options.numerals.length&&(n=n.replace(/[0-9]/g,function(t){return a.options.numerals[+t]}),s=s.replace(/[0-9]/g,function(t){return a.options.numerals[+t]})),o+a.options.prefix+n+s+a.options.suffix},this.easeOutExpo=function(t,i,n,a){return n*(1-Math.pow(2,-10*t/a))*1024/1023+i},this.options=__assign(__assign({},this.defaults),n),this.formattingFn=this.options.formattingFn?this.options.formattingFn:this.formatNumber,this.easingFn=this.options.easingFn?this.options.easingFn:this.easeOutExpo,this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.endVal=this.validateValue(i),this.options.decimalPlaces=Math.max(this.options.decimalPlaces),this.resetDuration(),this.options.separator=String(this.options.separator),this.useEasing=this.options.useEasing,""===this.options.separator&&(this.options.useGrouping=!1),this.el="string"==typeof t?document.getElementById(t):t,this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined","undefined"!=typeof window&&this.options.enableScrollSpy&&(this.error?console.error(this.error,t):(window.onScrollFns=window.onScrollFns||[],window.onScrollFns.push(function(){return a.handleScroll(a)}),window.onscroll=function(){window.onScrollFns.forEach(function(t){return t()})},this.handleScroll(this)))}return t.prototype.handleScroll=function(t){if(t&&window&&!t.once){var i=window.innerHeight+window.scrollY,n=t.el.getBoundingClientRect(),a=n.top+n.height+window.pageYOffset;a<i&&a>window.scrollY&&t.paused?(t.paused=!1,setTimeout(function(){return t.start()},t.options.scrollSpyDelay),t.options.scrollSpyOnce&&(t.once=!0)):window.scrollY>a&&!t.paused&&t.reset()}},t.prototype.determineDirectionAndSmartEasing=function(){var t=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>t;var i=t-this.startVal;if(Math.abs(i)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=t;var n=this.countDown?1:-1;this.endVal=t+n*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=t,this.finalEndVal=null;null!==this.finalEndVal?this.useEasing=!1:this.useEasing=this.options.useEasing},t.prototype.start=function(t){this.error||(this.callback=t,this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},t.prototype.pauseResume=function(){this.paused?(this.startTime=null,this.duration=this.remaining,this.startVal=this.frameVal,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count)):cancelAnimationFrame(this.rAF),this.paused=!this.paused},t.prototype.reset=function(){cancelAnimationFrame(this.rAF),this.paused=!0,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},t.prototype.update=function(t){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(t),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,null==this.finalEndVal&&this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},t.prototype.printValue=function(t){var i=this.formattingFn(t);"INPUT"===this.el.tagName?this.el.value=i:"text"===this.el.tagName||"tspan"===this.el.tagName?this.el.textContent=i:this.el.innerHTML=i},t.prototype.ensureNumber=function(t){return"number"==typeof t&&!isNaN(t)},t.prototype.validateValue=function(t){var i=Number(t);return this.ensureNumber(i)?i:(this.error="[CountUp] invalid start or end value: ".concat(t),null)},t.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},t}();export{CountUp}; | ||
!function(){for(var t=0,i=["webkit","moz","ms","o"],n=0;n<i.length&&!window.requestAnimationFrame;++n)window.requestAnimationFrame=window[i[n]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[i[n]+"CancelAnimationFrame"]||window[i[n]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(i){var n=(new Date).getTime(),a=Math.max(0,16-(n-t)),s=window.setTimeout(function(){return i(n+a)},a);return t=n+a,s}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)})}();var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var i,n=1,a=arguments.length;n<a;n++)for(var s in i=arguments[n])Object.prototype.hasOwnProperty.call(i,s)&&(t[s]=i[s]);return t}).apply(this,arguments)},CountUp=function(){function t(t,i,n){var a=this;this.endVal=i,this.options=n,this.version="2.4.1",this.defaults={startVal:0,decimalPlaces:0,duration:2,useEasing:!0,useGrouping:!0,useIndianSeparators:!1,smartEasingThreshold:999,smartEasingAmount:333,separator:",",decimal:".",prefix:"",suffix:"",enableScrollSpy:!1,scrollSpyDelay:200,scrollSpyOnce:!1},this.finalEndVal=null,this.useEasing=!0,this.countDown=!1,this.error="",this.startVal=0,this.paused=!0,this.once=!1,this.count=function(t){a.startTime||(a.startTime=t);var i=t-a.startTime;a.remaining=a.duration-i,a.useEasing?a.countDown?a.frameVal=a.startVal-a.easingFn(i,0,a.startVal-a.endVal,a.duration):a.frameVal=a.easingFn(i,a.startVal,a.endVal-a.startVal,a.duration):a.frameVal=a.startVal+(a.endVal-a.startVal)*(i/a.duration);var n=a.countDown?a.frameVal<a.endVal:a.frameVal>a.endVal;a.frameVal=n?a.endVal:a.frameVal,a.frameVal=Number(a.frameVal.toFixed(a.options.decimalPlaces)),a.printValue(a.frameVal),i<a.duration?a.rAF=requestAnimationFrame(a.count):null!==a.finalEndVal?a.update(a.finalEndVal):a.callback&&a.callback()},this.formatNumber=function(t){var i,n,s,e,o=t<0?"-":"";i=Math.abs(t).toFixed(a.options.decimalPlaces);var r=(i+="").split(".");if(n=r[0],s=r.length>1?a.options.decimal+r[1]:"",a.options.useGrouping){e="";for(var l=3,u=0,h=0,p=n.length;h<p;++h)a.options.useIndianSeparators&&4===h&&(l=2,u=1),0!==h&&u%l==0&&(e=a.options.separator+e),u++,e=n[p-h-1]+e;n=e}return a.options.numerals&&a.options.numerals.length&&(n=n.replace(/[0-9]/g,function(t){return a.options.numerals[+t]}),s=s.replace(/[0-9]/g,function(t){return a.options.numerals[+t]})),o+a.options.prefix+n+s+a.options.suffix},this.easeOutExpo=function(t,i,n,a){return n*(1-Math.pow(2,-10*t/a))*1024/1023+i},this.options=__assign(__assign({},this.defaults),n),this.formattingFn=this.options.formattingFn?this.options.formattingFn:this.formatNumber,this.easingFn=this.options.easingFn?this.options.easingFn:this.easeOutExpo,this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.endVal=this.validateValue(i),this.options.decimalPlaces=Math.max(this.options.decimalPlaces),this.resetDuration(),this.options.separator=String(this.options.separator),this.useEasing=this.options.useEasing,""===this.options.separator&&(this.options.useGrouping=!1),this.el="string"==typeof t?document.getElementById(t):t,this.el?this.printValue(this.startVal):this.error="[CountUp] target is null or undefined","undefined"!=typeof window&&this.options.enableScrollSpy&&(this.error?console.error(this.error,t):(window.onScrollFns=window.onScrollFns||[],window.onScrollFns.push(function(){return a.handleScroll(a)}),window.onscroll=function(){window.onScrollFns.forEach(function(t){return t()})},this.handleScroll(this)))}return t.prototype.handleScroll=function(t){if(t&&window&&!t.once){var i=window.innerHeight+window.scrollY,n=t.el.getBoundingClientRect(),a=n.top+n.height+window.pageYOffset;a<i&&a>window.scrollY&&t.paused?(t.paused=!1,setTimeout(function(){return t.start()},t.options.scrollSpyDelay),t.options.scrollSpyOnce&&(t.once=!0)):window.scrollY>a&&!t.paused&&t.reset()}},t.prototype.determineDirectionAndSmartEasing=function(){var t=this.finalEndVal?this.finalEndVal:this.endVal;this.countDown=this.startVal>t;var i=t-this.startVal;if(Math.abs(i)>this.options.smartEasingThreshold&&this.options.useEasing){this.finalEndVal=t;var n=this.countDown?1:-1;this.endVal=t+n*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=t,this.finalEndVal=null;null!==this.finalEndVal?this.useEasing=!1:this.useEasing=this.options.useEasing},t.prototype.start=function(t){this.error||(this.callback=t,this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},t.prototype.pauseResume=function(){this.paused?(this.startTime=null,this.duration=this.remaining,this.startVal=this.frameVal,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count)):cancelAnimationFrame(this.rAF),this.paused=!this.paused},t.prototype.reset=function(){cancelAnimationFrame(this.rAF),this.paused=!0,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},t.prototype.update=function(t){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(t),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,null==this.finalEndVal&&this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},t.prototype.printValue=function(t){var i=this.formattingFn(t);this.el&&("INPUT"===this.el.tagName?this.el.value=i:"text"===this.el.tagName||"tspan"===this.el.tagName?this.el.textContent=i:this.el.innerHTML=i)},t.prototype.ensureNumber=function(t){return"number"==typeof t&&!isNaN(t)},t.prototype.validateValue=function(t){var i=Number(t);return this.ensureNumber(i)?i:(this.error="[CountUp] invalid start or end value: ".concat(t),null)},t.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},t}();export{CountUp}; |
{ | ||
"name": "countup.js", | ||
"description": "Animates a numerical value by counting to it", | ||
"version": "2.3.2", | ||
"version": "2.4.1", | ||
"license": "MIT", | ||
@@ -18,3 +18,3 @@ "main": "./dist/countUp.umd.js", | ||
"lint": "eslint -c .eslintrc.js --ext .ts ./src", | ||
"serve": "http-server ./", | ||
"serve": "http-server -o -c-1 ./", | ||
"start": "npm run build && npm run serve", | ||
@@ -24,11 +24,10 @@ "test": "jest", | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/jest": "^27.5.1", | ||
"@typescript-eslint/eslint-plugin": "^5.24.0", | ||
"@typescript-eslint/eslint-plugin-tslint": "^5.24.0", | ||
"@typescript-eslint/parser": "^5.24.0", | ||
"@types/jest": "^28.1.8", | ||
"@typescript-eslint/eslint-plugin": "^5.41.0", | ||
"@typescript-eslint/eslint-plugin-tslint": "^5.41.0", | ||
"@typescript-eslint/parser": "^5.41.0", | ||
"browserify": "^17.0.0", | ||
"del": "^6.1.0", | ||
"eslint": "^8.15.0", | ||
"del": "^6.1.1", | ||
"eslint": "^8.26.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
@@ -38,8 +37,8 @@ "gulp": "^4.0.2", | ||
"gulp-uglify": "^3.0.2", | ||
"http-server": "^14.1.0", | ||
"jest": "^28.1.0", | ||
"jest-environment-jsdom": "^28.1.0", | ||
"rollup": "^2.73.0", | ||
"ts-jest": "^28.0.2", | ||
"typescript": "^4.6.4", | ||
"http-server": "^14.1.1", | ||
"jest": "^28.1.3", | ||
"jest-environment-jsdom": "^28.1.3", | ||
"rollup": "^2.79.1", | ||
"ts-jest": "^28.0.8", | ||
"typescript": "^4.8.4", | ||
"uglify-es": "^3.3.9" | ||
@@ -46,0 +45,0 @@ }, |
@@ -53,2 +53,3 @@ # CountUp.js | ||
useGrouping?: boolean; // example: 1,000 vs 1000 (true) | ||
useIndianSeparators?: boolean; // example: 1,00,000 vs 100,000 (false) | ||
useEasing?: boolean; // ease animation (true) | ||
@@ -55,0 +56,0 @@ smartEasingThreshold?: number; // smooth easing for large numbers above this if useEasing (999) |
@@ -8,2 +8,3 @@ import { CountUp } from './countUp'; | ||
const getTargetHtml = () => document.getElementById('target')?.innerHTML; | ||
const resetRAF = () => { | ||
@@ -34,3 +35,3 @@ time = 0; | ||
expect(countUp.error.length).toBe(0); | ||
expect(document.getElementById('target').innerHTML).toEqual('0'); | ||
expect(getTargetHtml()).toEqual('0'); | ||
}); | ||
@@ -67,3 +68,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('100'); | ||
expect(getTargetHtml()).toEqual('100'); | ||
}); | ||
@@ -83,3 +84,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('0'); | ||
expect(getTargetHtml()).toEqual('0'); | ||
expect(countUp.paused).toBeTruthy(); | ||
@@ -90,7 +91,7 @@ }); | ||
countUp.start(); | ||
expect(document.getElementById('target').innerHTML).toEqual('100'); | ||
expect(getTargetHtml()).toEqual('100'); | ||
resetRAF(); | ||
countUp.update(200); | ||
expect(document.getElementById('target').innerHTML).toEqual('200'); | ||
expect(getTargetHtml()).toEqual('200'); | ||
}); | ||
@@ -106,3 +107,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('6,000'); | ||
expect(getTargetHtml()).toEqual('6,000'); | ||
expect(spy).toHaveBeenCalled(); | ||
@@ -116,3 +117,3 @@ }); | ||
expect(document.getElementById('target').innerHTML).toEqual('6,000'); | ||
expect(getTargetHtml()).toEqual('6,000'); | ||
expect(spy).toHaveBeenCalledTimes(0); | ||
@@ -123,6 +124,6 @@ }); | ||
countUp = new CountUp('target', 10, { startVal: 500 }); | ||
expect(document.getElementById('target').innerHTML).toEqual('500'); | ||
expect(getTargetHtml()).toEqual('500'); | ||
countUp.start(); | ||
expect(document.getElementById('target').innerHTML).toEqual('10'); | ||
expect(getTargetHtml()).toEqual('10'); | ||
}); | ||
@@ -134,3 +135,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('-500'); | ||
expect(getTargetHtml()).toEqual('-500'); | ||
}); | ||
@@ -142,3 +143,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('2,000'); | ||
expect(getTargetHtml()).toEqual('2,000'); | ||
}); | ||
@@ -150,3 +151,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('100'); | ||
expect(getTargetHtml()).toEqual('100'); | ||
expect(cb).toHaveBeenCalled(); | ||
@@ -161,3 +162,3 @@ }); | ||
expect(document.getElementById('target').innerHTML).toEqual('100.00'); | ||
expect(getTargetHtml()).toEqual('100.00'); | ||
}); | ||
@@ -169,3 +170,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('100'); | ||
expect(getTargetHtml()).toEqual('100'); | ||
}); | ||
@@ -177,17 +178,29 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('100'); | ||
expect(getTargetHtml()).toEqual('100'); | ||
}); | ||
it('should respect the useGrouping option', () => { | ||
countUp = new CountUp('target', 10000, { useGrouping: false }); | ||
countUp = new CountUp('target', 100000, { useGrouping: false }); | ||
countUp.start(); | ||
expect(document.getElementById('target').innerHTML).toEqual('10000'); | ||
expect(getTargetHtml()).toEqual('100000'); | ||
resetRAF(); | ||
countUp = new CountUp('target', 1000000, { useGrouping: true }); | ||
countUp.start(); | ||
expect(getTargetHtml()).toEqual('1,000,000'); | ||
}); | ||
it('should respect the separator option', () => { | ||
countUp = new CountUp('target', 10000, { separator: ':' }); | ||
it('should respect the useIndianSeparators option', () => { | ||
countUp = new CountUp('target', 100000, { useIndianSeparators: true }); | ||
countUp.start(); | ||
expect(document.getElementById('target').innerHTML).toEqual('10:000'); | ||
expect(getTargetHtml()).toEqual('1,00,000'); | ||
resetRAF(); | ||
countUp = new CountUp('target', 10000000, { useIndianSeparators: true }); | ||
countUp.start(); | ||
expect(getTargetHtml()).toEqual('1,00,00,000'); | ||
}); | ||
@@ -199,3 +212,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('10:000'); | ||
expect(getTargetHtml()).toEqual('10:000'); | ||
}); | ||
@@ -207,3 +220,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('100,0'); | ||
expect(getTargetHtml()).toEqual('100,0'); | ||
}); | ||
@@ -217,3 +230,3 @@ | ||
expect(easeOutQuintic).toHaveBeenCalled(); | ||
expect(document.getElementById('target').innerHTML).toEqual('100'); | ||
expect(getTargetHtml()).toEqual('100'); | ||
}); | ||
@@ -227,3 +240,3 @@ | ||
expect(formatter).toHaveBeenCalled(); | ||
expect(document.getElementById('target').innerHTML).toEqual('~100~'); | ||
expect(getTargetHtml()).toEqual('~100~'); | ||
}); | ||
@@ -235,3 +248,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('$100'); | ||
expect(getTargetHtml()).toEqual('$100'); | ||
}); | ||
@@ -243,3 +256,3 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('100!'); | ||
expect(getTargetHtml()).toEqual('100!'); | ||
}); | ||
@@ -252,5 +265,5 @@ | ||
expect(document.getElementById('target').innerHTML).toEqual('!))'); | ||
expect(getTargetHtml()).toEqual('!))'); | ||
}); | ||
}); | ||
}); |
@@ -6,2 +6,3 @@ export interface CountUpOptions { // (default) | ||
useGrouping?: boolean; // example: 1,000 vs 1000 (true) | ||
useIndianSeparators?: boolean; // example: 1,00,000 vs 100,000 (false) | ||
useEasing?: boolean; // ease animation (true) | ||
@@ -26,3 +27,3 @@ smartEasingThreshold?: number; // smooth easing for large numbers above this if useEasing (999) | ||
version = '2.3.2'; | ||
version = '2.4.1'; | ||
private defaults: CountUpOptions = { | ||
@@ -34,2 +35,3 @@ startVal: 0, | ||
useGrouping: true, | ||
useIndianSeparators: false, | ||
smartEasingThreshold: 999, | ||
@@ -251,3 +253,3 @@ smartEasingAmount: 333, | ||
const result = this.formattingFn(val); | ||
if (!this.el) return; | ||
if (this.el.tagName === 'INPUT') { | ||
@@ -287,6 +289,3 @@ const input = this.el as HTMLInputElement; | ||
const neg = (num < 0) ? '-' : ''; | ||
let result: string, | ||
x1: string, | ||
x2: string, | ||
x3: string; | ||
let result: string, x1: string, x2: string, x3: string; | ||
result = Math.abs(num).toFixed(this.options.decimalPlaces); | ||
@@ -299,6 +298,12 @@ result += ''; | ||
x3 = ''; | ||
let factor = 3, j = 0; | ||
for (let i = 0, len = x1.length; i < len; ++i) { | ||
if (i !== 0 && (i % 3) === 0) { | ||
if (this.options.useIndianSeparators && i === 4) { | ||
factor = 2; | ||
j = 1; | ||
} | ||
if (i !== 0 && (j % factor) === 0) { | ||
x3 = this.options.separator + x3; | ||
} | ||
j++; | ||
x3 = x1[len - i - 1] + x3; | ||
@@ -305,0 +310,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92761
1726
205