Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dherault/loopa

A loop for npm scripts
https://github.com/dherault/loopa

Last synced: 23 days ago
JSON representation

A loop for npm scripts

Awesome Lists containing this project

README

        

# loopa









Loopa is a for loop for scripts. It will execute a command n times before exiting.

## Installation

`npm install --dev loopa` or `npx loopa`

## Usage

`loopa 3 echo "a loop"`

```
a loop
a loop
a loop
```

`loopa 10 npm run some-script`

```
(some-script executed 10 times)
```

`loopa infinity echo "an infinite loop"`

```
an infinite loop
an infinite loop
an infinite loop
...
```

`loopa 3 1000 echo "one second interval"`

```
one second interval
one second interval
one second interval
```

## Usage with environment variables

Environment variables should be escaped:

`FOO=foo loopa 100 echo \$FOO`

```
foo
foo
foo
...
```

If you do not like escaping your environment variables you can do the following in your package.json file:

```json
{
"scripts": {
"loop": "loopa 100 npm run echo-foo",
"echo-foo": "FOO=foo echo $FOO"
}
}
```

## Accessing the iteration variable

The iteration variable is available under the `$I` (or `\$I`) env variable:

`loopa 4 echo \$I`

```
0
1
2
3
```

## License

MIT