1 | # each-arg
|
2 |
|
3 | [![CircleCI](https://circleci.com/gh/manferlo81/each-arg.svg?style=svg)](https://circleci.com/gh/manferlo81/each-arg) [![Greenkeeper badge](https://badges.greenkeeper.io/manferlo81/each-arg.svg)](https://greenkeeper.io/) [![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) [![install size](https://packagephobia.now.sh/badge?p=each-arg)](https://packagephobia.now.sh/result?p=each-arg) [![npm bundle size](https://img.shields.io/bundlephobia/min/each-arg.svg)](https://bundlephobia.com/result?p=each-arg) [![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 |
|
5 | Iterates through arguments or any other array-like object starting from specific index.
|
6 |
|
7 | ## Install
|
8 |
|
9 | ```bach
|
10 | npm 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
|
48 | eachArg(arr, start, callback(value, index, ...extra): any, ...extra): void;
|
49 | ```
|
50 |
|
51 | Iterates 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 |
|
53 | If the `callback` returns a truthy value the iteration will stop.
|
54 |
|
55 | Any `extra` argument passed to `eachArg` function will be passed down to the `callback` function.
|
56 |
|
57 | The `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.
|
58 |
|
59 | ```typescript
|
60 | eachArg.call(thisArg, arr, start, callback, ..extra);
|
61 | ```
|
62 |
|
63 | ##### example
|
64 |
|
65 | ```javascript
|
66 | import eachArg from "each-arg";
|
67 |
|
68 | eachArg([1, 2, 3, 4, 5], 1, (value, index, num) => {
|
69 | console.log(value + " >> " + (index + num));
|
70 | return index === 3;
|
71 | }, 100);
|
72 | ```
|
73 |
|
74 | ```console
|
75 | 2 >> 101
|
76 | 3 >> 102
|
77 | 4 >> 103
|
78 | ```
|
79 |
|
80 | ## License
|
81 |
|
82 | [MIT](LICENSE) © [Manuel Fernández](https://github.com/manferlo81)
|