The minimal idle state detector.
npm install idle-timeout



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.
``bash`
npm install idle-timeout
`bash`
pnpm add idle-timeout
`bash`
yarn add idle-timeout
`html`
idleTimeout is totally easy to use. All you need to do is:
`js
import idleTimeout from 'idle-timeout';
idleTimeout(() => {
console.log('Idle state detected.');
});
`
The idleTimeout constructor takes two arguments:
- callback [Function] - _The callback function (receives element and timeout as arguments)_element [Element]
- - _The element that was listened for the timeout_timeout [Number]
- - _The current timeout value in milliseconds_options [Object]
- - _An optional options object_element [Element]
- - _The element to listen for the timeout_timeout [Number]
- - _The idle timeout (in milliseconds)_loop [Boolean]
- - _Whether the timeout should be looped when idle_
`jsIdle state detected on ${element} after ${timeout} ms
const instance = idleTimeout(
(element, timeout) => {
console.log();`
},
{
element: document,
timeout: 1000 60 5,
loop: false
}
);
pause() - _Pauses the timeout_
`js`
instance.pause();
resume() - _Resumes an paused timeout_
`js`
instance.resume();
reset() - _Reset the timeout_
`js`
instance.reset();
destroy() - _Destroy the instance_
`js`
instance.destroy();
idle [Boolean] - _Whether the current state is idle_
`js`
instance.idle; // false
timeout = value [Number] - _Set the timeout (in milliseconds)_
`js`
instance.timeout = 1000 * 60;
loop = value [Boolean] - _Set whether the timeout should be looped_
`js`
instance.loop = true;
idle = value [Boolean] - _Set the idle state_
`js``
instance.idle = true;
This project is licensed under the terms of the MIT License.