https://github.com/mathiasvr/tiny-timer
:clock2: Small countdown timer and stopwatch module.
https://github.com/mathiasvr/tiny-timer
countdown stopwatch timer
Last synced: 2 months ago
JSON representation
:clock2: Small countdown timer and stopwatch module.
- Host: GitHub
- URL: https://github.com/mathiasvr/tiny-timer
- Owner: mathiasvr
- License: mit
- Created: 2016-09-23T21:32:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-06-13T11:11:12.000Z (almost 4 years ago)
- Last Synced: 2025-03-15T11:50:20.404Z (3 months ago)
- Topics: countdown, stopwatch, timer
- Language: TypeScript
- Homepage:
- Size: 437 KB
- Stars: 40
- Watchers: 2
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-timer
[](https://npm.im/tiny-timer)
[](https://travis-ci.com/mathiasvr/tiny-timer)


[](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`.