{
  "name": "@sounisi5011/stream-transform-from",
  "version": "1.1.1",
  "description": "Create a transform stream from an async iterator",
  "keywords": [
    "async",
    "async-generator",
    "async-generator-function",
    "async-generator-functions",
    "async-generators",
    "async-iterable",
    "async-iterables",
    "async-iterator",
    "async-iterators",
    "asyncgenerator",
    "asyncgeneratorfunction",
    "asyncgeneratorfunctions",
    "asyncgenerators",
    "asynciterable",
    "asynciterables",
    "asynciterator",
    "asynciterators",
    "for-await",
    "for-await-of",
    "from",
    "generator",
    "generator-function",
    "generator-functions",
    "generatorfunction",
    "generatorfunctions",
    "generators",
    "iterable",
    "iterables",
    "iterator",
    "iterators",
    "stream",
    "streams",
    "transform",
    "util",
    "utility"
  ],
  "homepage": "https://github.com/sounisi5011/npm-packages/tree/main/packages/stream-transform-from#readme",
  "bugs": {
    "url": "https://github.com/sounisi5011/npm-packages/issues"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/sounisi5011/npm-packages.git",
    "directory": "packages/stream-transform-from"
  },
  "license": "MIT",
  "author": "sounisi5011",
  "type": "commonjs",
  "exports": {
    ".": "./dist/index.js",
    "./package.json": "./package.json"
  },
  "main": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "directories": {
    "lib": "./src/",
    "example": "./examples/",
    "test": "./tests/"
  },
  "files": [
    "dist/",
    "src/",
    "/CHANGELOG.md",
    "examples/index.js"
  ],
  "devDependencies": {
    "@sounisi5011/run-if-supported": "^1.0.0",
    "@types/jest": "27.5.1",
    "@types/node": "12.20.52",
    "jest": "28.1.0",
    "ts-jest": "28.0.3",
    "tsd": "0.20.0",
    "typescript": "4.7.2",
    "ultra-runner": "3.10.5"
  },
  "engines": {
    "node": "^12.17.x || 14.x || 15.x || 16.x || 17.x || >=18.x"
  },
  "runkitExampleFilename": "./examples/index.js",
  "scripts": {
    "build": "tsc",
    "build-with-cache": "ultra build",
    "lint:tsc": "run-p lint:tsc:*",
    "lint:tsc:src": "tsc --noEmit",
    "lint:tsc:test": "tsc -p ./tests/ --noEmit",
    "lint:tsc:test-d": "tsc -p ./test-d/ --noEmit",
    "test": "run-if-supported --verbose run-p test:*",
    "test:examples": "run-s build-with-cache test:examples:*",
    "test:examples:index": "node ./examples/index.js",
    "test:jest": "jest",
    "test:tsd": "run-s build-with-cache test:tsd:*",
    "test:tsd:exec": "tsd"
  },
  "readme": "# @sounisi5011/stream-transform-from\n\n[![Go to the latest release page on npm](https://img.shields.io/npm/v/@sounisi5011/stream-transform-from.svg)](https://www.npmjs.com/package/@sounisi5011/stream-transform-from)\n![Supported Node.js version: ^12.17.x || 14.x || 15.x || 16.x || 17.x || >=18.x](https://img.shields.io/static/v1?label=node&message=%5E12.17.x%20%7C%7C%2014.x%20%7C%7C%2015.x%20%7C%7C%2016.x%20%7C%7C%2017.x%20%7C%7C%20%3E%3D18.x&color=brightgreen)\n[![Tested with Jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![Minified Bundle Size Details](https://img.shields.io/bundlephobia/min/@sounisi5011/stream-transform-from/1.1.1)](https://bundlephobia.com/result?p=%40sounisi5011%2Fstream-transform-from%401.1.1)\n[![Install Size Details](https://packagephobia.com/badge?p=%40sounisi5011%2Fstream-transform-from%401.1.1)](https://packagephobia.com/result?p=%40sounisi5011%2Fstream-transform-from%401.1.1)\n[![Dependencies Status](https://status.david-dm.org/gh/sounisi5011/npm-packages.svg?path=packages%2Fstream-transform-from)](https://david-dm.org/sounisi5011/npm-packages?path=packages%2Fstream-transform-from)\n[![Build Status](https://github.com/sounisi5011/npm-packages/actions/workflows/ci.yaml/badge.svg)](https://github.com/sounisi5011/npm-packages/actions/workflows/ci.yaml)\n[![Maintainability Status](https://api.codeclimate.com/v1/badges/26495b68302f7ff963c3/maintainability)](https://codeclimate.com/github/sounisi5011/npm-packages/maintainability)\n\n[`stream.Transform` class]: https://nodejs.org/docs/latest/api/stream.html#stream_class_stream_transform\n[`Buffer` object]: https://nodejs.org/api/buffer.html\n\nCreate a [transform stream][`stream.Transform` class] from an async iterator.\nThis is [the last piece](https://github.com/nodejs/node/issues/27140#issuecomment-533266638) needed to convert between streams and async iterators/generators.\n\n## Features\n\n* No dependencies\n\n    This package uses only the Node.js built-in [`stream.Transform` class].\n\n* Strict type definition\n\n    The exact type definitions for arguments and return values will be generated based on the `objectMode` option.\n\n* Encoding arguments can be used\n\n    You can use `encoding`, which is passed as the second argument of the [`transform._transform()` method](https://nodejs.org/docs/latest/api/stream.html#stream_transform_transform_chunk_encoding_callback).\n    This allows you to safely convert a string to [`Buffer` object].\n\n## Installation\n\n```sh\nnpm install @sounisi5011/stream-transform-from\n```\n\n```sh\nyarn add @sounisi5011/stream-transform-from\n```\n\n```sh\npnpm add @sounisi5011/stream-transform-from\n```\n\n## Usage\n\n### Convert [`Buffer` objects][`Buffer` object]\n\n```js\nconst fs = require('fs');\nconst stream = require('stream');\n\nconst { transformFrom } = require('@sounisi5011/stream-transform-from');\n\nstream.pipeline(\n  fs.createReadStream('input.txt', 'utf8'),\n  transformFrom(async function*(source) {\n    for await (const { chunk } of source) {\n      yield chunk.toString('utf8').toUpperCase();\n    }\n  }),\n  fs.createWriteStream('output.txt'),\n  error => {\n    if (error) {\n      console.error(error);\n    } else {\n      console.log('done!');\n    }\n  }\n);\n```\n\n### Convert any type value\n\n```js\nconst stream = require('stream');\n\nconst { transformFrom } = require('@sounisi5011/stream-transform-from');\n\nstream.pipeline(\n  stream.Readable.from([1, 2, 3]),\n  transformFrom(\n    async function*(source) {\n      for await (const { chunk } of source) {\n        yield chunk + 2;\n      }\n    },\n    { objectMode: true }\n  ),\n  // ...\n  error => {\n    if (error) {\n      console.error(error);\n    } else {\n      console.log('done!');\n    }\n  }\n);\n```\n\n### Convert string to [`Buffer`][`Buffer` object] using encoding\n\n```js\nconst stream = require('stream');\n\nconst { transformFrom } = require('@sounisi5011/stream-transform-from');\n\nstream.pipeline(\n  // ...\n  transformFrom(\n    async function*(source) {\n      for await (const { chunk, encoding } of source) {\n        if (typeof chunk === 'string') {\n          yield Buffer.from(chunk, encoding);\n        }\n      }\n    },\n    { writableObjectMode: true }\n  ),\n  // ...\n  error => {\n    if (error) {\n      console.error(error);\n    } else {\n      console.log('done!');\n    }\n  }\n);\n```\n\n## API\n\n```js\nconst { transformFrom } = require('@sounisi5011/stream-transform-from');\n\n// The return value is a Transform stream.\nconst transformStream = transformFrom(\n  async function*(source) {\n    // `source` is `AsyncIterableIterator<{ chunk: Buffer, encoding: BufferEncoding }>`\n    //          or `AsyncIterableIterator<{ chunk: unknown, encoding: BufferEncoding }>` type\n\n    // The value returned by `yield` keyword will be passed as the first argument of `transform.push()` method.\n  },\n\n  // The second argument is an options for the Transform stream.\n  // The options are passed to the constructor function of the Transform class.\n  // However, the following fields are not allowed:\n  // + `construct`\n  // + `read`\n  // + `write`\n  // + `writev`\n  // + `final`\n  // + `destroy`\n  // + `transform`\n  // + `flush`\n  // The fields listed above will be ignored if specified.\n  {}\n);\n```\n\n## Related\n\n* [generator-transform-stream](https://github.com/bealearts/generator-transform-stream)\n"
}