{"id":19852437,"url":"https://github.com/mutsuntsai/gulp-through2","last_synced_at":"2026-02-09T05:02:42.375Z","repository":{"id":63642621,"uuid":"568728896","full_name":"MuTsunTsai/gulp-through2","owner":"MuTsunTsai","description":"A simple wrapper for creating gulp plugin instantly.","archived":false,"fork":false,"pushed_at":"2024-06-25T05:31:43.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T02:06:58.972Z","etag":null,"topics":["gulp","gulp-plugin","gulp4"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/gulp-through2","language":"TypeScript","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/MuTsunTsai.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"publiccode":null,"codemeta":null}},"created_at":"2022-11-21T09:36:57.000Z","updated_at":"2024-06-25T05:31:46.000Z","dependencies_parsed_at":"2024-11-12T14:02:11.109Z","dependency_job_id":"f814158f-4be5-4604-ba09-8aa44a56f274","html_url":"https://github.com/MuTsunTsai/gulp-through2","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"5179e97122dcd9e6b08c69a58bc2302ad4bd8791"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/MuTsunTsai/gulp-through2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuTsunTsai%2Fgulp-through2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuTsunTsai%2Fgulp-through2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuTsunTsai%2Fgulp-through2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuTsunTsai%2Fgulp-through2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MuTsunTsai","download_url":"https://codeload.github.com/MuTsunTsai/gulp-through2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuTsunTsai%2Fgulp-through2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29257512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T04:11:57.159Z","status":"ssl_error","status_checked_at":"2026-02-09T04:11:56.117Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["gulp","gulp-plugin","gulp4"],"created_at":"2024-11-12T14:01:57.508Z","updated_at":"2026-02-09T05:02:42.298Z","avatar_url":"https://github.com/MuTsunTsai.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# gulp-through2\n\n\u003e A simple wrapper for creating gulp plugin instantly.\n\n\n## Introduction\n\nLet's face it: lots of gulp plugins are really just simple wrappers around\n[through2](https://www.npmjs.com/package/through2)\n(which in turns is just a simple wrapper around `stream.Transform`)\nand some other NPM packages that do some simple content transformations.\n\nWhy the trouble? Why not just skip the middleman and create a plugin directly?\nIntroducing `gulp-through2`, a gulp meta-plugin that does exactly that,\nusing simple and flexible APIs. It works especially great when:\n\n1. You want to perform a task in your gulp flow that doesn't have a corresponding gulp plugin yet,\n   or the plugin is no longer actively maintained. (We all have been there, right?)\n2. You want to create and perhaps publish a gulp plugin that is also a simple wrapper,\n   and you don't want to repeat a lot of routine codes.\n\n## Install\n\n```\nnpm install --save-dev gulp-through2\n```\n\n## Quick examples\n\nHere are a few quick example that gives you an idea how it works:\n\n```js\nconst gulp = require('gulp');\nconst through2 = require('gulp-through2');\n\n// This is like a simplified version of gulp-replace\nconst myReplace = (search, replacement) =\u003e through2(\n\t// In the shorthand syntax, string content of the file\n\t// is transformed with the given transformation function.\n\tcontent =\u003e content.replace(search, replacement)\n);\n\n// This is like a simplified version of gulp-concat\n// This time we use the option syntax instead\nconst myConcat = filename =\u003e through2({\n\t// flush option takes an array of transformed files\n\t// (in this case there's no transformation function,\n\t// so its essentially the array of original files)\n\tflush(files) {\n\t\t// Easily read and write using gulp-through2 utility methods\n\t\tconst join = files.map(f =\u003e through2.read(f)).join('\\n');\n\t\tthrough2.write(files[0], join);\n\n\t\t// Create a new array containing a single file that passes on\n\t\tfiles[0].basename = filename;\n\t\treturn [files[0]];\n\t}\n});\n\n// Now we can use them:\ngulp.task('myTask', () =\u003e\n\tgulp.src('src/*.js')\n\t\t.pipe(myReplace(/abc/g, \"def\"))\n\t\t.pipe(myConcat(\"joined.js\"))\n\t\t.pipe(gulp.dest('...'))\n);\n\n```\n\n\n## Basic options\n\nMost gulp plugins follow a similar pattern:\nfirst they check a certain preconditions\n(especially the file extension and whether the file content is a stream),\nand then replace the file content by a certain transformation.\nSome plugins do a bit more than that:\nthey might add or remove files that pass through to the next gulp plugin.\nThis leads to the three most basic options of `gulp-through2`:\n\n### `filter`\n\nThis option determines if a file should be transformed,\nor should be passed through directly.\nIts value can be a string, a regular expression, a function,\nor an array of the above.\nEach have different ways of filtering:\n\n| Type       | Description                                                                                  |\n| ---------- | -------------------------------------------------------------------------------------------- |\n| `String`   | The extension of the file should match exactly to the string (e.g. \".html\"). Case-sensitive. |\n| `RegExp`   | The full filename of the file is tested against the regular expression.                      |\n| `Function` | The `File` object is passed to the function as the single parameter, and it should return boolean value indicating whether to transform the file. |\n| `Array`    | The file will be transformed if any of the conditions in the array is met.                   |\n\nIf this options is not provided, all files will be transformed.\n\n### `transform`\n\nThis is a function that takes three parameters:\n\n| Parameter                  | Description                     |\n| -------------------------- | ------------------------------- |\n| `content: string`          | The string content of the file. |\n| `file: File`               | The file object in question.    |\n| `encoding: BufferEncoding` | The encoding of the file.       |\n\nIt should return one of the following (with different effects):\n\n| Type     | Description                                            |\n| -------- | ------------------------------------------------------ |\n| `String` | The returned string will be used as the new content of the file.\u003cbr\u003eNote: the original file object is kept, so other manipulations on it will be applied. |\n| `File`   | The new file object will be passed on instead.         |\n| `null`   | The file is discarded and will not be passed on.       |\n| `void`   | The original file object (possibly mutated) passes on. |\n\nIf this option is not provided, no transformation will be applied to the files.\n\nNote that `gulp-through2` provides a shorthand syntax that uses only the two said options:\n\n```js\nthrough2(transform, filter?)\n```\n\n### `flush`\n\nThis is a function that takes the transformed file array as parameter,\nand it should return a new array indicating the files to be passed on.\nYou can then add, remove or change the order of the files as you like.\n\nIn case you still need to manipulate the file contents inside `flush()` function, `gulp-through2` provides two utility methods for reading and writing file contents:\n\n```ts\nfunction read(file: File, encoding?: BufferEncoding): string;\nfunction write(file: File, content: string | String, encoding?: BufferEncoding): void;\n```\n\nUseful tip: you can use the `clone()` method of the `File` object to create a new file with the same base path as the rest of the files. Also check out the readme of [vinyl](https://github.com/gulpjs/vinyl) to learn more about how the use the `File` objects.\n\n\n## Advanced options\n\nFor complete details of each options,\nrefer to [index.d.ts](src/index.d.ts).\nHere is a brief account of each option:\n\n| Option             | Description                                             |\n| ------------------ | ------------------------------------------------------- |\n| `flushEmptyList`   | `boolean` value indicating whether to run `flush()` when the transformed file list is empty. Default value is `false`. |\n| `streamTransform`  | A function for transforming stream contents of a file. If not provided, `gulp-through2` will throw an error when stream contents as passed in, which is the typical behavior in many gulp plugins. |\n| `name`             | The name of your plugin. Used only for printing errors. |\n| `transformOptions` |  Advanced options for creating `stream.Transform`.      |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutsuntsai%2Fgulp-through2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmutsuntsai%2Fgulp-through2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmutsuntsai%2Fgulp-through2/lists"}