# tiny-timer

> Small countdown timer and stopwatch module.

Latest version **1.6.0** (published 2021-01-21) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2021-01-21 |
| First published | 2016-09-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 38 |
| Author | Mathias Rasmussen |
| Maintainers | mathiasvr |
| Keywords | countdown, stopwatch, timer |

## Links

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

## Dependencies (1)

- [mitt](https://npm.io/package/mitt.md) ^2.1.0

## Recent versions

- 1.6.0 (latest) — 2021-01-21
- 1.5.1 — 2020-11-18
- 1.5.0 — 2020-05-26
- 1.4.0 — 2019-07-31
- 1.3.0 — 2018-11-27
- 1.2.0 — 2018-06-19
- 1.1.1 — 2016-10-11
- 1.1.0 — 2016-10-06
- 1.0.2 — 2016-09-24
- 1.0.1 — 2016-09-23
- 1.0.0 — 2016-09-23

## README

# tiny-timer

[![npm](https://img.shields.io/npm/v/tiny-timer.svg)](https://npm.im/tiny-timer)
[![Build Status](https://travis-ci.com/mathiasvr/tiny-timer.svg?branch=master)](https://travis-ci.com/mathiasvr/tiny-timer)
![downloads](https://img.shields.io/npm/dt/tiny-timer.svg)
[![dependencies](https://david-dm.org/mathiasvr/tiny-timer.svg)](https://david-dm.org/mathiasvr/tiny-timer)
[![license](https://img.shields.io/:license-MIT-blue.svg)](https://mvr.mit-license.org)

Small countdown timer and stopwatch module.

## Installation
npm:
```shell
$ npm install tiny-timer
```
Yarn:
```shell
$ yarn add tiny-timer
```

## Example
```javascript
const Timer = require('tiny-timer')

const timer = new Timer()

timer.on('tick', (ms) => console.log('tick', ms))
timer.on('done', () => console.log('done!'))
timer.on('statusChanged', (status) => console.log('status:', status))

timer.start(5000) // run for 5 seconds
```

## Usage

### `timer = new Timer({ interval: 1000, stopwatch: false })`
Optionally set the refresh `interval` in ms, or `stopwatch` mode instead of countdown.

### `timer.start(duration [, interval])` {
Starts timer running for a `duration` specified in ms.
Optionally override the default refresh `interval` in ms.

### `timer.stop()`
Stops timer.

### `timer.pause()`
Pauses timer.

### `timer.resume()`
Resumes timer.

## Events

### `timer.on('tick', (ms) => {})`
Event emitted every `interval` with the current time in ms.

### `timer.on('done', () => {})`
Event emitted when the timer reaches the `duration` set by calling `timer.start()`.

### `timer.on('statusChanged', (status) => {})`
Event emitted when the timer status changes.

## Properties

### `timer.time`
Gets the current time in ms.

### `timer.duration`
Gets the total `duration` the timer is running for in ms.

### `timer.status`
Gets the current status of the timer as a string: `running`, `paused` or `stopped`.

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