From 79632d36c34026561b2451af3f7a49205194575d Mon Sep 17 00:00:00 2001 From: Vlad Tansky Date: Mon, 27 Apr 2020 13:54:54 +0300 Subject: [PATCH] Update README.md --- README.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fbdd31d..81286d8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Elapsed time logger Similiar to console.time() & console.timeEnd() but returns formatted elapsed time `custom label: 4 hours 10 minutes 23.5 seconds` or if less then a second: `540ms` +Works in NodeJS and in browser. ![CircleCI](https://img.shields.io/circleci/build/github/vltansky/elapsed-time-logger) [![Coverage Status][coveralls-image]][coveralls-url] @@ -11,13 +12,14 @@ Similiar to console.time() & console.timeEnd() but returns formatted elapsed tim [coveralls-image]: https://img.shields.io/coveralls/github/vltansky/elapsed-time-logger [coveralls-url]: https://coveralls.io/github/vltansky/elapsed-time-logger -package have only one dependency +package depends on [Browser-hrtime](https://github.com/vltansky/browser-hrtime) # Install `$ npm i elapsed-time-logger` # Usage +## NodeJS ``` -const elapsed = require("elapsed-time-logger"); +const { elapsed } = require("elapsed-time-logger"); // chalk is't required, added as example to show that you can use colors in output const chalk = require('chalk'); @@ -40,3 +42,26 @@ setTimeout(()=>{ elapsedTimer.end('finished:');// output: finished: 806ms }, 800); ``` + +## ESM (Browser e.g Angular, react, etc.) +``` +import elapsed from 'elapsed-time-logger'; +// elapsed is similliar to console.time() & console.timeEnd() +elapsed.start('label'); +elapsed.start('label_id'); +setTimeout(()=>{ + elapsed.end('label');//output: label 801ms + elapsed.end('label_id', 'Text that goes here will override label on output'); + // output: Text that goes here will override label on output 801ms +}, 800); +// if paramter label is not provided, start() will return an instance +const elapsedTimer = elapsed.start(); +const elapsedTimer2 = elapsed.start(); +setTimeout(()=>{ + elapsedTimer2.end('elapsed2:'); + // output: you can use colors here, try chalk or colors packages: 806ms + const time = elapsedTimer.get();//return 806ms + console.log(time); + elapsedTimer.end('finished:');// output: finished: 806ms +}, 800); +```