`Array#forEach()` but it’s possible to define where to move to next
Installations
npm install array-iterate
Score
99.2
Supply Chain
99.4
Quality
75.6
Maintenance
100
Vulnerability
100
License
Developer
wooorm
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
Yes
Node Version
17.0.1
NPM Version
8.1.0
Statistics
7 Stars
78 Commits
3 Forks
4 Watching
1 Branches
3 Contributors
Updated on 02 Apr 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
100,504,724
Last day
-2%
86,901
Compared to previous day
Last week
2.2%
527,858
Compared to previous week
Last month
9.9%
2,137,295
Compared to previous month
Last year
46.6%
20,827,519
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
array-iterate
Array#forEach()
but it’s possible to define where to move to next.
Contents
- What is this?
- When should I use this?
- Install
- Use
- API
- Types
- Compatibility
- Security
- Contribute
- License
What is this?
A tiny package that works just like forEach
, with one small difference.
When should I use this?
You can use this if for some weird reason—like I did—you have to sometimes skip a few places ahead or backwards when moving through an array.
Install
This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:
1npm install array-iterate
In Deno with esm.sh
:
1import {arrayIterate} from 'https://esm.sh/array-iterate@2'
In browsers with esm.sh
:
1<script type="module"> 2 import {arrayIterate} from 'https://esm.sh/array-iterate@2?bundle' 3</script>
Use
1import {arrayIterate} from 'array-iterate' 2 3let first = true 4 5arrayIterate( 6 [1, 2, 3, 4], 7 function (value, index, values){ 8 console.log(this, value, index, values) 9 10 // Repeat once. 11 if (first && index + 1 === values.length) { 12 first = false 13 return 0 14 } 15 }, 16 {hello: 'world'} 17)
Yields:
1{hello: 'world'}, 1, 0, [1, 2, 3, 4] 2{hello: 'world'}, 2, 1, [1, 2, 3, 4] 3{hello: 'world'}, 3, 2, [1, 2, 3, 4] 4{hello: 'world'}, 4, 3, [1, 2, 3, 4] 5{hello: 'world'}, 1, 0, [1, 2, 3, 4] 6{hello: 'world'}, 2, 1, [1, 2, 3, 4] 7{hello: 'world'}, 3, 2, [1, 2, 3, 4] 8{hello: 'world'}, 4, 3, [1, 2, 3, 4]
API
This package exports the identifier arrayIterate
.
There is no default export.
arrayIterate(values, callbackFn[, thisArg])
Perform the specified action for each element in an array (just like
Array#forEach()
).
When callbackFn
returns a number
, moves to the element at that index
next.
Parameters
values
(Array<*>
) — values to iterate overcallbackFn
(Function
) — function called for each element, can return theindex
to move to nextthisArg
(*
, optional) — optional object passed asthis
incallbackFn
Returns
undefined
.
function callbackFn(value, index, values)
Callback given to iterate
.
Parameters
this
(*
) — context object when given asthisArg
toarrayIterate
orundefined
value
(*
) — element in arrayindex
(number
) — index ofvalue
invalues
values
(Array.<*>
) — list
Returns
The optional index
to move to next (number
or undefined
)
Types
This package is fully typed with TypeScript.
It exports the additional type CallbackFn
.
Compatibility
This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.
Security
This package is safe, assuming that you don’t create an infinite loop by keeping on repeating.
Contribute
Yes please! See How to Contribute to Open Source.
License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/wooorm/array-iterate/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/wooorm/array-iterate/main.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/wooorm/array-iterate/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:15
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
Project has not signed or included provenance with any releases.
Details
- Warn: release artifact 1.1.4 not signed: https://api.github.com/repos/wooorm/array-iterate/releases/23133624
- Warn: release artifact 1.1.3 not signed: https://api.github.com/repos/wooorm/array-iterate/releases/17167209
- Warn: release artifact 1.1.2 not signed: https://api.github.com/repos/wooorm/array-iterate/releases/10546295
- Warn: release artifact 1.1.4 does not have provenance: https://api.github.com/repos/wooorm/array-iterate/releases/23133624
- Warn: release artifact 1.1.3 does not have provenance: https://api.github.com/repos/wooorm/array-iterate/releases/17167209
- Warn: release artifact 1.1.2 does not have provenance: https://api.github.com/repos/wooorm/array-iterate/releases/10546295
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 1 are checked with a SAST tool
Score
3.1
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More