Gathering detailed insights and metrics for iterare
Gathering detailed insights and metrics for iterare
Gathering detailed insights and metrics for iterare
Gathering detailed insights and metrics for iterare
npm install iterare
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.5
Supply Chain
99.5
Quality
75.8
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
288 Stars
56 Commits
10 Forks
6 Watchers
2 Branches
4 Contributors
Updated on Apr 02, 2025
Latest Version
1.2.1
Package Id
iterare@1.2.1
Size
13.43 kB
NPM Version
6.9.0
Node Version
8.17.0
Published on
Jun 06, 2020
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
lat. to repeat, to iterate
ES6 Iterator library for applying multiple transformations to a collection in a single iteration.
Ever wanted to iterate over ES6 collections like Map
or Set
with Array
-built-ins like map()
, filter()
, reduce()
?
Lets say you have a large Set
of URIs and want to get a Set
back that contains file paths from all file://
URIs.
The loop solution is very clumsy and not very functional:
1const uris = new Set(['file:///foo.txt', 'http:///npmjs.com', 'file:///bar/baz.txt']) 2const paths = new Set() 3for (const uri of uris) { 4 if (!uri.startsWith('file://')) { 5 continue 6 } 7 const path = uri.substr('file:///'.length) 8 paths.add(path) 9}
Much more readable is converting the Set
to an array, using its methods and then converting back:
1new Set( 2 Array.from(uris) 3 .filter(uri => uri.startsWith('file://')) 4 .map(uri => uri.substr('file:///'.length)) 5)
But there is a problem: Instead of iterating once, you iterate 4 times (one time for converting, one time for filtering, one time for mapping, one time for converting back). For a large Set with thousands of elements, this has significant overhead.
Other libraries like RxJS or plain NodeJS streams would support these kinds of "pipelines" without multiple iterations, but they work only asynchronously.
With this library you can use many methods you know and love from Array
and lodash while only iterating once - thanks to the ES6 iterator protocol:
1import iterate from 'iterare' 2 3iterate(uris) 4 .filter(uri => uri.startsWith('file://')) 5 .map(uri => uri.substr('file:///'.length)) 6 .toSet()
iterate
accepts any kind of Iterator or Iterable (arrays, collections, generators, ...) and returns a new Iterator object that can be passed to any Iterable-accepting function (collection constructors, Array.from()
, for of
, ...).
Only when you call a method like toSet()
, reduce()
or pass it to a for of
loop will each value get pulled through the pipeline, and only once.
This library is essentially
Benchmarks based on the examples above:
map
+ filter
Simulate iterating over a very lage Set of strings and applying a filter and a map on it.
Method | ops/sec |
---|---|
Loop | 466 ops/sec ±1.31% (84 runs sampled) |
iterare | 397 ops/sec ±2.01% (81 runs sampled) |
RxJS | 339 ops/sec ±0.77% (83 runs sampled) |
Array method chain | 257 ops/sec ±1.73% (79 runs sampled) |
Lodash | 268 ops/sec ±0.84% (81 runs sampled) |
IxJS (ES6) | 216 ops/sec ±0.81% (81 runs sampled) |
IxJS (ES5) | 141 ops/sec ±0.87% (77 runs sampled) |
filter
+ take
Simulate iterating over a very lage Set of strings and applying a filter on it, then taking only the first 1000 elements. A smart implementations should only apply the filter predicate to the first 5 elements.
Method | ops/sec |
---|---|
Loop | 3,059,466 ops/sec ±0.75% (88 runs sampled) |
iterare | 963,257 ops/sec ±0.68% (89 runs sampled) |
IxJS (ES6) | 424,488 ops/sec ±0.63% (89 runs sampled) |
RxJS | 168,853 ops/sec ±2.58% (86 runs sampled) |
IxJS (ES5) | 107,961 ops/sec ±1.88% (78 runs sampled) |
Lodash | 41.71 ops/sec ±1.15% (54 runs sampled) |
Array method chain | 24.74 ops/sec ±3.69% (45 runs sampled) |
Going a step further, if you only care about a specific number of elements in the end, only these elements will run through the pipeline:
1iterate(collection) 2 .filter(uri => uri.startsWith('file://')) 3 .take(5)
In this example, the filter predicate is called only until 5 elements have been found. The alternative with an array would call it for every element in the collection:
1Array.from(collection) 2 .filter(uri => uri.startsWith('file://')) 3 .slice(0, 5)
The source is written in TypeScript.
npm run build
compiles TSnpm run watch
compiles on file changesnpm test
runs testsnode lib/benchmarks/____
runs a benchmarkNo vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/29 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
84 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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