https://github.com/annexare/idledetect
A TypeScript library for inactivity timer, which utilises `IdleDetector` API where possible or a fallback to `window.setTimeout` approach.
https://github.com/annexare/idledetect
cypress-tests idledetector inactivity-timer timeout typescript
Last synced: about 2 months ago
JSON representation
A TypeScript library for inactivity timer, which utilises `IdleDetector` API where possible or a fallback to `window.setTimeout` approach.
- Host: GitHub
- URL: https://github.com/annexare/idledetect
- Owner: annexare
- License: mit
- Created: 2021-12-23T22:20:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-06T12:37:32.000Z (over 1 year ago)
- Last Synced: 2025-03-16T01:23:50.648Z (3 months ago)
- Topics: cypress-tests, idledetector, inactivity-timer, timeout, typescript
- Language: TypeScript
- Homepage:
- Size: 68.4 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Idle Detect
[](https://github.com/annexare/IdleDetect/actions/workflows/tests.yml)
[](https://www.npmjs.com/package/idle-detect)A TypeScript library for inactivity timer, which utilises [IdleDetector API](https://developer.mozilla.org/en-US/docs/Web/API/IdleDetector) where possible or a fallback to `window.setTimeout` approach.
## Usage
```bash
npm install idle-detect
``````ts
import IdleDetect from 'idle-detect'
// Or, if you don't want to use still experimental IdleDetector API:
// import { IdleDetect } from 'idle-detect/dist/IdleDetect'const onInactive = () => {
console.info('User is inactive now')
}
const idleDetect = new IdleDetect(15 * 60, onInactive)// Start timer, e.g. when user is logged in
idleDetect.start()// End timer, e.g. when user is logged out
idleDetect.cleanupAndStop()
```