stream-from-value
Create streams from (single) arbitrary Javascript values like strings, functions, arrays, etc.
npm install stream-from-value --save
Usage
String | Buffer
Stream of single var StreamFromValue = require('stream-from-value'); StreamFromValue('some string') .pipe(process.stdout); // output: some string StreamFromValue(new Buffer('some string')) .pipe(process.stdout); // output: some string
Stream of (arbitrary) Javascript Value
var StreamFromValue = require('stream-from-value'); StreamFromValue.obj(['some', 'mixed', 'array', 42]).on('data', function(data){ console.log(data); // output: [ 'some', 'mixed', 'array', 42 ] });
Gulp File
Stream of (single)Gulp files are vinyl files:
npm install vinyl
Test some awsome Gulp plugin:
var StreamFromValue = require('stream-from-value'), File = require('vinyl'); var testfile = new File({ cwd: '/', base: '/hello/', path: '/hello/world.js', contents: new Buffer('console.log("Hello world!");') }); StreamFromValue.obj(testfile) .pipe(someAwsomeGulpPlugin()) .on('data', function(file){ console.log(file.contents.toString()); // dunno what someAwsomeGulpPlugin does :) });
API
Class: StreamFromValue
StreamFromValues are Readable streams.
new StreamFromValue(value, [options])
- value
JavaScript value
Arbitrary Javascript value like numbers, strings, objects, functions, ... - options
Object
passed through new Readable([options])
Note: The new
operator can be omitted.
StreamFromValue#obj(value, [options])
A convenience wrapper for new StreamFromValue(value, {objectMode: true, ...})
.
License
Copyright (c) 2014 Michael Mayer
Licensed under the MIT license.