Gathering detailed insights and metrics for through2-filter
Gathering detailed insights and metrics for through2-filter
Gathering detailed insights and metrics for through2-filter
Gathering detailed insights and metrics for through2-filter
A through2 wrapper to create an Array.prototype.filter analog for streams
npm install through2-filter
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
35 Stars
35 Commits
4 Forks
2 Watching
1 Branches
4 Contributors
Updated on 20 Apr 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-2.2%
366,560
Compared to previous day
Last week
2.3%
2,156,798
Compared to previous week
Last month
15.5%
8,547,777
Compared to previous month
Last year
-6.6%
100,242,897
Compared to previous year
1
3
This is a super thin wrapper around through2 that works like Array.prototype.filter
but for streams.
For when through2 is just too verbose :wink:
Note you will NOT be able to alter the content of the chunks. This is intended for filtering only. If you want to modify the stream content, use either through2
or through2-map
.
1var filter = require("through2-filter") 2 3var skip = filter(function (chunk) { 4 // skip buffers longer than 100 5 return chunk.length < 100 6}) 7 8// vs. with through2: 9var skip = through2(function (chunk, encoding, callback) { 10 // skip buffers longer than 100 11 if (chunk.length < 100) this.push(chunk) 12 return callback() 13}) 14 15// Then use your filter: 16source.pipe(skip).pipe(sink) 17 18// Additionally accepts `wantStrings` argument to conver buffers into strings 19var alphanum = new RegExp("^[A-Za-z0-1]+$") 20var scrub = filter({wantStrings: true}, function (str) { 21 return alphanum.exec(str) 22}) 23 24// Works like `Array.prototype.filter` meaning you can specify a function that 25// takes up to two* arguments: fn(element, index) 26var skip10 = filter(function (element, index) { 27 return index > 10 28})
*Differences from Array.prototype.filter
:
array
callback argument. That would require realizing the entire stream, which is generally counter-productive to stream operations.Array.prototype.filter
doesn't modify the source Array, which is somewhat nonsensical when applied to streams.require("through2-filter")([options], fn)
Create a through2-filter
instance that will call fn(chunk)
. If fn(chunk)
returns "true" the chunk will be passed downstream. Otherwise it will be dropped.
require("through2-filter").ctor([options], fn)
Create a through2-filter
Type that can be instantiated via new Type()
or Type()
to create reusable spies.
require("through2-filter").obj([options], fn)
Create a through2-filter
that defaults to objectMode = true
.
require("through2-filter").objCtor([options], fn)
Create a through2-filter
Type that defaults to objectMode = true
.
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 4/24 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
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
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