New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

two-step

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

two-step - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

62

index.js

@@ -1,6 +0,8 @@

function ParamList(step) {
function ParamList(step, name) {
this._idx = 1;
this._used = false;
this.vals = [ null ];
this.pending = [];
this.step = step;
this._idx = 1;
this.name = name;
}

@@ -16,5 +18,5 @@ ParamList.prototype = {

checkPending: function() {
if(!this.used && this.pending.length === 0) {
if(!this._used && this.pending.length === 0) {
this.step.apply(null, this.vals);
this.used = true;
this._used = true;
}

@@ -42,31 +44,30 @@ },

function errInfo(step, paramIdx, paramName) {
return { name: step, paramIdx: paramIdx, paramName: paramName };
function errInfo(stepName, paramIdx, paramName) {
return { name: stepName, paramIdx: paramIdx, paramName: paramName };
}
function StepObj(params, jumpTo, name) {
function StepObj(params, jumpTo, data) {
this._params = params;
this._jumpTo = jumpTo;
this.name = name;
this.data = data;
}
StepObj.prototype = {
val: function(name) {
var self = this, paramIdx = this._params.nextIdx();
var params = this._params, paramIdx = params.nextIdx();
return function(err, val) {
if(err) { return self._params.error(err, errInfo(self.name, paramIdx, name)); }
if(err) { return params.error(err, errInfo(params.name, paramIdx, name)); }
self._params.done(paramIdx, val);
params.done(paramIdx, val);
}
},
valArray: function(name) {
name = (name || "group");
var self = this, paramIdx = this._params.nextIdx();
var groupVals = new ParamList(function(err) {
if(err) { return self._params.error(err, errInfo(self.name, paramIdx, err.step.name)); }
name = (name || "array");
var params = this._params, paramIdx = params.nextIdx();
var arrayVals = new ParamList(function(err) {
if(err) { return params.error(err, errInfo(params.name, paramIdx, err.step.name)); }
self._params.done(paramIdx, groupVals.vals.slice(1));
params.done(paramIdx, arrayVals.vals.slice(1));
});
// Handles groups of zero length
process.nextTick(function() { groupVals.checkPending(); });
// Handles arrays of zero length
process.nextTick(function() { arrayVals.checkPending(); });

@@ -76,8 +77,8 @@ return {

valName = (valName || name + "(" + valIdx + ")");
var valIdx = groupVals.nextIdx();
var valIdx = arrayVals.nextIdx();
return function(err, val) {
if(err) { return groupVals.error(err, errInfo("", 0, valName)); }
if(err) { return arrayVals.error(err, errInfo("", 0, valName)); }
groupVals.done(valIdx, val);
arrayVals.done(valIdx, val);
};

@@ -94,8 +95,8 @@ },

listen: function(emitter, name) {
var self = this, paramIdx = this._params.nextIdx();
var params = this._params, paramIdx = params.nextIdx();
var chunks = [];
emitter.on('data', function (chunk) { chunks.push(chunk); });
emitter.on('error', function(err) { self._params.error(err, errInfo(self.name, paramIdx, name)); });
emitter.on('end', function() { self._params.done(paramIdx, chunks); });
emitter.on('error', function(err) { params.error(err, errInfo(params.name, paramIdx, name)); });
emitter.on('end', function() { params.done(paramIdx, chunks); });
},

@@ -127,10 +128,11 @@ jumpTo: function(func, args) {

function nextStep() {
function nextStep(err) {
// If error occurs in the last test, re-throw exception.
if(err && curIdx == steps.length) { throw err; }
if(curIdx >= steps.length) { return; }
var params = new ParamList(nextStep);
var stepObj = new StepObj(params, jumpTo, steps[curIdx].name);
var params = new ParamList(nextStep, steps[curIdx].name);
var stepObj = new StepObj(params, jumpTo, data);
stepObj.data = data;
try {

@@ -137,0 +139,0 @@ steps[curIdx++].apply(stepObj, arguments);

{ "name": "two-step"
, "version": "0.0.1"
, "version": "0.0.2"
, "description": "TwoStep is the spiritual successor of Step with better error handling and finer flow control"

@@ -4,0 +4,0 @@ , "keywords": [ "flow control", "step", "async" ]

@@ -5,3 +5,3 @@ var assert = require("assert");

save: function(stepObj, args) {
stepObj.data[stepObj.name] = { when: Date.now(), args: Array.prototype.slice.call(args) };
stepObj.data[stepObj._params.name] = { when: Date.now(), args: Array.prototype.slice.call(args) };
},

@@ -17,2 +17,4 @@ coverage: function(names) {

var nameA = names[i - 1], nameB = names[i];
assert.ok(data[nameA] != null, "Unknown function name: '" + nameA + "'");
assert.ok(data[nameB] != null, "Unknown function name: '" + nameB + "'");
assert.ok(data[nameA].when <= data[nameB].when, nameA + " was not called before " + nameB);

@@ -24,2 +26,3 @@ }

return function(data) {
assert.ok(data[name] != null, "Unknown function name: '" + name + "'");
assert.equal(data[name].args.length, 0, name + " didn't have empty args");

@@ -26,0 +29,0 @@ };

@@ -48,3 +48,14 @@ var fs = require("fs");

}
},
"throwing in last step": {
topic: function() { return TwoStep; },
"error in last step throws error": function(TwoStep) {
assert.throws(function() {
TwoStep(
function first() { },
function lastErr() { throw "Last Error Thrown"; }
);
}, "Last Error Thrown");
}
}
}).export(module);

@@ -8,3 +8,3 @@ var fs = require("fs");

vows.describe("Test `this.valArray`").addBatch({
"basic group test reading directories": {
"basic valArray test reading directories": {
topic: function() {

@@ -51,3 +51,3 @@ TwoStep(

},
"test empty group": {
"test empty valArray": {
topic: function() {

@@ -73,6 +73,6 @@ TwoStep(

"check results": function(data) {
assert.deepEqual(data["results"].args[1], [], "Empty group didn't result in empty array");
assert.deepEqual(data["results"].args[1], [], "Empty valArray didn't result in empty array");
}
},
"test sync group": {
"test sync calls to valArray async callbacks": {
topic: function() {

@@ -102,6 +102,6 @@ TwoStep(

"check results": function(data) {
assert.deepEqual(data["results"].args[1], [ 1, 2 ], "Group from sync values are incorrect");
assert.deepEqual(data["results"].args[1], [ 1, 2 ], "Results array from sync values is incorrect");
}
},
"test mixed sync and async group values": {
"test mixed sync and async values": {
topic: function() {

@@ -135,7 +135,7 @@ TwoStep(

data["results"].args[1], [ 1, 2, 3 ],
"Group from mixed sync and async values are incorrect"
"Results array from mixed sync and async values is incorrect"
);
}
},
"multi-group mixed sync and async values": {
"multi-valArray with mixed sync and async values": {
topic: function() {

@@ -175,7 +175,7 @@ TwoStep(

data["results"].args[1], [ 1, 2, 3 ],
"Multi group from mixed sync and async values are incorrect"
"Results array with mixed sync and async values is incorrect"
);
assert.deepEqual(
data["results"].args[2], [ "a", "b", "c" ],
"Multi group from mixed sync and async values are incorrect"
"Results array from mixed sync and async values is incorrect"
);

@@ -182,0 +182,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc