Gathering detailed insights and metrics for axax
Gathering detailed insights and metrics for axax
Gathering detailed insights and metrics for axax
Gathering detailed insights and metrics for axax
npm install axax
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
510 Stars
236 Commits
22 Forks
8 Watching
2 Branches
10 Contributors
Updated on 06 Jun 2024
Minified
Minified + Gzipped
TypeScript (99.15%)
JavaScript (0.85%)
Cumulative downloads
Total Downloads
Last day
6.1%
2,805
Compared to previous day
Last week
-12.1%
16,928
Compared to previous week
Last month
35%
77,787
Compared to previous month
Last year
193.1%
587,488
Compared to previous year
A library of async iterator extensions for JavaScript including map
, reduce
,
filter
, flatMap
, pipe
and more.
1npm install axax # or yarn add axax
Async iterators are a useful way to handle asynchronous streams. This library adds a number of utility methods similar to those found in lodash, underscore, Ramda or RxJs.
Axax contains both transpiled es5 code as well as esnext code, the difference being that
esnext uses the native for await
syntax. In nodejs 10.x that gives approximately a 40% speedup.
1// use es5 if you want to support more browsers 2import { map } from "axax/es5/map"; 3 4// use esnext if you're only using node 10.x or supporting very new browsers 5import { map } from "axax/esnext/map";
fromEvent
turns DOM events into an iterable.
1import { fromEvent } from "axax/es5/fromEvent"; 2 3const clicks = fromEvent(document, 'click'); 4 5for await (const click of clicks) { 6 console.log('a button was clicked'); 7}
fromLineReader
turns a NodeJS LineReader into an async iterable.
The example below prints the lines from a file in upper case after
filtering out the empty ones.
1// create the line reading async iterable 2const lines = fromLineReader( 3 require("readline").createInterface({ 4 input: require("fs").createReadStream("./data/example.txt") 5 }) 6); 7 8// create a filter that removes empty lines 9const notEmpty = filter(line => line.length > 0); 10 11// convert to uppercase 12const toUpperCase = map(line => line.toUpperCase()); 13 14// go through each of the non empty lines 15for await (const line of pipe(notEmpty, toUpperCase)(lines)) { 16 console.log(line); 17}
Subject
makes it easy to turn stream of events into an iterable. The code below
is essentially how fromEvent
was implemented.
1import { Subject } from "axax/es5/subject"; 2 3const subject = new Subject(); 4 5// set up a callback that calls value on the subject 6const callback = value => subject.onNext(value); 7 8// attach the callback to the click event 9document.addEventListener('click', callback); 10 11// remove the callback when / if the iterable stops 12subject.finally(() => document.removeEventListener('click', callback)); 13 14// go through all the click events 15for await (const click of subject.iterator) { 16 console.log('a button was clicked'); 17}
It's possible to have an async iterator leak if it never returns a value e.g.:
1const subject1 = new Subject(); 2const subject2 = new Subject(); 3 4async function* neverEnds() { 5 try { 6 for await(const i of subject2.iterator) { 7 yield i; 8 } 9 } finally { 10 console.log("never called") 11 } 12} 13 14async function* run() { 15 for await(const i of merge(subject1.iterator,neverEnds())) { 16 break; 17 } 18} 19 20run() 21subject1.onNext(1)
If you need to be able to cancel async iterators that may never return values, consider Rx or regular Observables for now.
(Thanks to @awto for the example)
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 1/13 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
dependency not pinned by hash detected -- score normalized to 0
Details
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
branch protection not enabled on development/release branches
Details
Reason
32 existing vulnerabilities detected
Details
Score
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