Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

wavevision/timer

Repository files navigation

Wavevision s.r.o.

Timer

CI Coverage Status npm

Simple utility for creating resumable timeouts written in TypeScript. Works both in Node and browser environments.

Installation

Via Yarn

yarn add @wavevision/timer

or npm

npm install --save @wavevision/timer

Usage

Create your own timer.

import timer from '@wavevision/timer';

timer(() => alert('Time is up!'), 1000);
// this timer will be auto-started
timer(() => alert('Hello!'), 500, true);

The returned object exposes following functions:

  • clear(): void – clears the timeout
  • pause(): number – pauses the timeout, returns remaining time
  • remains(): number – returns remaining time
  • restart(): void – clears and starts the timeout over again
  • resume(): void – resumes the timeout (or starts if not running)
  • running(): boolean – returns whether the timeout is running at the moment
  • start(): void – starts the timeout (or resumes if paused)