![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
always-stream
Advanced tools
Create stream from any value - function, array, string, buffer, promise, number, object and etc. Always returns a function that returns Transform Stream, using [through2][].
Create stream from any value - function, array, string, buffer, promise, number, object and etc. Always returns a function that returns Transform Stream, using through2.
Note: This is just a thin wrapper around callback2stream and value2stream.
npm i always-stream --save
For more use-cases see the tests
const alwaysStream = require('always-stream')
Create a stream from any value.
Params
val
{Mixed}: Any type of value.[opts]
{Object|Function=}: Directly passed to value2stream, callback2stream and through2.[Promize]
{Function}: Promise constructor to be used when no support for native Promise. Can be 2nd argument.returns
{Function}: That when executed, returns TransformStream
, using through2Example
var fs = require('fs')
var toStream = require('always-stream')
var numberStream = toStream(123)
numberStream().on('data', function (val) {
console.log(val) // => 123
})
var stringStream = toStream('str foo')
stringStream().on('data', function (val) {
console.log(val) // => 'str foo'
})
var readFile = toStream(fs.readFile)
readFile('package.json', 'utf8')
.on('data', function (val) {
var json = JSON.parse(val)
console.log(json.name) // => 'always-stream'
})
.once('error', console.error)
.once('end', console.error)
// or sync functions
var statFile = toStream(fs.statSync)
statFile('package.json')
.on('data', function (stats) {
console.log(stats) // => stat object
})
.once('error', console.error)
.once('end', console.error)
// also works for native functions
// like JSON.parse and JSON.stringify
// by respect optional arguments
var stringifyStream = toStream(JSON.stringify)
stringifyStream({ foo: 'bar' }, null, 2)
.on('data', function (val) {
console.log(val) // => '{\n "foo": "bar"\n}'
})
.once('error', console.error)
co@4
(passing 100% tests) homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.
FAQs
Create stream from any value - function, array, string, buffer, promise, number, object and etc. Always returns a function that returns Transform Stream, using [through2][].
The npm package always-stream receives a total of 0 weekly downloads. As such, always-stream popularity was classified as not popular.
We found that always-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.