Simple and powerful time estimation (ETA).
Ideal to draw progress in CLI, web and mobile.
- Zero dependencies. Works everywhere - node, browsers, toaster, etc.
- ETA, speed measurements and average step time estimation
Usage
Install with npm i arrival-time
or yarn add arrival-time
import { Estimation } from 'arrival-time';
const estimation = new Estimation();
const measure1 = estimation.update(25, 100);
console.log("Estimated time", measure1.estimate);
console.log("Estimated speed", measure1.speed);
console.log(measure1);
console.log(estimation.update(50, 100))
API
constructor
type Options = {
progress?: number;
total?: number;
startTime?: number;
timeFetcher?: TimeFetcher;
};
update(progress: number, total?: number)
Update current progress, and optionally update total progress.
Returns updated object with measurements.
measure(tick = 1000)
Return measurements object
type Measurements = {
timeDelta: number;
averageTime: number;
progressLeft: number;
speed: number;
estimate: number;
};
estimate()
Return estimate
value
reset(time?: number)
Reset start time to provided or current time
now()
Return current timestamp
Related projects