# better-timer

> A promise-based timer that can be paused

Latest version **2.0.4** (published 2023-07-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install better-timer
pnpm add better-timer
yarn add better-timer
bun add better-timer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2023-07-21 |
| First published | 2020-06-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Felix Wotschofsky |
| Maintainers | feliskio |
| Keywords | pauseable, timer, node, browser |

## Links

- npm: https://www.npmjs.com/package/better-timer
- Repository: https://github.com/wotschofsky/better-timer
- Homepage: https://github.com/wotschofsky/better-timer#readme
- Issues: https://github.com/wotschofsky/better-timer/issues
- npm.io page: https://npm.io/package/better-timer

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.0.4 (latest) — 2023-07-21
- 2.0.3 — 2023-04-08
- 2.0.2 — 2023-03-29
- 2.0.1 — 2022-08-09
- 2.0.0 — 2021-12-11
- 1.0.0 — 2020-06-24

## README

[![npm](https://img.shields.io/npm/v/better-timer?style=flat-square)](https://www.npmjs.com/package/better-timer)

# better-timer

Timer class that supports both promises and multiple callbacks.

## Installation

Add the script to your project through a package manager:

`$ npm i better-timer`

or

`$ yarn add better-timer`

Alternatively you can also import the script found in the releases section on GitHub directly. If you choose this option you won't need to use imports going forward - everything will all be available to you automatically.

```html
<script src="better-timer.min.js"></script>
```

Or include through a public CDN:

```html
<script src="https://unpkg.com/better-timer@2/dist/better-timer.min.js"></script>
```

## General Api

```javascript
  new Timer(duration, ...callbacks)
```

## Code example

```javascript
  import Timer from 'better-timer';
  // OR
  const Timer = require('better-timer');

  // Duration in Milliseconds
  const duration = 1000;

  const timer = new Timer(duration, () => {
    // Callbacks are optional
    console.log('Callback executed!');
  });

  // Get promise and add "then" block
  timer.promise.then(() => {
    console.log('Promise resolved!');
  });

  // Pause timer
  timer.pause();

  // Resume timer
  timer.resume();

  // Cancel timer
  timer.cancel();
```

---
_Source: https://npm.io/package/better-timer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
