{"id":27287278,"url":"https://github.com/primetime/node-streammagic","last_synced_at":"2025-04-11T20:19:07.673Z","repository":{"id":57372200,"uuid":"44614191","full_name":"primetime/node-streammagic","owner":"primetime","description":"Node.JS module that converts any variable into a stream","archived":false,"fork":false,"pushed_at":"2017-03-30T13:39:26.000Z","size":34,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T20:19:02.566Z","etag":null,"topics":["nodejs","stream"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/streammagic","language":"CoffeeScript","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/primetime.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-20T15:03:09.000Z","updated_at":"2020-05-19T03:11:06.000Z","dependencies_parsed_at":"2022-09-10T02:11:26.562Z","dependency_job_id":null,"html_url":"https://github.com/primetime/node-streammagic","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primetime%2Fnode-streammagic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primetime%2Fnode-streammagic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primetime%2Fnode-streammagic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primetime%2Fnode-streammagic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/primetime","download_url":"https://codeload.github.com/primetime/node-streammagic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248473112,"owners_count":21109629,"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":["nodejs","stream"],"created_at":"2025-04-11T20:19:05.646Z","updated_at":"2025-04-11T20:19:07.661Z","avatar_url":"https://github.com/primetime.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stream Magic\n[![Build Status](https://semaphoreci.com/api/v1/primetime/node-streammagic/branches/master/shields_badge.svg)](https://semaphoreci.com/primetime/node-streammagic)\n[![Coverage Status](https://coveralls.io/repos/github/primetime/node-streammagic/badge.svg?branch=master)](https://coveralls.io/github/primetime/node-streammagic?branch=master)\n[![npm](https://img.shields.io/npm/v/streammagic.svg)](https://www.npmjs.com/package/streammagic)\n\nA simple module that can convert any variable into a Node.js stream\n\n## What it does\nStream Magic extends the prototypes of all variable types within Node.JS with a `.toStream()` method, which lets you easily transform objects and variables into streams.\n\nA safe mode that doesn't extend prototypes is also available.\n\n#### Installation\nYou can install the [streammagic](https://www.npmjs.com/package/streammagic) package using npm.\n\n```\n$ npm install streammagic\n```\n\n#### Usage\nThe module exports a single function that attaches the `.toStream()` method to the prototypes. To use it, simply require the module and run the function once.\n```Javascript\n// No need to assign this as the function doesn't return anything\nrequire('streammagic')();\n```\n\nOnce this is done, the `.toStream()` method should be available on all variables.\n\n```Javascript\n// Logs 'hello world' to stdout (the console)\nlet myString = 'hello world';\nlet myStream = myString.toStream();\nmyStream.pipe(process.stdout);\n\n// Or shorter\n'hello world'.toStream().pipe(process.stdout)\n```\n\n#### Safe mode\nThe safe mode is available as a method of the module. Simply require it like this:\n\n```Javascript\nconst toStream = require('streammagic').toStream;\n\n// Same as above\nlet myString = 'hello world';\nlet myStream = toStream(myString);\nmyStream.pipe(process.stdout);\n\n// Short version\ntoStream('hello world').pipe(process.stdout);\n```\n\n## Datatypes\n\n#### Primitive datatypes\nAll primitive datatypes (number, boolean, string) will be pushed to the stream in one piece. This cause a slight performance loss for long strings, depending on the actions of the subsequent pipes. _This is something that may be addressed later on_.\n\n```Javascript\n// Boolean\nlet stream = false.toStream() // stream.on('data') will contain: false\n\n// Number\nlet stream = (35).toStream() // stream.on('data') will contain: 35\n\n// String\nlet stream = 'foo'.toStream() // stream.on('data') will contain: foo\n```\n\n\n#### Arrays\nArrays will be piped one item at a time. This can be useful for processing datasets.\n\n```Javascript\nlet myArray = ['hello', 'world'];\nlet myStream = myArray.toStream();\n\nmyStream.on('data', function(data){\n\t// The data event will fire twice. Data will contain 'hello' the first time, 'world' the second.\n});\n```\n\n\n#### Objects\nObjects are piped one property at a time as `{key: value}` objects. Keep this in mind, as assembling the original object on the other end of the pipe will require some manual work.\n\n```Javascript\nlet myObject = {\n\thello: 'world',\n\tfoo: 'bar'\n};\nlet myStream = myObject.toStream();\n\nmyStream.on('data', function(data){\n\t// The data event will fire twice. Data will contain {hello: 'world'} the first time, {foo: 'bar'} the second.\n});\n```\n\n###### Tip\n\nIf you need an object or an array to be piped as one instead of being split up, you can simply wrap it inside another array. Only the outermost array or object will be split.\n\n```Javascript\nlet myArray = ['hello', 'world'];\nlet myStream = [myArray].toStream();\n\nmyStream.on('data', function(data){\n\tconsole.log(data); // ['hello', 'world']\n});\n```\n\n#### Buffers\nNode buffers will be piped as they are, just like primitive datatypes.\n\n## Issues\nIf you find any bugs or problems with this module, please [create an issue](https://github.com/primetime/node-streammagic/issues) so we can look into it. Pull requests with bugfixes are of course welcome.\n\n## License\nThis module is licensed under the [MIT License](https://github.com/primetime/node-streammagic/blob/master/license.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimetime%2Fnode-streammagic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprimetime%2Fnode-streammagic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimetime%2Fnode-streammagic/lists"}