Comparing version 0.0.2 to 0.0.3
@@ -15,3 +15,16 @@ module.exports.createPipe = function() { | ||
function remove(processor) { | ||
delete pipe[pipe.indexOf(processor)]; | ||
var processorIndex = pipe.indexOf(processor); | ||
if (processorIndex === -1) { | ||
throw new RangeError('processor function not found in pipe'); | ||
} | ||
delete pipe[processorIndex]; | ||
pipe = pipe.filter(function(value) { | ||
return value !== undefined; | ||
}); | ||
return self; | ||
} | ||
@@ -21,2 +34,3 @@ | ||
pipe = []; | ||
return self; | ||
} | ||
@@ -49,2 +63,2 @@ | ||
return self; | ||
}; | ||
}; |
{ | ||
"name": "piton-pipe", | ||
"description": "Build and run an Async pipeline of functions", | ||
"version": "0.0.2", | ||
"author": "Paul Serby <paul.serby@clock.co.uk>", | ||
"version": "0.0.3", | ||
"author": "Paul Serby <paul@serby.net>", | ||
"contributors": [ | ||
{ "name": "Paul Serby", "email": "paul.serby@clock.co.uk" } | ||
{ "name": "Paul Serby", "email": "paul@serby.net" } | ||
], | ||
@@ -12,7 +12,8 @@ "dependencies": { | ||
"devDependencies": { | ||
"expresso": "0.7.2" | ||
"mocha": "0.3.6", | ||
"should": "0.3.2" | ||
}, | ||
"keywords": ["pipe"], | ||
"repository": "git://github.com/PabloSerbo/piton-pipe", | ||
"main": "index", | ||
"repository": "git://github.com/serby/piton-pipe", | ||
"main": "index", | ||
"scripts": { | ||
@@ -22,3 +23,3 @@ "test": "cake test", | ||
}, | ||
"engines": { "node": ">= 0.4.6 < 0.5.0" } | ||
} | ||
"engines": { "node": ">= 0.4.6 < 0.7.0" } | ||
} |
# piton-pipe - Build and run an Async pipeline of functions. | ||
Input is given then passed though the functions in the pipe via callbacks. | ||
An input value is given to the pipe and passed each function in turn. | ||
This allows async operations to process the value. | ||
@@ -12,10 +13,10 @@ | ||
var pipe = require('piton-pipe').createPipe(['onCreate']); | ||
pipe.add('onCreate', function(value, callback) { | ||
pipe.add(function(value, callback) { | ||
callback(null, value + 2; | ||
}); | ||
pipe.add('onCreate', function(value, callback) { | ||
pipe.add(function(value, callback) { | ||
callback(null, value / 3); | ||
}); | ||
var value = 7; | ||
pipe.run(value, 'onCreate', function(error, newValue) { | ||
pipe.run(value, function(error, newValue) { | ||
console.log(newValue); | ||
@@ -25,5 +26,5 @@ }); | ||
## Credits | ||
* [Paul Serby](https://github.com/PabloSerbo/) | ||
* [Paul Serby](https://github.com/serby/) | ||
## Licence | ||
Licenced under the [New BSD License](http://opensource.org/licenses/bsd-license.php) |
@@ -9,39 +9,103 @@ var | ||
module.exports = { | ||
'add without a function fails': function() { | ||
var pipe = Pipe.createPipe(); | ||
assert.throws(function() { | ||
pipe.add(); | ||
}, /TypeError/); | ||
}, | ||
'add is chainable': function() { | ||
var pipe = Pipe.createPipe(); | ||
assert.strictEqual(pipe.add(additionProcess), pipe); | ||
}, | ||
'run does nothing with an empty pipe': function() { | ||
var pipe = Pipe.createPipe(); | ||
pipe.run(1, function(error, value) { | ||
assert.eql(value, 1); | ||
describe('pipe', function() { | ||
describe('#add()', function() { | ||
it('without a function as a parameter fails', function() { | ||
var pipe = Pipe.createPipe(); | ||
assert.throws(function() { | ||
pipe.add(); | ||
}, /TypeError/); | ||
}); | ||
}, | ||
'run processes correctly': function() { | ||
var pipe = Pipe.createPipe() | ||
.add(additionProcess) | ||
.add(additionProcess); | ||
it('is chainable', function() { | ||
var pipe = Pipe.createPipe(); | ||
pipe.add(additionProcess).should.equal(pipe); | ||
}); | ||
}); | ||
pipe.run(1, function(error, value) { | ||
assert.eql(value, 3); | ||
describe('#run()', function() { | ||
it('does nothing with an empty pipe', function(done) { | ||
var pipe = Pipe.createPipe(); | ||
pipe.run(1, function(error, value) { | ||
value.should.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}, | ||
'remove is successful': function() { | ||
var pipe = Pipe.createPipe() | ||
.add(additionProcess) | ||
.add(additionProcess); | ||
it('run processes correctly', function(done) { | ||
pipe.run(1, function(error, value) { | ||
assert.eql(value, 3); | ||
var pipe = Pipe.createPipe() | ||
.add(additionProcess) | ||
.add(additionProcess); | ||
pipe.run(1, function(error, value) { | ||
value.should.equal(3); | ||
done(); | ||
}); | ||
}); | ||
} | ||
}; | ||
}); | ||
describe('#remove()', function() { | ||
it('is successful', function(done) { | ||
var functionToRemove = function(value, callback) { | ||
callback(null, value + 10); | ||
}; | ||
var pipe = Pipe.createPipe() | ||
.add(additionProcess) | ||
.add(functionToRemove); | ||
pipe.remove(functionToRemove); | ||
pipe.run(1, function(error, value) { | ||
value.should.equal(2); | ||
done(); | ||
}); | ||
}); | ||
it('throws error if process function not found', function() { | ||
var pipe = Pipe.createPipe(); | ||
assert.throws(function() { | ||
pipe.remove(additionProcess); | ||
}, /RangeError: processor function not found in pipe/ ); | ||
}); | ||
it('is chainable', function() { | ||
var pipe = Pipe.createPipe(); | ||
pipe | ||
.add(additionProcess) | ||
.remove(additionProcess).should.equal(pipe); | ||
}); | ||
}); | ||
describe('#clear()', function() { | ||
it('does not error with empty pipe', function() { | ||
var pipe = Pipe.createPipe(); | ||
pipe.clear(); | ||
}); | ||
it('is chainable', function() { | ||
var pipe = Pipe.createPipe(); | ||
pipe | ||
.clear(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
5998
131
29
0
2
1