npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elapsed-time-logger

v1.1.7

Published

Similiar to console.time() but returns readable elapsed time e.g Label: 1 hour 20 minutes 10.3 seconds

Downloads

1,273

Readme

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.

Test Coverage Status David NPM

package depends on Browser-hrtime

1.28 KB (minified and gzipped)

Installation

npm install elapsed-time-logger # yarn add elapsed-time-logger

Examples

NodeJS

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');
 
// 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 parameter label is not provided, start() will return an instance 
const elapsedTimer = elapsed.start();
const elapsedTimer2 = elapsed.start();
setTimeout(()=>{
    elapsedTimer2.end(chalk.green('you can use colors here, try chalk or colors packages:'));
    // 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);

Web with module

import elapsed from 'elapsed-time-logger';

elapsed.start('testoverride');
setTimeout(()=>{
    elapsed.end('testoverride', 'override label');
}, 100);

elapsed.start('vlad');
setTimeout(()=>{
    const test = elapsed.get('vlad');
    console.log(test);
}, 1200);

// ElapsedLogger is similliar to console.time() & console.timeEnd() 
elapsed.start('label');
elapsed.start('timer label');
setTimeout(()=>{
    elapsed.end('label');
    elapsed.end('timer label');
}, 800);

// or use ElapsedLogger as an instance (recommended)
const elapsedTimer = elapsed.start();
setTimeout(()=>{
    const t = elapsedTimer.get();
    console.log(t);
    elapsedTimer.end('finished:');
}, 800);

Web

<script crossorigin src="https://unpkg.com/browser-hrtime/lib/hrtime.js"></script>
<script crossorigin src="https://unpkg.com/elapsed-time-logger/lib/elapsed-time-logger.min.js"></script>
    elapsedLogger.start('test2');
    setTimeout(()=>{
        elapsedLogger.end('test2');
    }, 1300);


    elapsedLogger.start('test');
    setTimeout(()=>{
        elapsedLogger.end('test');
    }, 1300);

    elapsedLogger.start('testoverride');
    setTimeout(()=>{
        elapsedLogger.end('testoverride', 'override label');
    }, 100);


    elapsedLogger.start('vlad');
    setTimeout(()=>{
        const test = elapsedLogger.get('vlad');
        console.log(test);
    }, 1200);

    // ElapsedLogger is similliar to console.time() & console.timeEnd() 
    elapsedLogger.start('label');
    elapsedLogger.start('timer label');
    setTimeout(()=>{
        elapsedLogger.end('label');
        elapsedLogger.end('timer label');
    }, 800);


    // or use ElapsedLogger as an instance (recommended)
    const elapsedTimer = elapsedLogger.start();
    // const elapsedTimer2 = elapsedLogger.start();
    console.log('smth');
    setTimeout(()=>{
        const t = elapsedTimer.get();
        console.log(t)
        elapsedTimer.end('finished:');
    }, 800);

Contribution

Clone project from Github

git clone [email protected]:vltansky/elapsed-time-logger.git

Install npm packages

cd elapsed-time-logger
npm install

Build sources

npm run build

Test

npm run test

=======

License

MIT