Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky authored Apr 27, 2020
1 parent 1aee077 commit 79632d3
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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');
Expand All @@ -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);
```

0 comments on commit 79632d3

Please sign in to comment.