Socket
Socket
Sign inDemoInstall

stream-transform

Package Overview
Dependencies
1
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.8 to 2.0.0

lib/es5/index.d.ts

17

CHANGELOG.md
# Changelog
## Version 2.0.0
Breaking changes:
* state: isolate properties into the "state" property
New Features:
* typescript: new ts definitions
Minor enhancements:
* api: clone options
* api: simplify argument discovery
* project: fix license in package.json
* babel: include .babelrc to git
* package: latest dependencies
## Version 1.0.8

@@ -9,3 +24,3 @@

* package: update license to MIT
* travis: test agains Node.js 11
* travis: test against Node.js 11

@@ -12,0 +27,0 @@ ## Version 1.0.7

93

lib/es5/index.js

@@ -5,3 +5,3 @@ "use strict";

// Generated by CoffeeScript 2.3.2
// Generated by CoffeeScript 2.4.1
// # Stream Transformer

@@ -12,16 +12,21 @@ // Pass all elements of an array or a stream to transform, filter and add. Features include:

// arguments signature.
// * Ability to skip data.
// * Ability to skip records.
// * 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;
var Transformer, clone, stream, util;
stream = require('stream');
util = require('util'); // ## Usage
util = require('util');
var _require = require('mixme');
clone = _require.clone;
// ## Usage
// Callback approach, for ease of use:
// `transform([data], handler, [options])`
// `transform(records, [options], handler, callback)`
// Stream API, for maximum of power:
// `transform([data], [options], handler, [options], [callback])`
// `transform([records], [options], handler, [callback])`
module.exports = function () {
var argument, callback, data, error, handler, i, j, k, len, options, result, transform, type, v;
var argument, callback, error, handler, i, j, len, options, records, result, transform, type;
options = {};

@@ -39,17 +44,6 @@

if (i === 0) {
if (type === 'function') {
handler = argument;
} else if (type !== null) {
data = argument;
}
continue;
}
if (type === 'object') {
for (k in argument) {
v = argument[k];
options[k] = v;
}
if (type === 'array') {
records = argument;
} else if (type === 'object') {
options = clone(argument);
} else if (type === 'function') {

@@ -62,3 +56,3 @@ if (handler && i === arguments.length - 1) {

} else if (type !== 'null') {
throw new Error('Invalid arguments');
throw new Error("Invalid Arguments: got ".concat(JSON.stringify(argument), " at position ").concat(i));
}

@@ -70,8 +64,8 @@ }

if (data) {
if (records) {
process.nextTick(function () {
var len1, m, row;
var k, len1, record;
for (m = 0, len1 = data.length; m < len1; m++) {
row = data[m];
for (k = 0, len1 = records.length; k < len1; k++) {
record = records[k];

@@ -82,3 +76,3 @@ if (error) {

transform.write(row);
transform.write(record);
}

@@ -127,16 +121,23 @@

var options1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var transform1 = arguments.length > 1 ? arguments[1] : undefined;
var base;
var handler1 = arguments.length > 1 ? arguments[1] : undefined;
var base, base1;
this.options = options1;
this.transform = transform1;
this.handler = handler1;
if ((base = this.options).consume == null) {
base.consume = false;
}
this.options.objectMode = true;
if ((base = this.options).parallel == null) {
base.parallel = 100;
if ((base1 = this.options).parallel == null) {
base1.parallel = 100;
}
stream.Transform.call(this, this.options);
this.running = 0;
this.started = 0;
this.finished = 0;
this.state = {
running: 0,
started: 0,
finished: 0
};
return this;

@@ -152,6 +153,6 @@ };

var callback, err, l;
this.started++;
this.running++;
this.state.started++;
this.state.running++;
if (this.running < this.options.parallel) {
if (this.state.running < this.options.parallel) {
cb();

@@ -162,3 +163,3 @@ cb = null;

try {
l = this.transform.length;
l = this.handler.length;

@@ -171,3 +172,3 @@ if (this.options.params != null) {

// sync
this.__done(null, [this.transform.call(this, chunk, this.options.params)], cb);
this.__done(null, [this.handler.call(this, chunk, this.options.params)], cb);
} else if (l === 2) {

@@ -183,3 +184,3 @@ // async

this.transform.call(this, chunk, callback, this.options.params);
this.handler.call(this, chunk, callback, this.options.params);
} else {

@@ -198,3 +199,3 @@ throw Error("Invalid handler arguments");

this._ending = function () {
if (this.running === 0) {
if (this.state.running === 0) {
return cb();

@@ -209,3 +210,3 @@ }

var chunk, j, len;
this.running--;
this.state.running--;

@@ -216,3 +217,3 @@ if (err) {

this.finished++;
this.state.finished++;

@@ -219,0 +220,0 @@ for (j = 0, len = chunks.length; j < len; j++) {

@@ -5,13 +5,17 @@ "use strict";

// Generated by CoffeeScript 2.3.2
// Generated by CoffeeScript 2.4.1
// # Stream Transformer Sync
// Provides a synchronous alternative to the CSV transformer.
// ## Usage
// `const records = transform(data, [options])`
// `const records = transform(records, [options], handler)`
// ## Source Code
var transform;
var clone, transform;
transform = require('.');
var _require = require('mixme');
clone = _require.clone;
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, expected_handler_length, handler, i, j, k, len, len1, options, record, records, transformer, type; // Import arguments normalization

@@ -30,17 +34,6 @@ options = {};

if (i === 0) {
if (type === 'function') {
handler = argument;
} else if (type !== null) {
data = argument;
}
continue;
}
if (type === 'object') {
for (k in argument) {
v = argument[k];
options[k] = v;
}
if (type === 'array') {
records = argument;
} else if (type === 'object') {
options = clone(argument);
} else if (type === 'function') {

@@ -53,3 +46,3 @@ if (handler && i === arguments.length - 1) {

} else if (type !== 'null') {
throw new Error('Invalid arguments');
throw new Error("Invalid Arguments: got ".concat(JSON.stringify(argument), " at position ").concat(i));
}

@@ -77,4 +70,4 @@ } // Validate arguments

for (l = 0, len1 = data.length; l < len1; l++) {
record = data[l];
for (k = 0, len1 = records.length; k < len1; k++) {
record = records[k];

@@ -81,0 +74,0 @@ transformer._transform(record, null, function () {});

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 2.3.2
// Generated by CoffeeScript 2.4.1
// # Stream Transformer

@@ -9,3 +9,3 @@

// arguments signature.
// * Ability to skip data.
// * Ability to skip records.
// * Sequential and concurrent execution using the "parallel" options.

@@ -15,3 +15,3 @@

// information.
var Transformer, stream, util;
var Transformer, clone, stream, util;

@@ -22,2 +22,4 @@ stream = require('stream');

({clone} = require('mixme'));
// ## Usage

@@ -27,9 +29,9 @@

// `transform([data], handler, [options])`
// `transform(records, [options], handler, callback)`
// Stream API, for maximum of power:
// `transform([data], [options], handler, [options], [callback])`
// `transform([records], [options], handler, [callback])`
module.exports = function() {
var argument, callback, data, error, handler, i, j, k, len, options, result, transform, type, v;
var argument, callback, error, handler, i, j, len, options, records, result, transform, type;
options = {};

@@ -44,15 +46,6 @@ for (i = j = 0, len = arguments.length; j < len; i = ++j) {

}
if (i === 0) {
if (type === 'function') {
handler = argument;
} else if (type !== null) {
data = argument;
}
continue;
}
if (type === 'object') {
for (k in argument) {
v = argument[k];
options[k] = v;
}
if (type === 'array') {
records = argument;
} else if (type === 'object') {
options = clone(argument);
} else if (type === 'function') {

@@ -65,3 +58,3 @@ if (handler && i === arguments.length - 1) {

} else if (type !== 'null') {
throw new Error('Invalid arguments');
throw new Error(`Invalid Arguments: got ${JSON.stringify(argument)} at position ${i}`);
}

@@ -71,11 +64,11 @@ }

error = false;
if (data) {
if (records) {
process.nextTick(function() {
var len1, m, row;
for (m = 0, len1 = data.length; m < len1; m++) {
row = data[m];
var k, len1, record;
for (k = 0, len1 = records.length; k < len1; k++) {
record = records[k];
if (error) {
break;
}
transform.write(row);
transform.write(record);
}

@@ -117,14 +110,19 @@ return transform.end();

// Options are documented [here](http://csv.js.org/transform/options/).
Transformer = function(options1 = {}, transform1) {
var base;
Transformer = function(options1 = {}, handler1) {
var base, base1;
this.options = options1;
this.transform = transform1;
this.handler = handler1;
if ((base = this.options).consume == null) {
base.consume = false;
}
this.options.objectMode = true;
if ((base = this.options).parallel == null) {
base.parallel = 100;
if ((base1 = this.options).parallel == null) {
base1.parallel = 100;
}
stream.Transform.call(this, this.options);
this.running = 0;
this.started = 0;
this.finished = 0;
this.state = {
running: 0,
started: 0,
finished: 0
};
return this;

@@ -139,5 +137,5 @@ };

var callback, err, l;
this.started++;
this.running++;
if (this.running < this.options.parallel) {
this.state.started++;
this.state.running++;
if (this.state.running < this.options.parallel) {
cb();

@@ -147,3 +145,3 @@ cb = null;

try {
l = this.transform.length;
l = this.handler.length;
if (this.options.params != null) {

@@ -153,3 +151,3 @@ l--;

if (l === 1) { // sync
this.__done(null, [this.transform.call(this, chunk, this.options.params)], cb);
this.__done(null, [this.handler.call(this, chunk, this.options.params)], cb);
} else if (l === 2) { // async

@@ -159,3 +157,3 @@ callback = (err, ...chunks) => {

};
this.transform.call(this, chunk, callback, this.options.params);
this.handler.call(this, chunk, callback, this.options.params);
} else {

@@ -173,3 +171,3 @@ throw Error("Invalid handler arguments");

this._ending = function() {
if (this.running === 0) {
if (this.state.running === 0) {
return cb();

@@ -183,7 +181,7 @@ }

var chunk, j, len;
this.running--;
this.state.running--;
if (err) {
return this.emit('error', err);
}
this.finished++;
this.state.finished++;
for (j = 0, len = chunks.length; j < len; j++) {

@@ -190,0 +188,0 @@ chunk = chunks[j];

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 2.3.2
// Generated by CoffeeScript 2.4.1
// # Stream Transformer Sync

@@ -8,11 +8,13 @@

// `const records = transform(data, [options])`
// `const records = transform(records, [options], handler)`
// ## Source Code
var transform;
var clone, transform;
transform = require('.');
({clone} = require('mixme'));
module.exports = function() {
var argument, callback, chunks, data, expected_handler_length, handler, i, j, k, l, len, len1, options, record, transformer, type, v;
var argument, callback, chunks, expected_handler_length, handler, i, j, k, len, len1, options, record, records, transformer, type;
// Import arguments normalization

@@ -28,15 +30,6 @@ options = {};

}
if (i === 0) {
if (type === 'function') {
handler = argument;
} else if (type !== null) {
data = argument;
}
continue;
}
if (type === 'object') {
for (k in argument) {
v = argument[k];
options[k] = v;
}
if (type === 'array') {
records = argument;
} else if (type === 'object') {
options = clone(argument);
} else if (type === 'function') {

@@ -49,3 +42,3 @@ if (handler && i === arguments.length - 1) {

} else if (type !== 'null') {
throw new Error('Invalid arguments');
throw new Error(`Invalid Arguments: got ${JSON.stringify(argument)} at position ${i}`);
}

@@ -67,4 +60,4 @@ }

};
for (l = 0, len1 = data.length; l < len1; l++) {
record = data[l];
for (k = 0, len1 = records.length; k < len1; k++) {
record = records[k];
transformer._transform(record, null, (function() {}));

@@ -71,0 +64,0 @@ }

{
"version": "1.0.8",
"version": "2.0.0",
"name": "stream-transform",

@@ -11,3 +11,3 @@ "description": "Object transformations implementing the Node.js `stream.Transform` API",

],
"license": "BSD-3-Clause",
"license": "MIT",
"repository": {

@@ -18,11 +18,29 @@ "type": "git",

"homepage": "https://csv.js.org/transform/",
"coffeelintConfig": {
"indentation": {
"level": "error",
"value": 2
},
"line_endings": {
"level": "error",
"value": "unix"
},
"max_line_length": {
"level": "ignore"
}
},
"devDependencies": {
"@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"
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@types/mocha": "^5.2.6",
"@types/node": "^11.13.7",
"@types/should": "^13.0.0",
"coffeescript": "~2.4.1",
"csv-generate": "~3.2.0",
"mocha": "~6.1.4",
"pad": "~2.3.0",
"should": "~13.2.3",
"ts-node": "^8.1.0",
"typescript": "^3.4.5"
},

@@ -32,3 +50,3 @@ "optionalDependencies": {},

"scripts": {
"preversion": "rm -rf lib && npm test && grep '## Trunk' CHANGELOG.md",
"preversion": "grep '## Trunk' CHANGELOG.md && npm test && cp lib/*.ts lib/es5 && git add lib/es5/*.ts",
"version": "version=`grep '^ \"version\": ' package.json | sed 's/.*\"\\([0-9\\.]*\\)\".*/\\1/'` && sed -i \"s/## Trunk/## Version $version/\" CHANGELOG.md && git add CHANGELOG.md",

@@ -41,4 +59,13 @@ "postversion": "git push && git push --tags && npm publish",

"pretest": "coffee -b -o lib src && cd lib && babel *.js -d es5 && cd ..",
"test": "mocha test/**/*.coffee"
"test": "mocha test/**/*.{coffee,ts}"
},
"types": [
"./lib/es5/index.d.ts",
"./lib/es5/sync.d.ts",
"./lib/index.d.ts",
"./lib/sync.d.ts"
],
"dependencies": {
"mixme": "^0.3.1"
}
}

@@ -16,3 +16,3 @@

transformer.on('error', function(err){
console.log(err.message)
console.error(err.message)
})

@@ -19,0 +19,0 @@ transformer.on('finish', function(){

@@ -19,3 +19,3 @@

.on('error', function(err){
console.log(err.message)
console.error(err.message)
})

@@ -22,0 +22,0 @@ .on('finish', function(){

@@ -12,3 +12,3 @@

setTimeout( () => {
const {running, started, finished} = this
const {running, started, finished} = this.state
assert.equal(running, test_running--)

@@ -23,3 +23,3 @@ assert.equal(started, test_started)

process.stdout.write('-------\n')
const {running, started, finished} = this
const {running, started, finished} = this.state
process.stdout.write(`${running}_${started}_${finished}\n`)

@@ -26,0 +26,0 @@ })

@@ -8,3 +8,3 @@

setTimeout( () => {
const {running, started, finished} = transformer
const {running, started, finished} = transformer.state
callback(null, `${running}_${started}_${finished}\n`)

@@ -16,3 +16,3 @@ }, 100)

process.stdout.write('-------\n')
const {running, started, finished} = transformer
const {running, started, finished} = transformer.state
process.stdout.write(`${running}_${started}_${finished}\n`)

@@ -19,0 +19,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc