https://github.com/wavevision/timer
⏱ Simple resumable timeout handler
https://github.com/wavevision/timer
browser node resumable timeout timer typescript
Last synced: 7 months ago
JSON representation
⏱ Simple resumable timeout handler
- Host: GitHub
- URL: https://github.com/wavevision/timer
- Owner: wavevision
- License: mit
- Created: 2020-01-13T16:21:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T13:41:27.000Z (over 2 years ago)
- Last Synced: 2024-04-25T05:02:16.332Z (over 1 year ago)
- Topics: browser, node, resumable, timeout, timer, typescript
- Language: TypeScript
- Homepage:
- Size: 1.65 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Timer
[](https://github.com/wavevision/timer/actions/workflows/ci.yml)
[](https://coveralls.io/github/wavevision/timer?branch=master)
[](https://www.npmjs.com/package/@wavevision/timer)Simple utility for creating resumable timeouts written in TypeScript. Works both in Node and browser environments.
## Installation
Via [Yarn](https://yarnpkg.com)
```bash
yarn add @wavevision/timer
```or [npm](https://npmjs.com)
```bash
npm install --save @wavevision/timer
```## Usage
Create your own timer.
```typescript
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)