# idlejs

> Execute a function only when certain events on certain target element have or have not occured within given timeout.

Latest version **3.0.0** (published 2020-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install idlejs
pnpm add idlejs
yarn add idlejs
bun add idlejs
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2020-07-10 |
| First published | 2017-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 60.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Harun Urhan |
| Maintainers | harunurhan |
| Keywords | library, typescript, javascript, idle, idlejs, not-idlejs, module |

## Links

- npm: https://www.npmjs.com/package/idlejs
- Homepage: https://github.com/harunurhan/idlejs#readme
- Issues: https://github.com/harunurhan/idlejs/issues
- npm.io page: https://npm.io/package/idlejs

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2020-07-10
- 2.1.0 — 2020-03-27
- 2.0.1 — 2018-03-17
- 2.0.0 — 2017-12-07
- 1.1.0 — 2017-12-06
- 1.0.0 — 2017-12-06

## README

# idlejs

Execute a function only when certain events on certain target element have or have not occured within given timeout.

It's simple, configurable, typescript friendly and has an easy chainable API.

### Install

```bash
yarn add idlejs

npm install --save idlejs
```

### v2 to v3

#### Change imports from `idlejs/dist` to `idlejs`

```js
import { ... } from 'idjejs' 
```

### Idle

Excutes the callback function (`do`) when **none** of the specified events have occurred within given time, in other words when user is idle. 

#### Usage

```typescript
import { Idle } from 'idlejs';

// with predefined events on `document`
const idle = new Idle()
  .whenNotInteractive()
  .within(5)
  .do(() => logoutUser())
  .start();

// another example with custom events which are useful if events aren't bubbling up to the document
const idle = new Idle()
  .whenNot([{
    events: ['click', 'hover'],
    target: buttonEl,
  },
  {
    events: ['click', 'input'],
    target: inputEl,
  },
  ])
  .whenNotInteractive()
  .within(10)
  .do(logoutUser)
  .start();
```

For more features or examples please check the [tests](./src/idle.spec.ts) and [source]('./src/idle.ts) code.

### NotIdle

Executes the callback function (`do`), if at least **one** of the specified events have occured within given time, in other words when user is not idle or interactive.

#### Usage

```typescript
import { NotIdle } from 'idlejs';

// with predefined events on `document`
const idle = new Idle()
  .whenInteractive()
  .within(10)
  .do(() => log('user was active in the last 10 minutes'))
  .start();

// another example with custom events which are useful if events aren't bubbling up to the `document`
const notIdle = new NotIdle()
  .when([{
    events: ['click', 'hover'],
    target: buttonEl,
  },
  {
    events: ['click', 'input'],
    target: inputEl,
  },
  ])
  .whenInteractive()
  .within(10)
  .do(() => log('user was active in the last 10 minutes'))
  .start();
```

For more features or examples please check the [tests](./src/not-idle.spec.ts) and [source]('./src/not-idle.ts) code.

### Setting time

Second parameter of `within` is time unit in miliseconds, by default 60000 (a minute).

```typescript
// will trigger if nothing happens for 5 minutes
new Idle()
  .within(5)

// will trigger if nothing happens for 5 seconds
new Idle()
  .within(5, 1000)
```

---
_Source: https://npm.io/package/idlejs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
