# high-res-timeout

> A high-resolution, object-oriented replacement for setTimeout() and setInterval(). Good for animations, progress indicators, carousels, you name it.

Latest version **1.0.11** (published 2020-10-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install high-res-timeout
pnpm add high-res-timeout
yarn add high-res-timeout
bun add high-res-timeout
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2020-10-24 |
| First published | 2018-04-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 18.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Travis Uribe |
| Maintainers | tvanc |
| Keywords | js, timer, timeout, javascript, setTimeout, setInterval, performance.now, DOMHighResTimeStamp, requestAnimationFrame |

## Links

- npm: https://www.npmjs.com/package/high-res-timeout
- Repository: https://github.com/truribe/high-res-timeout
- Issues: https://github.com/truribe/high-res-timeout/issues
- npm.io page: https://npm.io/package/high-res-timeout

## Dependencies (3)

- [raf](https://npm.io/package/raf.md) ^3.4.1
- [events](https://npm.io/package/events.md) ^3.2.0
- [performance-now](https://npm.io/package/performance-now.md) ^2.1.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.11 (latest) — 2020-10-24
- 1.0.10 — 2020-07-18
- 1.0.9 — 2020-05-02
- 1.0.8 — 2019-09-15
- 1.0.6 — 2018-04-26
- 1.0.5 — 2018-04-24
- 1.0.4 — 2018-04-17
- 1.0.3 — 2018-04-17
- 1.0.2 — 2018-04-16
- 1.0.1 — 2018-04-13
- 1.0.0 — 2018-04-13

## README

# High Res Timeout

A high-resolution, object-oriented replacement for setTimeout() and setInterval().
Good for animations, progress indicators, carousels, you name it.

## Installation

```bash
npm install --save-dev high-res-timeout
```

## Usage

### Simple timeout

```javascript
import HighResTimeout from "high-res-timeout"
const timeout = new HighResTimeout(250)
```

### Repeating timeout (setInterval)

```javascript
import HighResTimeout from "high-res-timeout"
const interval = new HighResTimeout(250, true)
```

### Lifecycle callbacks

#### As a Promise

```javascript
timeout
    .start()
    .then(() => console.log("I am complete!"))
    .catch(() => console.log("I've been stopped!"))
```

#### Events

```javascript
timeout.start()
    .on('complete', () => console.log('I am complete!'))
    .on('stop', () => console.log("I've stopped!"))
    .on('start', () => console.log("I've started!"))
    .on('reset', () => console.log("I've been reset!"))
    .on('tick', () => {
    	console.log(`I'm ${(timeout.progress * 100).toFixed(0))}% done`)
    });
```

### Methods and properties

#### Instance methods

| Method     | Chainable | Description                                                                                           |
| ---------- | --------- | ----------------------------------------------------------------------------------------------------- |
| start()    | &check;   | Starts the timeout. Takes into account time elapsed between previous calls to `start()` and `stop()`. |
| stop()     | &check;   | Stops the timeout.                                                                                    |
| reset()    | &check;   | Resets the timeout.                                                                                   |
| complete() | &check;   | Completes the timeout as if it had completed organically.                                             |
| then()     | &cross;   | Attach a callback that will be called when the timeout completes. Returns a Promise.                  |

#### Instance properties

| Property | Readable | Writable | Description                                                                      |
| -------- | -------- | -------- | -------------------------------------------------------------------------------- |
| duration | &check;  | &check;  | Get/set timeout duration.                                                        |
| progress | &check;  | &cross;  | Float between 0 and 1 indicating how much of the timeout's duration has elapsed. |
| running  | &check;  | &cross;  | Whether the timeout is currently counting down.                                  |

## Development

Use the following commands to perform code coverage after each change and to open a Browsersync tab to the coverage
reports.

```bash
npm run watch
npm run serve
```

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