{"id":20665099,"url":"https://github.com/brycebaril/through2-filter","last_synced_at":"2025-10-25T19:14:23.278Z","repository":{"id":60775290,"uuid":"11915926","full_name":"brycebaril/through2-filter","owner":"brycebaril","description":"A through2 wrapper to create an Array.prototype.filter analog for streams","archived":false,"fork":false,"pushed_at":"2024-04-12T18:36:28.000Z","size":15,"stargazers_count":35,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T18:08:00.619Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brycebaril.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2013-08-06T04:45:00.000Z","updated_at":"2024-04-20T18:38:23.943Z","dependencies_parsed_at":"2024-04-20T18:48:53.451Z","dependency_job_id":null,"html_url":"https://github.com/brycebaril/through2-filter","commit_stats":{"total_commits":25,"total_committers":3,"mean_commits":8.333333333333334,"dds":"0.16000000000000003","last_synced_commit":"6b5f6684a420a3029e5258737caef1276d53a1dc"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brycebaril%2Fthrough2-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brycebaril%2Fthrough2-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brycebaril%2Fthrough2-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brycebaril%2Fthrough2-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brycebaril","download_url":"https://codeload.github.com/brycebaril/through2-filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T19:28:10.195Z","updated_at":"2025-10-25T19:14:18.197Z","avatar_url":"https://github.com/brycebaril.png","language":"JavaScript","readme":"through2-filter\n===============\n\n[![NPM](https://nodei.co/npm/through2-filter.png)](https://nodei.co/npm/through2-filter/)\n\nThis is a super thin wrapper around [through2](http://npm.im/through2) that works like `Array.prototype.filter` but for streams.\n\nFor when through2 is just too verbose :wink:\n\nNote 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`.\n\n```js\nvar filter = require(\"through2-filter\")\n\nvar skip = filter(function (chunk) {\n  // skip buffers longer than 100\n  return chunk.length \u003c 100\n})\n\n// vs. with through2:\nvar skip = through2(function (chunk, encoding, callback) {\n  // skip buffers longer than 100\n  if (chunk.length \u003c 100) this.push(chunk)\n  return callback()\n})\n\n// Then use your filter:\nsource.pipe(skip).pipe(sink)\n\n// Additionally accepts `wantStrings` argument to conver buffers into strings\nvar alphanum = new RegExp(\"^[A-Za-z0-1]+$\")\nvar scrub = filter({wantStrings: true}, function (str) {\n  return alphanum.exec(str)\n})\n\n// Works like `Array.prototype.filter` meaning you can specify a function that\n// takes up to two* arguments: fn(element, index)\nvar skip10 = filter(function (element, index) {\n  return index \u003e 10\n})\n```\n\n*Differences from `Array.prototype.filter`:\n  * No third `array` callback argument. That would require realizing the entire stream, which is generally counter-productive to stream operations.\n  * `Array.prototype.filter` doesn't modify the source Array, which is somewhat nonsensical when applied to streams.\n\nAPI\n---\n\n`require(\"through2-filter\")([options], fn)`\n---\n\nCreate 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.\n\n`require(\"through2-filter\").ctor([options], fn)`\n---\n\nCreate a `through2-filter` Type that can be instantiated via `new Type()` or `Type()` to create reusable spies.\n\n`require(\"through2-filter\").obj([options], fn)`\n---\n\nCreate a `through2-filter` that defaults to `objectMode = true`.\n\n`require(\"through2-filter\").objCtor([options], fn)`\n---\n\nCreate a `through2-filter` Type that defaults to `objectMode = true`.\n\nOptions\n-------\n\n  * wantStrings: Automatically call chunk.toString() for the super lazy.\n  * all other through2 options\n\nLICENSE\n=======\n\nMIT\n","funding_links":[],"categories":["模块","Modules"],"sub_categories":["数据流-Stream","Stream"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrycebaril%2Fthrough2-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrycebaril%2Fthrough2-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrycebaril%2Fthrough2-filter/lists"}