UNPKG

2.86 kBMarkdownView Raw
1# each-arg
2
3[![CircleCI](https://circleci.com/gh/manferlo81/each-arg.svg?style=svg)](https://circleci.com/gh/manferlo81/each-arg) [![npm](https://img.shields.io/npm/v/each-arg.svg)](https://www.npmjs.com/package/each-arg) [![jsdelivr](https://data.jsdelivr.com/v1/package/npm/each-arg/badge?style=rounded)](https://www.jsdelivr.com/package/npm/each-arg) [![dependencies Status](https://david-dm.org/manferlo81/each-arg/status.svg)](https://david-dm.org/manferlo81/each-arg) [![devDependencies Status](https://david-dm.org/manferlo81/each-arg/dev-status.svg)](https://david-dm.org/manferlo81/each-arg?type=dev) [![npm type definitions](https://img.shields.io/npm/types/each-arg.svg)](https://github.com/microsoft/TypeScript) [![codecov](https://codecov.io/gh/manferlo81/each-arg/branch/master/graph/badge.svg)](https://codecov.io/gh/manferlo81/each-arg) [![Known Vulnerabilities](https://snyk.io/test/github/manferlo81/each-arg/badge.svg?targetFile=package.json)](https://snyk.io/test/github/manferlo81/each-arg?targetFile=package.json) [![license](https://img.shields.io/npm/l/each-arg.svg)](LICENSE)
4
5Iterates through arguments or any other array-like object starting from specific index.
6
7## Install
8
9```bach
10npm i each-arg
11```
12
13## CDN
14
15### jsDelivr
16
17```html
18<script src="https://cdn.jsdelivr.net/npm/each-arg@latest/dist/each-arg.umd.js">
19```
20
21*for production...*
22
23```html
24<script src="https://cdn.jsdelivr.net/npm/each-arg@latest/dist/each-arg.umd.min.js">
25```
26
27[more options...](https://www.jsdelivr.com/package/npm/each-arg?version=latest)
28
29### unpkg
30
31```html
32<script src="https://unpkg.com/each-arg@latest/dist/each-arg.umd.js">
33```
34
35*for production...*
36
37```html
38<script src="https://unpkg.com/each-arg@latest/dist/each-arg.umd.min.js">
39```
40
41[more options...](https://unpkg.com/each-arg@latest/)
42
43## Usage
44
45##### syntax
46
47```typescript
48eachArg(arr, start, callback(value, index, ...extra): any, ...extra): void;
49```
50
51Iterates over the `array` or `array-like` `arr` starting from the `start` index. The `callback` function will be called for every `value` in the array, with the `value` itself, the `index` of the current item and any `extra` argument passed to `eachArg` function.
52
53Any `extra` argument passed to `eachArg` function will be passed down to the `callback` function.
54
55The `callback` function inherits the `this` value form the `eachArg` function call. If you need a specific value inside the `callback`, call `eachArg` using it's `call` method.
56
57```typescript
58eachArg.call(thisArg, arr, start, callback, ..extra);
59```
60
61##### example
62
63```javascript
64import eachArg from "each-arg";
65
66eachArg([1, 2, 3, 4, 5], 1, (value, index, num) => {
67 console.log(value + " >> " + (index + num));
68 return index === 3;
69}, 100);
70```
71
72```console
732 >> 101
743 >> 102
754 >> 103
76```
77
78## License
79
80[MIT](LICENSE) &copy; [Manuel Fernández](https://github.com/manferlo81)