{"id":20665102,"url":"https://github.com/brycebaril/through2-map","last_synced_at":"2025-04-06T01:10:17.343Z","repository":{"id":9907759,"uuid":"11916254","full_name":"brycebaril/through2-map","owner":"brycebaril","description":"A through2 to create an Array.prototype.map analog for streams.","archived":false,"fork":false,"pushed_at":"2024-04-13T01:06:55.000Z","size":19,"stargazers_count":70,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T18:08:00.590Z","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-06T05:11:29.000Z","updated_at":"2024-04-20T18:38:23.875Z","dependencies_parsed_at":"2024-04-20T18:48:52.464Z","dependency_job_id":null,"html_url":"https://github.com/brycebaril/through2-map","commit_stats":{"total_commits":25,"total_committers":3,"mean_commits":8.333333333333334,"dds":0.07999999999999996,"last_synced_commit":"8a482d218bdf2de40bf867a1f28ffa9fa0a3b315"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brycebaril%2Fthrough2-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brycebaril%2Fthrough2-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brycebaril%2Fthrough2-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brycebaril%2Fthrough2-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brycebaril","download_url":"https://codeload.github.com/brycebaril/through2-map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419861,"owners_count":20936012,"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.322Z","updated_at":"2025-04-06T01:10:17.317Z","avatar_url":"https://github.com/brycebaril.png","language":"JavaScript","readme":"through2-map\n============\n\n[![NPM](https://nodei.co/npm/through2-map.png)](https://nodei.co/npm/through2-map/)\n\nThis is a super thin wrapper around [through2](http://npm.im/through2) that works like `Array.prototype.map` but for streams.\n\nFor when through2 is just too verbose :wink:\n\nNote you will **NOT** be able to skip chunks. This is intended for modification only. If you want filter the stream content, use either `through2` or `through2-filter`. This transform also does not have a `flush` function.\n\n**IMPORTANT:** If you return `null` from your function, the stream will end there.\n\n```js\n\nvar map = require(\"through2-map\")\n\nvar truncate = map(function (chunk) {\n  return chunk.slice(0, 10)\n})\n\n// vs. with through2:\nvar truncate = through2(function (chunk, encoding, callback) {\n  this.push(chunk.slice(0, 10))\n  return callback()\n})\n\n// Then use your map:\nsource.pipe(truncate).pipe(sink)\n\n// Additionally accepts `wantStrings` argument to convert buffers into strings\nvar stripTags = map({wantStrings: true}, function (str) {\n  // OMG don't actually use this\n  return str.replace(/\u003c.*?\u003e/g, \"\")\n})\n\n// Works like `Array.prototype.map` meaning you can specify a function that\n// takes up to two* arguments: fn(chunk, index)\nvar spaceout = map({wantStrings: true}, function (chunk, index) {\n  return (index % 2 == 0) ? chunk + \"\\n\\n\" : chunk\n})\n\n// vs. with through2:\nvar spaceout = through2(function (chunk, encoding, callback) {\n  if (this.index == undefined) this.index = 0\n  var buf = (this.index++ % 2 == 0) ? Buffer.concat(chunk, new Buffer(\"\\n\\n\")) : chunk\n  this.push(buf)\n  return callback()\n})\n\n```\n\n*Differences from `Array.prototype.map`:\n  * Cannot insert `null` elements into the stream without aborting.\n  * No third `array` callback argument. That would require realizing the entire stream, which is generally counter-productive to stream operations.\n  * `Array.prototype.map` doesn't modify the source Array, which is somewhat nonsensical when applied to streams.\n\nAPI\n---\n\n```\nrequire(\"through2-map\")([options,] fn)\n```\n\nCreate a `stream.Transform` instance that will call `fn(chunk, index)` on each stream segment.\n\n- - -\n\n```\nvar Tx = require(\"through2-map\").ctor([options,] fn)\n```\n\nCreate a reusable `stream.Transform` TYPE that can be called via `new Tx` or `Tx()` to create an instance.\n\n- - -\n\n```\nrequire(\"through2-map\").obj([options,] fn)\n```\n\nCreate a `through2-map` instance that defaults to `objectMode: true`.\n\n- - -\n\n```\nrequire(\"through2-map\").objCtor([options,] fn)\n```\n\nJust like ctor, but with `objectMode: true` defaulting to 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-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrycebaril%2Fthrough2-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrycebaril%2Fthrough2-map/lists"}