UNPKG

3.73 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) [![dependabot](https://badgen.net/dependabot/manferlo81/each-arg?icon=dependabot)](https://dependabot.com) [![npm](https://badgen.net/npm/v/each-arg)](https://www.npmjs.com/package/each-arg) [![codecov](https://codecov.io/gh/manferlo81/each-arg/branch/master/graph/badge.svg)](https://codecov.io/gh/manferlo81/each-arg) [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/each-arg/badge?style=rounded)](https://www.jsdelivr.com/package/npm/each-arg) [![dependencies](https://badgen.net/david/dep/manferlo81/each-arg)](https://david-dm.org/manferlo81/each-arg) [![dev dependencies](https://badgen.net/david/dev/manferlo81/each-arg)](https://david-dm.org/manferlo81/each-arg?type=dev) [![packagephobia](https://badgen.net/packagephobia/install/each-arg)](https://packagephobia.now.sh/result?p=each-arg) [![bundlephobia](https://badgen.net/bundlephobia/min/each-arg)](https://bundlephobia.com/result?p=each-arg) [![types](https://img.shields.io/npm/types/each-arg.svg)](https://github.com/microsoft/typescript) [![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://badgen.net/npm/license/each-arg)](LICENSE)
4
5Iterates through arguments or any other array-like object starting from a 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## Reference
44
45***syntax***
46
47```typescript
48eachArg(arr, start, callback(value, index, ...extra): any, ...extra): void;
49```
50
51*Iterates over the* `array`*,* `string` *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 a negative* `start` *index is provided the iteration will start from* `X` *number of items counting from the last item in the input array-like.*
54
55*If the* `callback` *returns a truthy value the iteration will stop.*
56
57*Any* `extra` *argument passed to* `eachArg` *function will be passed down to the* `callback` *function.*
58
59*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.*
60
61```typescript
62eachArg.call(thisArg, arr, start, callback, ..extra);
63```
64
65***example***
66
67```javascript
68import eachArg from "each-arg";
69
70eachArg([1, 2, 3, 4, 5], 1, (value, index, num) => {
71 console.log(value + " >> " + (index + num));
72 return index === 3;
73}, 100);
74```
75
76```console
772 >> 101
783 >> 102
794 >> 103
80```
81
82## Usage
83
84### Node.js
85
86```javascript
87const eachArg = require("each-arg");
88eachArg(args, start, callback);
89```
90
91### Browser
92
93*After adding the* `script` *tag,* `eachArg` *function will be available globally through* `eachArg` *or* `window.eachArg`*.*
94
95```javascript
96eachArg(args, start, callback);
97```
98
99## License
100
101[MIT](LICENSE) &copy; [Manuel Fernández](https://github.com/manferlo81)