JSPM

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

a simple timer 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 that enables recording ellapsed time and format the result.

Table of Contents

Install

npm install --save timer-node

API

require

const Timer = require('timer-node');

import

import Timer from 'timer-node';

Construction

const timer = new Timer('test-timer');

.start()

starts the timer

timer.start();

.stop()

stops the timer

timer.stop();

.isRunning()

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

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

.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

.format(template)

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

  • %lbl 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 = '%lbl [%s] s [%ms] ms';
console.log(timer.format(custom)); // test-timer [4] s [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