Comparing version 0.1.0 to 0.2.0
require( "ee-error" ); | ||
require('ee-error'); | ||
module.exports = require( "./lib/async" ); | ||
module.exports = require('./lib/async'); |
@@ -5,5 +5,5 @@ | ||
module.exports = { | ||
wait: require( "./wait" ) | ||
, each: require( "./each" ) | ||
, chain: require( "./chain" ) | ||
wait: require('./wait') | ||
, each: require('./each') | ||
, chain: require('./chain') | ||
}; |
var each = require( "./each" ) | ||
, log = require( "ee-log" ) | ||
, type = require( "ee-types" ); | ||
var each = require('./each') | ||
, log = require('ee-log') | ||
, type = require('ee-types'); | ||
module.exports = function(){ | ||
var args = [ [] ], callback; | ||
module.exports = function() { | ||
var args = [[]], callback; | ||
Array.prototype.slice.call( arguments, 0 ).forEach( function( arg, index, arr ){ | ||
if ( index === arr.length - 1 ){ | ||
if ( !type.function( arg ) ) throw new Error( "Last argument must be typeof «function»!" ).setName( "InvalidArgumentException" ); | ||
Array.prototype.slice.call(arguments, 0).forEach(function(arg, index, arr) { | ||
if (index === arr.length - 1) { | ||
if (!type.function(arg)) throw new Error('Last argument must be typeof «function»!').setName('InvalidArgumentException'); | ||
callback = arg; | ||
} | ||
else { | ||
if ( type.function( arg ) ) args.push( arg ); | ||
else args[ 0 ].push( arg ); | ||
if (type.function(arg)) args.push(arg); | ||
else args[0].push(arg); | ||
} | ||
} ); | ||
}); | ||
args.push( function( err, results ){ | ||
callback( err, results[ 0 ] ); | ||
} ); | ||
args.push(function(err, results) { | ||
callback(err, results[0]); | ||
}); | ||
each.apply( undefined, args ); | ||
each.apply(undefined, args); | ||
}; |
101
lib/each.js
var type = require( "ee-types" ) | ||
, log = require( "ee-log" ); | ||
var type = require('ee-types') | ||
, log = require('ee-log'); | ||
var work = function( item, fn, index, next ){ | ||
var arg = item.result.concat( function(){ | ||
var work = function(item, fn, index, next) { | ||
var arg = item.result.concat(function() { | ||
item.result = []; | ||
Array.prototype.slice.call( arguments, 0 ).every( function( arg, argIndex ){ | ||
if ( argIndex === 0 ){ | ||
if ( type.error( arg ) ) { | ||
Array.prototype.slice.call(arguments, 0).every(function(arg, argIndex) { | ||
if (argIndex === 0) { | ||
if (type.error(arg)) { | ||
item.result = arg; | ||
@@ -19,11 +20,11 @@ return false; | ||
} | ||
else item.result.push( arg ); | ||
else item.result.push(arg); | ||
return true; | ||
} ); | ||
}); | ||
next( type.error( item.result ) ); | ||
} ); | ||
next(type.error(item.result)); | ||
}); | ||
fn.apply( undefined, arg ); | ||
fn.apply(undefined, arg); | ||
}; | ||
@@ -34,11 +35,11 @@ | ||
var pipeline = function( item, workers, complete ){ | ||
var pipeline = function(item, workers, complete) { | ||
var index = 0; | ||
var doJob = function(){ | ||
work( item, workers[ index ], index, function( isError ){ | ||
var doJob = function() { | ||
work(item, workers[index], index, function(isError) { | ||
index++; | ||
if ( index < workers.length && !isError ) doJob(); | ||
else complete( isError ? 0 : item.result.length, isError ); | ||
if (index < workers.length && !isError) doJob(); | ||
else complete(isError ? 0 : item.result.length, isError); | ||
} ); | ||
@@ -53,30 +54,46 @@ } | ||
module.exports = function(){ | ||
var items = [], workers = [], callback; | ||
var items = [] | ||
, workers = [] | ||
, finished = 0 | ||
, maxLen = 0 | ||
, errCount = 0 | ||
, complete | ||
, callback; | ||
Array.prototype.slice.call( arguments, 0 ).forEach( function( arg, index, arr ){ | ||
if ( index === 0 ){ | ||
if ( !type.array( arg ) ) throw new Error( "Argument 0 must be typeof «array»! got «"+type( arg )+"»" ).setName( "InvalidArgumentException" ); | ||
items = arg.map( function( item ){ return { index: index, result: type.array( item ) ? item: [ item ] }; } ); | ||
// filter callback and input from worker functions | ||
Array.prototype.slice.call(arguments, 0).forEach(function(arg, index, arr){ | ||
if (index === 0){ | ||
if (!type.array(arg)) throw new Error('Argument 0 must be typeof «array»! got «'+type( arg )+'»').setName('InvalidArgumentException'); | ||
items = arg.map(function(item){ | ||
return { | ||
index: index | ||
, result: type.array(item) ? item: [item] | ||
}; | ||
}); | ||
} | ||
else if ( index === arr.length - 1 ){ | ||
if ( !type.function( arg ) ) throw new Error( "Last argument must be typeof «function»! got «"+type( arg )+"»" ).setName( "InvalidArgumentException" ); | ||
else if (index === arr.length - 1) { | ||
if (!type.function(arg)) throw new Error('Last argument must be typeof «function»! got «'+type( arg )+'»').setName('InvalidArgumentException'); | ||
callback = arg; | ||
} | ||
else { | ||
if ( !type.function( arg ) ) throw new Error( "workers must be typeof «function»! got «"+type( arg )+"»" ).setName( "InvalidArgumentException" ); | ||
workers.push( arg ); | ||
if (!type.function(arg)) throw new Error('workers must be typeof «function»! got «'+type( arg )+'»').setName('InvalidArgumentException'); | ||
workers.push(arg); | ||
} | ||
} ); | ||
}); | ||
var finished = 0, maxLen = 0, errCount = 0, complete = function( argLen, hasError ){ | ||
if ( argLen > maxLen ) maxLen = argLen; | ||
if ( hasError ) errCount++; | ||
complete = function(argLen, hasError) { | ||
var i = 0; | ||
if ( ++finished === items.length ){ | ||
if (argLen > maxLen) maxLen = argLen; | ||
if (hasError) errCount++; | ||
items.sort( function( a, b ){ return a.index > b.index ? 1 : -1 } ); | ||
if (++finished === items.length) { | ||
items = items.map( function( item ){ | ||
if ( maxLen <= 1 ) return type.array( item.result ) ? item.result[ 0 ] : item.result; | ||
items.sort(function(a, b) { | ||
return a.index > b.index ? 1 : -1 | ||
}); | ||
items = items.map(function(item) { | ||
if (maxLen <= 1) return type.array(item.result) ? item.result[0] : item.result; | ||
else return item.result; | ||
@@ -86,4 +103,10 @@ } ); | ||
if ( errCount ) callback( new Error( "There were "+errCount+" errors while processing your data!" ).setName( "ProcessingError" ), items ); | ||
else callback( undefined, items ); | ||
if (errCount) { | ||
i = items.length; | ||
while(i--) { | ||
if (item instanceof Error) return callback(item); | ||
} | ||
callback(new Error('There were '+errCount+' errors while processing your data!').setName('ProcessingError'), items); | ||
} | ||
else callback(undefined, items); | ||
} | ||
@@ -93,5 +116,5 @@ }; | ||
items.forEach( function( item, idx ){ | ||
pipeline( item, workers, complete ); | ||
} ); | ||
items.forEach(function(item, idx) { | ||
pipeline(item, workers, complete); | ||
}); | ||
} |
var type = require( "ee-types" ) | ||
, log = require( "ee-log" ); | ||
var type = require('ee-types') | ||
, log = require('ee-log'); | ||
@@ -9,38 +9,50 @@ | ||
module.exports = function(){ | ||
var jobs = [], callback, resLen = 0; | ||
module.exports = function() { | ||
var jobs = [] | ||
, resLen = 0 | ||
, results = [] | ||
, finished = 0 | ||
, errCount = 0 | ||
, complete | ||
, callback; | ||
Array.prototype.slice.call( arguments, 0 ).forEach( function( arg, index, arr ){ | ||
if ( !type.function( arg ) ) throw new Error( "Expected type «function», got «"+type( arg ) +"»!" ).setName( "InvalidArgumentException" ); | ||
if ( index === arr.length -1 ) callback = arg; | ||
else jobs.push( arg ); | ||
} ); | ||
Array.prototype.slice.call(arguments, 0).forEach(function(arg, index, arr) { | ||
if (!type.function(arg)) throw new Error('Expected type «function», got «'+type(arg)+'»!').setName('InvalidArgumentException'); | ||
if (index === arr.length -1) callback = arg; | ||
else jobs.push(arg); | ||
}); | ||
var results = [], finished = 0, errCount = 0, complete = function( index, args ){ | ||
complete = function(index, args) { | ||
var i, a; | ||
finished++; | ||
if (args.length > 0) { | ||
a = args[0]; | ||
if ( args.length > 0 ){ | ||
var a = args[ 0 ]; | ||
if (type.undefined(a) || type.null(a)) args.shift(); | ||
else if (type.error(a)) errCount++, args = args[0]; | ||
if ( type.undefined( a ) || type.null( a ) ) args.shift(); | ||
else if ( type.error( a ) ) errCount++, args = args[ 0 ]; | ||
if (args.length > resLen) resLen = args.length; | ||
if ( args.length > resLen ) resLen = args.length; | ||
results[ index ] = args; | ||
results[index] = args; | ||
} | ||
if ( finished === jobs.length ) { | ||
if ( resLen <= 1 ){ | ||
results = results.map( function( r ){ | ||
return type.array( r ) ? r[ 0 ] : r; | ||
} ); | ||
if (finished === jobs.length) { | ||
if (resLen <= 1) { | ||
results = results.map(function(r) { | ||
return type.array(r) ? r[0] : r; | ||
}); | ||
} | ||
if ( errCount > 0 ) callback( new Error( "There were "+errCount+" errors while processing your data!" ).setName( "ProcessingError" ), results ); | ||
else callback( undefined, results ); | ||
if (errCount) { | ||
i = results.length; | ||
while(i--) { | ||
if (results instanceof Error) return callback(results); | ||
} | ||
callback(new Error('There were '+errCount+' errors while processing your data!').setName('ProcessingError'), results); | ||
} | ||
else callback(undefined, results); | ||
} | ||
@@ -50,7 +62,7 @@ } | ||
jobs.forEach( function( job, index ){ | ||
job( function(){ | ||
complete( index, Array.prototype.slice.call( arguments, 0 ) ); | ||
} ); | ||
} ); | ||
jobs.forEach(function(job, index) { | ||
job(function() { | ||
complete(index, Array.prototype.slice.call(arguments, 0)); | ||
}); | ||
}); | ||
} |
{ | ||
"name" : "ee-async" | ||
, "description" : "simple control flow helpers" | ||
, "version" : "0.1.0" | ||
, "description" : "simpler control flow for asynchronous operations" | ||
, "version" : "0.2.0" | ||
, "homepage" : "https://github.com/eventEmitter/ee-async" | ||
@@ -19,9 +19,9 @@ , "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)" | ||
, "dependencies": { | ||
"ee-types" : "*" | ||
, "ee-log" : "*" | ||
, "ee-error" : "*" | ||
"ee-types" : "0.1.x" | ||
, "ee-log" : "0.2.x" | ||
, "ee-error" : "0.1.x" | ||
} | ||
, "devDependencies": {} | ||
, "optionalDependencies": {} | ||
, "keywords" : [ "asnc", "control-flow", "each", "chain", "wait" ] | ||
, "keywords" : ["asnc", "control-flow", "each", "chain", "wait"] | ||
, "scripts": { | ||
@@ -28,0 +28,0 @@ "test" : "node test.js" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 3 instances in 1 package
8551
190
1
1
+ Addedee-class@0.4.0(transitive)
+ Addedee-log@0.2.23(transitive)
+ Addedee-types@0.1.3(transitive)
- Removed@distributed-systems/callsite@1.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.13.2.1(transitive)
- Removedapp-root-path@2.2.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedchalk@1.1.32.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedee-class@1.4.0(transitive)
- Removedee-log@1.1.03.0.9(transitive)
- Removedee-types@2.2.14.0.4(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedlogd-console-output@1.3.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedsection-tests@1.3.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.05.5.0(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedee-error@0.1.x
Updatedee-log@0.2.x
Updatedee-types@0.1.x