Comparing version 1.0.0 to 1.1.0
@@ -5,2 +5,3 @@ 'use strict'; | ||
var Readable = require('stream').Readable; | ||
var isArray = require('lodash.isarray'); | ||
@@ -10,4 +11,4 @@ /** | ||
*/ | ||
function InitStream(data, opts) { | ||
Readable.call(this, opts); | ||
function InitStream(data, options) { | ||
Readable.call(this, options); | ||
this.data = data; | ||
@@ -19,4 +20,4 @@ } | ||
InitStream.prototype._read = function() { | ||
this.push(this.data); | ||
this.push(null); | ||
this.push(this.data.shift()); | ||
if (this.data.length === 0) this.push(null); | ||
}; | ||
@@ -27,4 +28,10 @@ | ||
*/ | ||
module.exports = function(data, opts) { | ||
return new InitStream(data, opts); | ||
module.exports = function(data, options) { | ||
data = (isArray(data)) ? data.slice() : [data]; | ||
options = options || {}; | ||
options.objectMode = options.objectMode || true; | ||
return new InitStream(data, options); | ||
}; |
{ | ||
"name": "noria", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A collection of utilities and Classes for working with Node.js streams", | ||
@@ -12,3 +12,5 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha", | ||
"coverage": "istanbul cover _mocha && open ./coverage/lcov-report/index.html", | ||
"coveralls": "istanbul cover _mocha && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage" | ||
}, | ||
@@ -23,8 +25,8 @@ "engines": { | ||
"keywords": [ | ||
"stream", | ||
"utility", | ||
"util", | ||
"classes", | ||
"node", | ||
"nodejs" | ||
"stream", | ||
"utility", | ||
"util", | ||
"classes", | ||
"node", | ||
"nodejs" | ||
], | ||
@@ -39,5 +41,13 @@ "author": "Akim McMath <akim.elijah.mcmath@gmail.com>", | ||
"chai": "^3.4.1", | ||
"coveralls": "^2.11.4", | ||
"event-stream": "^3.3.2", | ||
"istanbul": "^0.4.0", | ||
"mocha": "^2.3.4" | ||
}, | ||
"dependencies": { | ||
"lodash.isarray": "^3.0.4", | ||
"lodash.isboolean": "^3.0.1", | ||
"lodash.isfunction": "^3.0.6", | ||
"lodash.isstring": "^3.0.1" | ||
} | ||
} |
# Noria | ||
[![NPM version](http://img.shields.io/npm/v/noria.svg?style=flat-square)](https://npmjs.org/package/noria) | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://www.npmjs.com/package/noria) | ||
[![Build Status](https://img.shields.io/travis/akim-mcmath/noria.svg?style=flat-square)](https://travis-ci.org/akim-mcmath/noria) | ||
[![Dependency Status](https://img.shields.io/gemnasium/akim-mcmath/noria.svg?style=flat-square)](https://img.shields.io/gemnasium/akim-mcmath/noria) | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.md) | ||
[![Build Status](https://img.shields.io/travis/akim-mcmath/noria/master.svg?style=flat-square)](https://travis-ci.org/akim-mcmath/noria) | ||
[![Coverage Status](https://img.shields.io/coveralls/akim-mcmath/noria/master.svg?style=flat-square&service=github)](https://coveralls.io/github/akim-mcmath/noria?branch=master) | ||
[![Dependency Status](https://img.shields.io/gemnasium/akim-mcmath/noria.svg?style=flat-square)](https://gemnasium.com/akim-mcmath/noria) | ||
A collection of utilities and Classes for working with | ||
A collection of utilities for working with | ||
Node.js [streams](https://nodejs.org/api/stream.html). | ||
@@ -20,5 +21,32 @@ | ||
#### collect([encoding], [objectMode], callback, [options]) | ||
* `encoding` String (optional) - alias for `options.encoding`. | ||
* `objectMode` Boolean (optional) - alias for `options.objectMode`. | ||
* `callback` Function - Called after all data has been collected. Takes one | ||
`data` parameter. | ||
* `options` Object (optional) - Options passed to the stream. | ||
Returns a new [Transform](https://nodejs.org/api/stream.html#stream_class_stream_transform) | ||
stream that buffers all incoming data and then calls `callback(data)`. Or, if | ||
`objectMode` is true, `data` will be an array containing each object that has | ||
passed through. If `encoding` is defined, `data` will be converted to a string | ||
before it is passed to `callback`. | ||
The `options` parameter is identical to that of Node's | ||
[Transform stream constructor](https://nodejs.org/api/stream.html#stream_new_stream_transform_options). | ||
The following will print the contents of a file to the console before writing | ||
it to a new location. | ||
```js | ||
fs.createReadStream('liftoff-file.txt') | ||
.pipe(noria.collect('utf8', function(data) { | ||
console.log(data); | ||
})) | ||
.pipe(fs.createWriteStrem('landing-file.txt')); | ||
``` | ||
#### init(data, [options]) | ||
* `data` Buffer | String | Object - The data to pass to the stream. | ||
* `data` - The data to pass to the stream. | ||
* `options` Object (optional) - Options to pass to the stream. | ||
@@ -28,15 +56,16 @@ | ||
[Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable) | ||
stream initialized with some arbitrary data. The `options` parameter is | ||
identical that of Node's | ||
stream initialized with some arbitrary data. If `data` is an array, each | ||
element in the array will be treated as a chunk of data. options.objectMode is | ||
true by default. The `options` parameter is identical that of Node's | ||
[Readable stream constructor](https://nodejs.org/api/stream.html#stream_new_stream_readable_options). | ||
To pass an Object as the `data` argument, ensure that you set | ||
`objectMode: true`. | ||
```js | ||
const noria = require('noria'); | ||
// Initializes with one chunk of type String. | ||
noria.init('Colorless green ideas sleep furiously.'); | ||
noria.init('Colorless green ideas sleep furiously.') | ||
.pipe(process.stdout) | ||
// Initializes with three chunks of various types. | ||
noria.init([42, 'than', {name: 'adams'}]); | ||
// Prints: 'Colorless green ideas sleep furiously.' | ||
// Initializes with one chunk of type Array. | ||
noria.init([['the', 'universe']]); | ||
``` | ||
@@ -59,3 +88,2 @@ | ||
```js | ||
const noria = require('noria'); | ||
const fs = require('fs'); | ||
@@ -76,2 +104,2 @@ | ||
Copyright © 2015 Akim McMath. Licensed under the MIT License. | ||
Copyright © 2015 Akim McMath. Licensed under the [MIT License](LICENSE.md). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10151
7
115
102
4
5
+ Addedlodash.isarray@^3.0.4
+ Addedlodash.isboolean@^3.0.1
+ Addedlodash.isfunction@^3.0.6
+ Addedlodash.isstring@^3.0.1
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.isboolean@3.0.3(transitive)
+ Addedlodash.isfunction@3.0.9(transitive)
+ Addedlodash.isstring@3.0.1(transitive)