stream-transform
Advanced tools
Comparing version 1.0.4 to 1.0.5
# Changelog | ||
## Version 1.0.5 | ||
* package: move to csv.js.org | ||
* package: upgrade dependencies including babel 7 | ||
* example: new sequential mode sample | ||
* examples: new state examples | ||
* examples: new api sync example | ||
* examples: new mixed output stream example | ||
* handler: bind execution context with current instance | ||
## Version 1.0.4 | ||
@@ -5,0 +15,0 @@ |
@@ -1,10 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
// Generated by CoffeeScript 2.0.3 | ||
// Generated by CoffeeScript 2.3.2 | ||
// # Stream Transformer | ||
// Pass all elements of an array or a stream to transform, filter and add. Features include: | ||
// * Extends the Node.js "stream.Transform" API. | ||
@@ -15,26 +13,20 @@ // * Both synchrounous and asynchronous support based and user callback | ||
// * Sequential and concurrent execution using the "parallel" options. | ||
// Please look at the [README], the [samples] and the [tests] for additional | ||
// information. | ||
var Transformer, stream, util; | ||
stream = require('stream'); | ||
util = require('util'); | ||
// ## Usage | ||
util = require('util'); // ## Usage | ||
// Callback approach, for ease of use: | ||
// `transform([data], handler, [options])` | ||
// Stream API, for maximum of power: | ||
// `transform([data], [options], handler, [options], [callback])` | ||
// `transform([data], [options], handler, [options], [callback])` | ||
module.exports = function () { | ||
var argument, callback, data, error, handler, i, j, k, len, options, result, transform, type, v; | ||
options = {}; | ||
for (i = j = 0, len = arguments.length; j < len; i = ++j) { | ||
argument = arguments[i]; | ||
type = typeof argument === 'undefined' ? 'undefined' : _typeof(argument); | ||
type = _typeof(argument); | ||
if (argument === null) { | ||
@@ -45,2 +37,3 @@ type = 'null'; | ||
} | ||
if (i === 0) { | ||
@@ -52,4 +45,6 @@ if (type === 'function') { | ||
} | ||
continue; | ||
} | ||
if (type === 'object') { | ||
@@ -70,17 +65,24 @@ for (k in argument) { | ||
} | ||
transform = new Transformer(options, handler); | ||
error = false; | ||
if (data) { | ||
process.nextTick(function () { | ||
var len1, m, row; | ||
for (m = 0, len1 = data.length; m < len1; m++) { | ||
row = data[m]; | ||
if (error) { | ||
break; | ||
} | ||
transform.write(row); | ||
} | ||
return transform.end(); | ||
}); | ||
} | ||
if (callback || options.consume) { | ||
@@ -91,2 +93,3 @@ result = []; | ||
results = []; | ||
while (record = transform.read()) { | ||
@@ -99,2 +102,3 @@ if (callback) { | ||
} | ||
return results; | ||
@@ -104,2 +108,3 @@ }); | ||
error = true; | ||
if (callback) { | ||
@@ -115,12 +120,11 @@ return callback(err); | ||
} | ||
return transform; | ||
}; | ||
}; // ## Transformer | ||
// Options are documented [here](http://csv.js.org/transform/options/). | ||
// ## Transformer | ||
// Options are documented [here](http://csv.adaltas.com/transform/). | ||
Transformer = function Transformer() { | ||
var options1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var transform1 = arguments[1]; | ||
var transform1 = arguments.length > 1 ? arguments[1] : undefined; | ||
var base; | ||
@@ -130,5 +134,7 @@ this.options = options1; | ||
this.options.objectMode = true; | ||
if ((base = this.options).parallel == null) { | ||
base.parallel = 100; | ||
} | ||
stream.Transform.call(this, this.options); | ||
@@ -142,3 +148,2 @@ this.running = 0; | ||
util.inherits(Transformer, stream.Transform); | ||
module.exports.Transformer = Transformer; | ||
@@ -152,2 +157,3 @@ | ||
this.running++; | ||
if (this.running < this.options.parallel) { | ||
@@ -157,14 +163,17 @@ cb(); | ||
} | ||
try { | ||
l = this.transform.length; | ||
if (this.options.params != null) { | ||
l--; | ||
} | ||
if (l === 1) { | ||
// sync | ||
this.__done(null, [this.transform.call(null, chunk, this.options.params)], cb); | ||
this.__done(null, [this.transform.call(this, chunk, this.options.params)], cb); | ||
} else if (l === 2) { | ||
// async | ||
callback = function callback(err) { | ||
for (var _len = arguments.length, chunks = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
for (var _len = arguments.length, chunks = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
chunks[_key - 1] = arguments[_key]; | ||
@@ -175,6 +184,8 @@ } | ||
}; | ||
this.transform.call(null, chunk, callback, this.options.params); | ||
this.transform.call(this, chunk, callback, this.options.params); | ||
} else { | ||
throw Error("Invalid handler arguments"); | ||
} | ||
return false; | ||
@@ -193,2 +204,3 @@ } catch (error1) { | ||
}; | ||
return this._ending(); | ||
@@ -200,11 +212,16 @@ }; | ||
this.running--; | ||
if (err) { | ||
return this.emit('error', err); | ||
} | ||
this.finished++; | ||
for (j = 0, len = chunks.length; j < len; j++) { | ||
chunk = chunks[j]; | ||
if (typeof chunk === 'number') { | ||
chunk = '' + chunk; | ||
chunk = "".concat(chunk); | ||
} | ||
if (chunk != null && chunk !== '') { | ||
@@ -216,12 +233,12 @@ // We dont push empty string | ||
} | ||
if (cb) { | ||
cb(); | ||
} | ||
if (this._ending) { | ||
return this._ending(); | ||
} | ||
}; | ||
// [readme]: https://github.com/wdavidw/node-stream-transform | ||
}; // [readme]: https://github.com/wdavidw/node-stream-transform | ||
// [samples]: https://github.com/wdavidw/node-stream-transform/tree/master/samples | ||
// [tests]: https://github.com/wdavidw/node-stream-transform/tree/master/test |
@@ -1,26 +0,23 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
// Generated by CoffeeScript 2.0.3 | ||
// Generated by CoffeeScript 2.3.2 | ||
// # Stream Transformer Sync | ||
// Provides a synchronous alternative to the CSV transformer. | ||
// ## Usage | ||
// `const data = transform(data, [options])` | ||
// `const records = transform(data, [options])` | ||
// ## Source Code | ||
var transform; | ||
transform = require('.'); | ||
module.exports = function () { | ||
var argument, callback, chunks, data, expected_handler_length, handler, i, j, k, l, len, len1, options, record, transformer, type, v; | ||
// Import arguments normalization | ||
var argument, callback, chunks, data, expected_handler_length, handler, i, j, k, l, len, len1, options, record, transformer, type, v; // Import arguments normalization | ||
options = {}; | ||
for (i = j = 0, len = arguments.length; j < len; i = ++j) { | ||
argument = arguments[i]; | ||
type = typeof argument === 'undefined' ? 'undefined' : _typeof(argument); | ||
type = _typeof(argument); | ||
if (argument === null) { | ||
@@ -31,2 +28,3 @@ type = 'null'; | ||
} | ||
if (i === 0) { | ||
@@ -38,4 +36,6 @@ if (type === 'function') { | ||
} | ||
continue; | ||
} | ||
if (type === 'object') { | ||
@@ -55,22 +55,30 @@ for (k in argument) { | ||
} | ||
} | ||
// Validate arguments | ||
} // Validate arguments | ||
expected_handler_length = 1; | ||
if (options.params) { | ||
expected_handler_length++; | ||
} | ||
if (handler.length > expected_handler_length) { | ||
throw Error('Invalid Handler: only synchonous handlers are supported'); | ||
} | ||
// Start transformation | ||
} // Start transformation | ||
chunks = []; | ||
transformer = new transform.Transformer(options, handler); | ||
transformer.push = function (chunk) { | ||
return chunks.push(chunk); | ||
}; | ||
for (l = 0, len1 = data.length; l < len1; l++) { | ||
record = data[l]; | ||
transformer._transform(record, null, function () {}); | ||
} | ||
return chunks; | ||
}; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 2.0.3 | ||
// Generated by CoffeeScript 2.3.2 | ||
// # Stream Transformer | ||
@@ -109,3 +109,3 @@ | ||
// Options are documented [here](http://csv.adaltas.com/transform/). | ||
// Options are documented [here](http://csv.js.org/transform/options/). | ||
Transformer = function(options1 = {}, transform1) { | ||
@@ -144,3 +144,3 @@ var base; | ||
if (l === 1) { // sync | ||
this.__done(null, [this.transform.call(null, chunk, this.options.params)], cb); | ||
this.__done(null, [this.transform.call(this, chunk, this.options.params)], cb); | ||
} else if (l === 2) { // async | ||
@@ -150,3 +150,3 @@ callback = (err, ...chunks) => { | ||
}; | ||
this.transform.call(null, chunk, callback, this.options.params); | ||
this.transform.call(this, chunk, callback, this.options.params); | ||
} else { | ||
@@ -153,0 +153,0 @@ throw Error("Invalid handler arguments"); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 2.0.3 | ||
// Generated by CoffeeScript 2.3.2 | ||
// # Stream Transformer Sync | ||
@@ -8,3 +8,3 @@ | ||
// `const data = transform(data, [options])` | ||
// `const records = transform(data, [options])` | ||
@@ -11,0 +11,0 @@ // ## Source Code |
{ | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"name": "stream-transform", | ||
@@ -16,11 +16,12 @@ "description": "Object transformations implementing the Node.js `stream.Transform` API", | ||
}, | ||
"homepage": "http://csv.adaltas.com/transform/", | ||
"homepage": "https://csv.js.org/transform/", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"coffeescript": "~2.0.1", | ||
"csv-generate": "~2.0.0", | ||
"mocha": "~4.0.1", | ||
"pad": "~2.0.1", | ||
"should": "~13.1.2" | ||
"@babel/cli": "^7.1.0", | ||
"@babel/core": "^7.1.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"coffeescript": "~2.3.2", | ||
"csv-generate": "~2.1.0", | ||
"mocha": "~5.2.0", | ||
"pad": "~2.2.1", | ||
"should": "~13.2.3" | ||
}, | ||
@@ -27,0 +28,0 @@ "optionalDependencies": {}, |
[![Build Status](https://api.travis-ci.org/adaltas/node-stream-transform.svg)](https://travis-ci.org/#!/adaltas/node-stream-transform) | ||
Part of the [CSV module][csv_home], this project is a simple object | ||
transformation framework. It implements the Node.js [`stream.Transform` API][streamtransform]. | ||
It also provides a simple callback-based API for convenience. | ||
It is both extremely easy to use and powerful. | ||
Part of the [CSV module](https://csv.js.org/), this project is a simple object transformation framework. It implements the Node.js [`stream.Transform` API](http://nodejs.org/api/stream.html#stream_class_stream_transform). It also provides a simple callback-based API for convenience. It is both extremely easy to use and powerful. | ||
[Documentation for the "csv-parse" package is available here][home]. | ||
## Documentation | ||
* [Project homepage](http://localhost:8000/stringify/) | ||
* [API](http://localhost:8000/stringify/api/) | ||
* [Options](http://localhost:8000/stringify/options/) | ||
* [Handler](http://localhost:8000/stringify/handler/) | ||
* [State properties](http://localhost:8000/stringify/state/) | ||
* [Examples](http://localhost:8000/stringify/examples/) | ||
## Features | ||
* Follow the Node.js [streaming API][streamtransform] | ||
* Simplicity with the optional callback API | ||
* Synchronous and asynchronous user handler functions | ||
* Accepts arrays of strings, or arrays of objects as input | ||
* Sequential or user-defined concurrent execution | ||
* Skip and create new records | ||
* Alter or clone input data | ||
* BSD License | ||
* Extends the native Node.js [transform stream API](http://nodejs.org/api/stream.html#stream_class_stream_transform) | ||
* Simplicity with the optional callback and sync API | ||
* Pipe transformations between readable and writable streams | ||
* Synchronous versus asynchronous user functions | ||
* Sequential and parallel execution | ||
* Accept object, array or JSON as input and output | ||
* Sequential or user-defined concurrent execution | ||
* Skip and multiply records | ||
* Alter or clone input records | ||
* BSD License | ||
Usage | ||
----- | ||
## Usage | ||
Refer to the [project webpage][home] for [an exhaustive list of options][home] | ||
and [some usage examples][examples]. | ||
The module is built on the Node.js Stream API. For the sake of simplify, a simple callback API is also provided. To give you a quick look, here's an example of the callback API: | ||
The module is built on the Node.js Stream API. For the sake of simplify, a | ||
simple callback API is also provided. To give you a quick look, here's an | ||
example of the callback API: | ||
```javascript | ||
@@ -43,21 +43,8 @@ var transform = require('stream-transform'); | ||
Development | ||
----------- | ||
## Development | ||
Tests are executed with mocha. To install it, simple run `npm install` | ||
followed by `npm test`. It will install mocha and its dependencies in your | ||
project "node_modules" directory and run the test suite. The tests run | ||
against the CoffeeScript source files. | ||
Tests are executed with mocha. To install it, simple run `npm install` followed by `npm test`. It will install mocha and its dependencies in your project "node_modules" directory and run the test suite. The tests run against the CoffeeScript source files. | ||
To generate the JavaScript files, run `npm run coffee`. | ||
The test suite is run online with [Travis](http://travis-ci.org/wdavidw/node-stream-transform) against the versions | ||
0.10, 0.11 and 0.12 of Node.js. | ||
[streamtransform]: http://nodejs.org/api/stream.html#stream_class_stream_transform | ||
[home]: http://csv.adaltas.com/transform/ | ||
[examples]: http://csv.adaltas.com/transform/examples/ | ||
[csv_home]: https://github.com/wdavidw/node-csv | ||
[stream-samples]: https://github.com/wdavidw/node-stream-transform/tree/master/samples | ||
[stream-test]: https://github.com/wdavidw/node-stream-transform/tree/master/test | ||
The test suite is run online with [Travis](http://travis-ci.org/wdavidw/node-stream-transform). See the [Travis definition file](https://github.com/adaltas/node-stream-transform/blob/master/.travis.yml) to view the tested Node.js version. |
@@ -9,3 +9,3 @@ | ||
return data | ||
}); | ||
}) | ||
transformer.on('readable', function(){ | ||
@@ -15,6 +15,6 @@ while(row = transformer.read()){ | ||
} | ||
}); | ||
}) | ||
transformer.on('error', function(err){ | ||
console.log(err.message) | ||
}); | ||
}) | ||
transformer.on('finish', function(){ | ||
@@ -21,0 +21,0 @@ assert.deepEqual(output, [ |
Sorry, the diff of this file is not supported yet
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
25292
18
652
0
8
50