Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/molvqingtai/timer
⏰ Short and sweet timer based on requestAnimationFrame API
https://github.com/molvqingtai/timer
Last synced: 2 months ago
JSON representation
⏰ Short and sweet timer based on requestAnimationFrame API
- Host: GitHub
- URL: https://github.com/molvqingtai/timer
- Owner: molvqingtai
- License: mit
- Created: 2021-05-08T15:21:13.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-26T11:30:24.000Z (3 months ago)
- Last Synced: 2024-10-18T07:07:18.659Z (3 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@resreq/timer
- Size: 456 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Timer
[![version](https://img.shields.io/github/v/release/molvqingtai/timer)](https://www.npmjs.com/package/timer) [![workflow](https://github.com/molvqingtai/timer/actions/workflows/ci.yml/badge.svg)](https://github.com/molvqingtai/timer/actions) [![download](https://img.shields.io/npm/dt/@resreq/timer)](https://www.npmjs.com/package/@resreq/timer) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
⏰ Short and sweet timer based on requestAnimationFrame API
## Install
```shell
npm install @resreq/timer
```## Usage
```typescript
import Timer from '@resreq/timer'const log = (time: number) => console.log('time:', time)
const timer = new Timer(log, {
delay: 1000,
immediate: true
})timer.on('start', (time) => {
console.log('start:', time)
})
timer.on('pause', (time) => {
console.log('pause:', time)
})
timer.on('stop', (time) => {
console.log('stop:', time)
})timer.start()
setTimeout(() => timer.pause(), 1000)
setTimeout(() => timer.start(), 2000)
setTimeout(() => timer.stop(), 3000)// => start: 1712160512855
// => time: 1712160512858
// => pause: 1712160513855
// => start: 1712160514855
// => time: 1712160514855
// => stop: 1712160515855
```## LICENSE
This project is licensed under the MIT License - see the [LICENSE](https://github.com/molvqingtai/timer/blob/main/LICENSE) file for details.