JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 28359
  • Score
    100M100P100Q131806F
  • License MIT

a simple timer object in nodejs

Package Exports

  • timer-node

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (timer-node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

timer-node

build:? npm npm npm

A simple timer object that enables recording time and format the result.

Install

npm install --save timer-node

Usage

Creation

const timerFn = require('timer-node');
const timer = timerFn('test-timer');

.start()

starts the timer

timer.start();

.stop()

stops the timer

timer.stop();

.seconds()

return the seconds part in the recorded time

console.log(timer.seconds()); // 4

.milliseconds()

return the milliseconds part in the recorded time

console.log(timer.milliseconds()); // 254

.microseconds()

return the microseconds part in the recorded time

console.log(timer.microseconds()); // 782

.nanoseconds()

return the nanoseconds part in the recorded time

console.log(timer.nanoseconds()); // 615

.isRunning()

checks if the timer is running and hasn't been stopped

console.log(timer.isRunning()); // false

.isStopped()

checks if the timer has been stopped

console.log(timer.isStopped()); // true

.format(template)

formats the recorded time using a custom or default template. The function replaces the time fractions placeholders in a string. Placeholders are:

  • %label for the timer label.
  • %s for the seconds.
  • %ms for the milliseconds.
  • %us for the microseconds.
  • %ns for the nanoseconds.
// using the default template
console.log(timer.format()); // test-timer: 4 s, 254 ms, 782 us, 615 ns

// using a custom template
const custom = '%label: [%s secs %ms ms]';
console.log(timer.format(custom)); // test-timer: [4 secs 254 ms]

.clear()

clears the timer values. Can be started again to record new time.

timer.clear();
console.log(timer.seconds()); // null

Build

grunt build

License

The MIT License. Full License is here