Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobmllr95/idle-timeout
A basic idle state detector written in ES6.
https://github.com/jacobmllr95/idle-timeout
Last synced: 5 days ago
JSON representation
A basic idle state detector written in ES6.
- Host: GitHub
- URL: https://github.com/jacobmllr95/idle-timeout
- Owner: jacobmllr95
- License: mit
- Created: 2016-03-29T23:16:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-20T15:52:44.000Z (over 1 year ago)
- Last Synced: 2024-10-10T12:42:41.216Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/idle-timeout
- Size: 545 KB
- Stars: 24
- Watchers: 1
- Forks: 5
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [idleTimeout](https://github.com/jackmu95/idle-timeout/)
[![Version](https://badgen.net/npm/v/idle-timeout)](https://www.npmjs.com/package/idle-timeout/)
[![Size](https://badgen.net/bundlephobia/min/idle-timeout)](https://bundlephobia.com/result?p=idle-timeout)
[![License](https://badgen.net/npm/license/idle-timeout)](https://github.com/jackmu95/idle-timeout/blob/master/LICENSE)A zero dependency, ~3KB library to make idle state detection in the browser an ease. With it's simple but yet powerful API it features everything you will ever need.
## Installation
### Using npm
```bash
npm install idle-timeout
```### Using yarn
```bash
yarn add idle-timeout
```### Using CDN
```html
```
## Usage
idleTimeout is totally easy to use. All you basically need to do is:
```javascript
idleTimeout(() => {
// Do some cool stuff
});
```## Documentation
The idleTimeout constructor takes two arguments:
- `callback [Function]` - _The callback function_
- `options [Object]` - _An **optional** options object_
- `element [Element]` - _The element to listen for the timeout_
- `timeout [Number]` - _The idle timeout (in milliseconds)_
- `loop [Boolean]` - _Wether the timeout should be looped when idle_```javascript
const instance = idleTimeout(
() => {
// Callback
},
{
element: document,
timeout: 1000 * 60 * 5,
loop: false
}
);
```### Methods
`pause()` - _Pauses the timeout_
```javascript
instance.pause();
````resume()` - _Resumes an paused timeout_
```javascript
instance.resume();
````reset()` - _Reset the timeout_
```javascript
instance.reset();
````destroy()` - _Destroy the instance_
```javascript
instance.destroy();
```### Getters
`idle [Boolean]` - _Wether the current state is idle_
```javascript
instance.idle; // false
```### Setters
`timeout = value [Number]` - _Set the timeout (in milliseconds)_
```javascript
instance.timeout = 1000 * 60;
````loop = value [Boolean]` - _Set wether the timeout should be looped_
```javascript
instance.loop = true;
````idle = value [Boolean]` - _Set the idle state_
```javascript
instance.idle = true;
```## Browser Support
| Chrome
| Firefox
| Safari
| Opera
| Edge
| IE
|
| :-------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| Latest 2 | Latest 2 | Latest 2 | Latest 2 | Latest 2 | 11 |## License
This project is licensed under the terms of the [MIT License](LICENSE).