streamfilter
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -0,1 +1,21 @@ | ||
# [4.0.0](https://github.com/nfroidure/streamfilter/compare/v3.0.0...v4.0.0) (2024-07-17) | ||
### Code Refactoring | ||
* **core:** use es6 class instead ([de678c8](https://github.com/nfroidure/streamfilter/commit/de678c88cc93db1d8d289a554da14a803dceb739)), closes [#5](https://github.com/nfroidure/streamfilter/issues/5) | ||
### Features | ||
* **core:** allow async funtions as callbacks ([affadc4](https://github.com/nfroidure/streamfilter/commit/affadc44bfbf5e675b793205f3583951a5a5a06a)) | ||
### BREAKING CHANGES | ||
* **core:** No more magic, users will have to choose between the class `StreamFilter` and the | ||
`filterStream` utility function. | ||
# [3.0.0](https://github.com/nfroidure/streamfilter/compare/v2.0.0...v3.0.0) (2018-11-10) | ||
@@ -2,0 +22,0 @@ |
162
package.json
{ | ||
"name": "streamfilter", | ||
"version": "3.0.0", | ||
"description": "Filtering streams.", | ||
"main": "src/index.js", | ||
"metapak": { | ||
@@ -10,28 +6,44 @@ "configs": [ | ||
"readme", | ||
"tsesm", | ||
"jest", | ||
"jsdocs", | ||
"eslint", | ||
"mocha", | ||
"codeclimate", | ||
"travis" | ||
"ghactions" | ||
], | ||
"data": { | ||
"files": "src/*.js tests/*.mocha.js", | ||
"testsFiles": "tests/*.mocha.js" | ||
"files": "'src/**/*.ts'", | ||
"testsFiles": "'src/**/*.tests.ts'", | ||
"distFiles": "'dist/**/*.js'", | ||
"ignore": [ | ||
"dist" | ||
], | ||
"bundleFiles": [ | ||
"dist", | ||
"src" | ||
] | ||
} | ||
}, | ||
"name": "streamfilter", | ||
"version": "4.0.0", | ||
"description": "Filtering streams.", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"build": "rimraf 'dist' && tsc --outDir dist", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md", | ||
"cli": "env NODE_ENV=${NODE_ENV:-cli}", | ||
"cover": "nyc npm test && nyc report --reporter=html --reporter=text", | ||
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls && rm -rf ./coverage", | ||
"cover": "npm run jest -- --coverage", | ||
"cz": "env NODE_ENV=${NODE_ENV:-cli} git cz", | ||
"doc": "echo \"# API\" > API.md; jsdoc2md src/*.js tests/*.mocha.js >> API.md && git add API.md", | ||
"lint": "eslint src/*.js tests/*.mocha.js", | ||
"doc": "echo \"# API\" > API.md; jsdoc2md 'dist/**/*.js' >> API.md && git add API.md", | ||
"format": "npm run prettier", | ||
"jest": "NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest", | ||
"lint": "eslint 'src/**/*.ts'", | ||
"metapak": "metapak", | ||
"mocha": "mocha tests/*.mocha.js", | ||
"precz": "npm t && npm run lint && npm run doc && npm run metapak -- -s", | ||
"prettier": "prettier --write src/*.js tests/*.mocha.js", | ||
"preversion": "npm t && npm run lint && npm run doc && npm run metapak -- -s", | ||
"test": "npm run mocha", | ||
"version": "npm run changelog && git add CHANGELOG.md" | ||
"precz": "npm t && npm run lint && npm run build && npm run doc && npm run metapak -- -s", | ||
"prettier": "prettier --write 'src/**/*.ts'", | ||
"preversion": "npm t && npm run lint && npm run build && npm run doc && npm run metapak -- -s", | ||
"rebuild": "swc ./src -s -d dist -C jsc.target=es2022", | ||
"test": "echo \"WARNING: No tests specified\" && npm run jest", | ||
"type-check": "tsc --pretty --noEmit", | ||
"version": "npm run changelog" | ||
}, | ||
@@ -58,21 +70,26 @@ "repository": { | ||
"devDependencies": { | ||
"commitizen": "^3.0.4", | ||
"conventional-changelog-cli": "^2.0.11", | ||
"coveralls": "^3.0.2", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"eslint": "^5.8.0", | ||
"eslint-plugin-prettier": "^3.0.0", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"metapak": "^2.0.0", | ||
"metapak-nfroidure": "^9.0.2", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.0.1", | ||
"prettier": "^1.14.3", | ||
"streamtest": "^1.2.4" | ||
"@eslint/js": "^9.7.0", | ||
"@swc/cli": "^0.4.0", | ||
"@swc/core": "^1.6.13", | ||
"@swc/helpers": "^0.5.12", | ||
"@swc/jest": "^0.2.36", | ||
"commitizen": "^4.3.0", | ||
"conventional-changelog-cli": "^5.0.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^9.7.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-jest": "^28.6.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"jest": "^29.7.0", | ||
"jsdoc-to-markdown": "^8.0.0", | ||
"metapak": "^6.0.1", | ||
"metapak-nfroidure": "^18.2.0", | ||
"prettier": "^3.3.3", | ||
"rimraf": "^6.0.1", | ||
"streamtest": "^3.0.0", | ||
"typescript": "^5.5.3", | ||
"typescript-eslint": "^7.16.0" | ||
}, | ||
"dependencies": { | ||
"readable-stream": "^3.0.6" | ||
}, | ||
"engines": { | ||
"node": ">=8.12.0" | ||
"node": ">=20.11.1" | ||
}, | ||
@@ -86,3 +103,4 @@ "config": { | ||
"files": [ | ||
"src/**/*.js", | ||
"dist", | ||
"src", | ||
"LICENSE", | ||
@@ -92,23 +110,2 @@ "README.md", | ||
], | ||
"eslintConfig": { | ||
"extends": [ | ||
"eslint:recommended" | ||
], | ||
"parserOptions": { | ||
"sourceType": "script", | ||
"modules": true | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"jest": true, | ||
"mocha": true | ||
}, | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"rules": { | ||
"prettier/prettier": "error" | ||
} | ||
}, | ||
"prettier": { | ||
@@ -118,3 +115,3 @@ "semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"trailingComma": "all", | ||
"proseWrap": "always" | ||
@@ -127,11 +124,50 @@ }, | ||
"conventional-changelog-cli", | ||
"typescript", | ||
"rimraf", | ||
"@swc/cli", | ||
"@swc/core", | ||
"@swc/helpers", | ||
"jest", | ||
"@swc/jest", | ||
"jsdoc-to-markdown", | ||
"eslint", | ||
"prettier", | ||
"eslint-config-prettier", | ||
"prettier", | ||
"mocha", | ||
"coveralls", | ||
"nyc" | ||
"eslint-plugin-prettier", | ||
"typescript-eslint" | ||
] | ||
}, | ||
"overrides": { | ||
"eslint": "^9.7.0" | ||
}, | ||
"type": "module", | ||
"types": "dist/index.d.ts", | ||
"jest": { | ||
"coverageReporters": [ | ||
"lcov" | ||
], | ||
"testPathIgnorePatterns": [ | ||
"/node_modules/" | ||
], | ||
"roots": [ | ||
"<rootDir>/src" | ||
], | ||
"transform": { | ||
"^.+\\.tsx?$": [ | ||
"@swc/jest", | ||
{} | ||
] | ||
}, | ||
"testEnvironment": "node", | ||
"moduleNameMapper": { | ||
"(.+)\\.js": "$1" | ||
}, | ||
"extensionsToTreatAsEsm": [ | ||
".ts" | ||
], | ||
"prettierPath": null | ||
}, | ||
"dependencies": { | ||
"yerror": "^8.0.0" | ||
} | ||
} |
143
README.md
@@ -10,10 +10,3 @@ [//]: # ( ) | ||
[![Build status](https://secure.travis-ci.org/nfroidure/streamfilter.svg)](https://travis-ci.org/nfroidure/streamfilter) | ||
[![Coverage Status](https://coveralls.io/repos/nfroidure/streamfilter/badge.svg?branch=master)](https://coveralls.io/r/nfroidure/streamfilter?branch=master) | ||
[![NPM version](https://badge.fury.io/js/streamfilter.svg)](https://npmjs.org/package/streamfilter) | ||
[![Dependency Status](https://david-dm.org/nfroidure/streamfilter.svg)](https://david-dm.org/nfroidure/streamfilter) | ||
[![devDependency Status](https://david-dm.org/nfroidure/streamfilter/dev-status.svg)](https://david-dm.org/nfroidure/streamfilter#info=devDependencies) | ||
[![Dependency Status](https://dependencyci.com/github/nfroidure/streamfilter/badge)](https://dependencyci.com/github/nfroidure/streamfilter) | ||
[![Package Quality](http://npm.packagequality.com/shield/streamfilter.svg)](http://packagequality.com/#?package=streamfilter) | ||
[![Code Climate](https://codeclimate.com/github/nfroidure/streamfilter.svg)](https://codeclimate.com/github/nfroidure/streamfilter) | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/streamfilter/blob/main/LICENSE) | ||
@@ -24,3 +17,3 @@ | ||
`streamfilter` is a function based filter for streams inspired per gulp-filter | ||
but no limited to Gulp nor to objectMode streams. | ||
but no limited to Gulp nor to objectMode streams. | ||
@@ -30,2 +23,3 @@ ## Installation | ||
First, install `streamfilter` in your project: | ||
```sh | ||
@@ -42,7 +36,8 @@ npm install --save streamfilter | ||
```js | ||
import FilterStream from 'streamfilter'; | ||
import { StreamFilter } from 'streamfilter'; | ||
const filter = new FilterStream((chunk, encoding, cb) => { | ||
const filter = new StreamFilter((chunk, encoding, cb) => { | ||
const mustBeFiltered = chunk.length() > 128; | ||
if(mustBeFiltered) { | ||
if (mustBeFiltered) { | ||
cb(true); | ||
@@ -55,5 +50,3 @@ return; | ||
// Print to stdout a filtered stdin | ||
process.stdin | ||
.pipe(filter) | ||
.pipe(process.stdout); | ||
process.stdin.pipe(filter).pipe(process.stdout); | ||
``` | ||
@@ -64,15 +57,20 @@ | ||
```js | ||
import FilterStream from 'streamfilter'; | ||
import { filterStream } from 'streamfilter'; | ||
const filter = new FilterStream((chunk, encoding, cb) => { | ||
const mustBeFiltered = chunk.length() > 128; | ||
if(mustBeFiltered) { | ||
cb(true); | ||
return; | ||
} | ||
cb(false); | ||
}, { | ||
restore: true | ||
}); | ||
// Here we use the functionnal help | ||
const filter = new filterStream( | ||
// Here we use an async callback instead | ||
async (chunk, encoding) => { | ||
const mustBeFiltered = chunk.length() > 128; | ||
if (mustBeFiltered) { | ||
return true; | ||
} | ||
return false; | ||
}, | ||
{ | ||
restore: true, | ||
}, | ||
); | ||
// Print accepted chunks in stdout | ||
@@ -86,34 +84,34 @@ filter.pipe(process.stdout); | ||
### Filter and restore as a passthrough stream | ||
Let's reach total hype! | ||
```js | ||
import FilterStream from 'streamfilter'; | ||
import { StreamFilter } from 'streamfilter'; | ||
import { Transform } from 'stream'; | ||
// Filter values | ||
const filter = new FilterStream((chunk, encoding, cb) => { | ||
const mustBeFiltered = chunk.length() > 128; | ||
if(mustBeFiltered) { | ||
cb(true); | ||
return; | ||
} | ||
cb(false); | ||
}, { | ||
restore: true, | ||
passthrough: true | ||
}); | ||
const filter = new StreamFilter( | ||
(chunk, encoding, cb) => { | ||
const mustBeFiltered = chunk.length() > 128; | ||
if (mustBeFiltered) { | ||
cb(true); | ||
return; | ||
} | ||
cb(false); | ||
}, | ||
{ | ||
restore: true, | ||
passthrough: true, | ||
}, | ||
); | ||
// Uppercase strings | ||
const mySuperTransformStream = new Transform({ | ||
transform: (chunk, encoding, cb) => cb( | ||
null, | ||
Buffer.from( | ||
chunk.toString(encoding).toUpperCase(), | ||
encoding, | ||
), | ||
), | ||
transform: (chunk, encoding, cb) => | ||
cb(null, Buffer.from(chunk.toString(encoding).toUpperCase(), encoding)), | ||
}); | ||
// Pipe stdin | ||
process.stdin.pipe(filter) | ||
process.stdin | ||
.pipe(filter) | ||
// Edit kept chunks | ||
@@ -124,7 +122,7 @@ .pipe(mySuperTransformStream) | ||
// and output! | ||
.pipe(process.stdout) | ||
.pipe(process.stdout); | ||
``` | ||
Note that in this case, this is *your* responsibility to end the restore stream | ||
by piping in another stream or ending him manually. | ||
Note that in this case, this is _your_ responsibility to end the restore stream | ||
by piping in another stream or ending it manually. | ||
@@ -134,10 +132,27 @@ [//]: # (::contents:end) | ||
# API | ||
## Classes | ||
<dl> | ||
<dt><a href="#StreamFilter">StreamFilter</a></dt> | ||
<dd><p>Filter piped in streams according to the given <code>filterCallback</code>.</p> | ||
</dd> | ||
</dl> | ||
## Functions | ||
<dl> | ||
<dt><a href="#filterStream">filterStream(filterCallback, options)</a> ⇒</dt> | ||
<dd><p>Utility function if you prefer a functional way of using this lib</p> | ||
</dd> | ||
</dl> | ||
<a name="StreamFilter"></a> | ||
## StreamFilter(filterCallback, options) ⇒ <code>Stream</code> | ||
Filter piped in streams according to the given `filterCallback` that takes the | ||
following arguments: `chunk` the actual chunk, `encoding` the chunk encoding, | ||
filterResultCallback` the function to call as the result of the filtering | ||
process with `true` in argument to filter her or `false` otherwise. | ||
## StreamFilter | ||
Filter piped in streams according to the given `filterCallback`. | ||
**Kind**: global class | ||
<a name="new_StreamFilter_new"></a> | ||
### new StreamFilter(filterCallback, options) | ||
Options are passed in as is in the various stream instances spawned by this | ||
@@ -147,4 +162,3 @@ module. So, to use the objectMode, simply pass in the `options.objectMode` | ||
**Kind**: global function | ||
**Returns**: <code>Stream</code> - The filtering stream | ||
**Returns**: [<code>StreamFilter</code>](#StreamFilter) - The filtering stream | ||
@@ -155,6 +169,19 @@ | Param | Type | Description | | ||
| options | <code>Object</code> | Filtering options | | ||
| options.passthrough | <code>boolean</code> | Set to `true`, this option change the restore stream nature from a readable stream to a passthrough one, allowing you to reuse the filtered chunks in an existing pipeline. | | ||
| options.passthrough | <code>boolean</code> | Set to `true`, this option changes the restore stream nature from a readable stream to a passthrough one, allowing you to reuse the filtered chunks in an existing pipeline. | | ||
| options.restore | <code>boolean</code> | Set to `true`, this option create a readable stream allowing you to use the filtered chunks elsewhere. The restore stream is exposed in the `FilterStream` instance as a `restore` named property. | | ||
<a name="filterStream"></a> | ||
## filterStream(filterCallback, options) ⇒ | ||
Utility function if you prefer a functional way of using this lib | ||
**Kind**: global function | ||
**Returns**: Stream | ||
| Param | | ||
| --- | | ||
| filterCallback | | ||
| options | | ||
# Authors | ||
@@ -164,2 +191,2 @@ - [Nicolas Froidure](http://insertafter.com/en/index.html) | ||
# License | ||
[MIT](https://github.com/nfroidure/streamfilter/blob/master/LICENSE) | ||
[MIT](https://github.com/nfroidure/streamfilter/blob/main/LICENSE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
83437
12
1372
181
Yes
21
1
+ Addedyerror@^8.0.0
+ Addedyerror@8.0.0(transitive)
- Removedreadable-stream@^3.0.6
- Removedinherits@2.0.4(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)