Socket
Socket
Sign inDemoInstall

timerize

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timerize

> A timy timer package to time things !


Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

timerize

A timy timer package to time things !

Installation

npm i timerize

Usage

// If you use Node / CommonJS / not a ES2015 module compiler
const Timer = require('timerize').default;

// If you use TypeScript / a ES2015 module-compatible navigator/compiler
import Timer from 'timerize';


const timer = new Timer;

console.log(timer.elapsed); // 12 for exemple

// Change the format of number output
timer.format = "s";

console.log(timer.elapsed); // 1.123 for exemple

// Change the default format for every new Timer instances and instance with unchanged format
Timer.default_format = "s";

timer.pause();

// do things

timer.start();

// ...

Important note:

The timer does not consume any resource when it is "running". Calculations are made when you get the elapsed time.

You can leave him without call pause() and waiting for it became garbage-collected.

Reference

@@constructor

You can provide two optional arguments: time (starting time, default Date.now()) and format (default Timer.default_format). Timer automatically starts after instanciation, you do not need to call .start() !

const timer = new Timer(Date.now(), "s");

elapsed

Get elapsed time according to desired format

const elapsed_time = timer.elapsed;

format

Change the elapsed time format output. Default format is ms.

Accepted formats are ms, s, m, h and d, for milliseconds, seconds, minutes, hours and days.

timer.format = "m";

You can also change defaut format for new instances (and instances that does not have a specified format) with Timer.default_format

Timer.default_format = "s";

pause()

Pause the timer. You can optionnaly specify a number of milliseconds of how much time the timer should restart automatically.

If the timer is already paused, it will have no action.

timer.pause(ms?);

start()

Start the timer after a pause.

If the timer was not paused, it will be reset.

timer.start();

paused

Check if the timer is paused.

if (timer.paused) {
    // do sth
}

FAQs

Package last updated on 11 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc