# setinterval-bykey

> A simple Node.js utility to manage multiple named intervals easily.

Latest version **1.0.3** (published 2025-07-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install setinterval-bykey
pnpm add setinterval-bykey
yarn add setinterval-bykey
bun add setinterval-bykey
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2025-07-25 |
| First published | 2023-03-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | SLASH |
| Maintainers | slash2 |
| Keywords | interval, timeout, ms, setInterval, interval, timer, nodejs, utility, interval-manager |

## Links

- npm: https://www.npmjs.com/package/setinterval-bykey
- Repository: https://github.com/Youssef-mohamed-developer/setinterval-bykey
- Homepage: https://github.com/Youssef-mohamed-developer/setinterval-bykey#readme
- Issues: https://github.com/Youssef-mohamed-developer/setinterval-bykey/issues
- npm.io page: https://npm.io/package/setinterval-bykey

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [@codegrenade/naija-faker-mcp](https://npm.io/package/@codegrenade/naija-faker-mcp.md) — 0 weekly downloads
- [@hainaio/page-spy-plugin-ospy](https://npm.io/package/@hainaio/page-spy-plugin-ospy.md) — 0 weekly downloads
- [@hainaio/page-spy-browser](https://npm.io/package/@hainaio/page-spy-browser.md) — 0 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2025-07-25
- 1.0.2 — 2023-04-13
- 1.0.1 — 2023-03-20
- 1.0.0 — 2023-03-18

## README

# Interval Manager
- A lightweight and easy-to-use Node.js utility to manage multiple named intervals.

---

## Features
- Start multiple intervals identified by unique keys.
- Check if a specific interval is running by its key.
- Clear individual intervals or all intervals at once.
- Throws clear errors on invalid input.
- Minimal dependencies, pure Node.js timer management.

---

## Installation
```shell
npm install setinterval-bykey
```

---

## Usage
```js
const intervalManager = require('interval-manager');

// Start an interval that logs "Hello" every second
intervalManager.start(() => {
  console.log('Hello');
}, 1000, 'greeting');

// Check if 'greeting' interval is running
console.log(intervalManager.isRunning('greeting')); // true

// Stop the 'greeting' interval after 5 seconds
setTimeout(() => {
  intervalManager.clear('greeting');
  console.log('Greeting interval stopped');
}, 5000);
```

---

## API
### `start(fn, interval, key)`
Starts a new `interval` with the callback function `fn` running every interval milliseconds under the identifier `key`.

Throws `TypeError` if parameters are invalid.

Returns `true` if interval started successfully, or `false` if an interval with the same key already exists.

### `isRunning(key)`
Checks if an interval under the given `key` is currently active.

Throws `TypeError` if `key` is invalid.

Returns `true` if running, otherwise `false`.

### `clear(key)`
Stops and removes the interval identified by `key`.

Throws `TypeError` if `key` is invalid.

Returns `true` if interval was cleared, or `false` if no interval found under that key.

### `clearAll()`
Stops and clears all running intervals.

---

## 📜 License

MIT

---

## ✍️ Author

Youssef Mohamed - (SLASH)

## 🔗 Links
- [npm](https://www.npmjs.com/~slash2)
- [GitHub](https://github.com/Youssef-mohamed-developer)
- [Discord](https://discord.gg/kEWDQZH9xp)

Feel free to open issues or contribute! 🚧

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