https://github.com/kamdz/incrementator
🔂 A lightweight TypeScript utility for iterating over multiple numeric parameters with flexible control.
https://github.com/kamdz/incrementator
increment loop range step
Last synced: 17 days ago
JSON representation
🔂 A lightweight TypeScript utility for iterating over multiple numeric parameters with flexible control.
- Host: GitHub
- URL: https://github.com/kamdz/incrementator
- Owner: kamdz
- License: mit
- Created: 2025-03-08T19:02:41.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-03-08T19:23:44.000Z (10 months ago)
- Last Synced: 2025-03-08T19:28:52.532Z (10 months ago)
- Topics: increment, loop, range, step
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/incrementator
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 🔂 incrementator
A lightweight TypeScript utility for iterating over multiple numeric parameters with flexible control.
The `incrementator` utility can be seen as a replacement for traditional nested loops.
Using `incrementator` simplifies the iteration process, especially when working with multiple parameters and dynamic step functions.
## 🚀 Features
- Iterate over multiple parameters simultaneously
- Support for dynamic step functions
- Flexible stop conditions (fixed or function-based)
- Efficient iteration without unnecessary computations
## 🛠️ Installation
```sh
npm install incrementator
```
## 📖 Usage
```typescript
import incrementator from "incrementator";
incrementator(
{
x: { start: 0, stop: 2, step: 1 },
y: { start: 5, stop: 3, step: -0.5 },
},
({ x, y }) => console.log(`x=${x}, y=${y}`)
);
// Output:
// x=0, y=5
// x=0, y=4.5
// x=0, y=4
// x=0, y=3.5
// x=0, y=3
// x=1, y=5
// Equivalent code with for loops
// for (let x = 0; x < 2; x++) {
// for (let y = 5; y >= 3; y -= 0.5) {
// console.log(`x=${x}, y=${y}`);
// }
// }
incrementator(
{
a: { start: 1, stop: 10, step: (current) => current * 2 },
},
({ a }) => console.log(`a=${a}`)
);
// Output:
// a=1
// a=2
// a=4
// a=8
// Equivalent code with while loop
// let a = 1;
// while (a < 10) {
// console.log(`a=${a}`);
// a *= 2;
// }
```
## 🔧 API
### `incrementator(config, callback)`
Iterates over multiple numeric parameters, calling `callback` for each combination.
- `config: Record` – Configuration object where each key defines a parameter and its value is an object with the following properties:
- `start: number` – Initial value.
- `stop: number | (current: number) => boolean` – Fixed stop value or a function to determine when to stop.
- `step: number | (current: number) => number` – Fixed step value or a function to compute the next value.
- `callback: (values: Record) => void` – Function executed for each combination of values.