@pipeletteio/time-meter
v2.0.2
Published
A minimal Node.js time-meter to calculate time between anything
Downloads
10
Readme
Installation
npm install @pipeletteio/time-meter
Docs:
Read documentation here.
Example:
const { TimeMeter } = require('@pipeletteio/time-meter');
const meter = new TimeMeter();
setTimeout(() => console.log(`${meter.next()}ms`), 200);
With Typescript:
import { TimeMeter } from '@pipeletteio/time-meter';
const meter = new TimeMeter();
setTimeout(() => console.log(`${meter.next()}ms`), 200);
A shared time meter instance can be retreived from the package (default meter uses the milisecond format):
import { meter } from '@pipeletteio/time-meter';
Using a custom formatter (availables: LegacyFormatter
, MilisecondFormatter
and NanosecondFormatter
):
import { TimeMeter, LegacyFormatter } from '@pipeletteio/time-meter';
const meter = new TimeMeter({ formatter: new LegacyFormatter() });
setTimeout(() => {
const [seconds, nanoseconds] = meter.next();
console.log(`${seconds}s ${nanoseconds}ns`);
}, 200);
Using your own formatter:
import { TimeMeter, TimeFormatterInterface } from '@pipeletteio/time-meter';
class SecondFormatter implements TimeFormatterInterface {
static DIVIDER = BigInt(1e9);
format (ns: bigint): number {
return Number(ns / SecondFormatter.DIVIDER);
}
}
const meter = new TimeMeter({ formatter: new SecondFormatter() });
setTimeout(() => console.log(`${meter.next()}s`), 1500);