Comparing version 0.1.1 to 0.1.2
@@ -1,4 +0,3 @@ | ||
function drain(val, newVal, callback) { | ||
var start = parseInt(val, 0); | ||
var end = parseInt(newVal, 0); | ||
function drain(_a) { | ||
var start = _a.start, end = _a.end, onInterval = _a.onInterval, onComplete = _a.onComplete; | ||
var diff = Math.abs(end - start); | ||
@@ -8,10 +7,13 @@ var direction = end - start > 0 ? "up" : "down"; | ||
if (diff > 10000) | ||
step = 9999; | ||
step = 9494; | ||
else if (diff > 1000) | ||
step = 999; | ||
step = 949; | ||
else if (diff > 100) | ||
step = 99; | ||
step = 94; | ||
else if (diff > 10) | ||
step = 9; | ||
if (diff === 0) { | ||
if (typeof onComplete === "function") { | ||
onComplete(start); | ||
} | ||
return; | ||
@@ -25,7 +27,9 @@ } | ||
} | ||
callback(start); | ||
if (typeof onInterval === "function") { | ||
onInterval(start); | ||
} | ||
setTimeout(function () { | ||
drain(start, end, callback); | ||
drain({ start: start, end: end, onInterval: onInterval, onComplete: onComplete }); | ||
}, 100); | ||
} | ||
export default drain; |
{ | ||
"name": "drain-js", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Number change animator", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -13,3 +13,10 @@ # Drain.js | ||
`drain(start: Number, end: Number, callback: Function)` | ||
```ts | ||
drain({ | ||
start: Number, | ||
end: Number, | ||
onInterval?: Function, | ||
onComplete?: Function | ||
}); | ||
``` | ||
@@ -21,3 +28,3 @@ ### Sample | ||
drain(3000, 2750, console.log); | ||
drain({ start: 3000, end: 2750, onInterval: console.log }); | ||
@@ -24,0 +31,0 @@ // Output |
@@ -1,5 +0,9 @@ | ||
function drain(val, newVal, callback: Function) { | ||
let start: number = parseInt(val, 0); | ||
let end: number = parseInt(newVal, 0); | ||
type drainArgs = { | ||
start: number, | ||
end: number, | ||
onInterval?: Function, | ||
onComplete?: Function | ||
} | ||
function drain({ start, end, onInterval, onComplete }: drainArgs) { | ||
let diff = Math.abs(end - start); | ||
@@ -9,8 +13,11 @@ let direction = end - start > 0 ? "up" : "down"; | ||
if (diff > 10000) step = 9999; | ||
else if (diff > 1000) step = 999; | ||
else if (diff > 100) step = 99; | ||
if (diff > 10000) step = 9494; | ||
else if (diff > 1000) step = 949; | ||
else if (diff > 100) step = 94; | ||
else if (diff > 10) step = 9; | ||
if (diff === 0) { | ||
if (typeof onComplete === "function") { | ||
onComplete(start); | ||
} | ||
return; | ||
@@ -25,6 +32,8 @@ } | ||
callback(start); | ||
if (typeof onInterval === "function") { | ||
onInterval(start); | ||
} | ||
setTimeout(() => { | ||
drain(start, end, callback); | ||
drain({ start: start, end: end, onInterval, onComplete }); | ||
}, 100); | ||
@@ -31,0 +40,0 @@ } |
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
14493
81
38