Comparing version 0.1.0 to 0.1.1
var map = require('lie-map'); | ||
var cast = require('lie-cast'); | ||
function every(array,func){ | ||
var hasfunc = typeof func === 'function'; | ||
var code = Math.random().toString(); | ||
return map(array,function(value){ | ||
return cast(value).then(function(castValue){ | ||
return func(castValue); | ||
}).then(function(bool){ | ||
var cvalue = cast(value); | ||
if(hasfunc){ | ||
cvalue = cvalue.then(func); | ||
} | ||
return cvalue.then(function(bool){ | ||
if(!bool){ | ||
throw 'false'; | ||
throw code; | ||
} | ||
@@ -15,6 +19,10 @@ return; | ||
return true; | ||
},function(){ | ||
return false; | ||
},function(reason){ | ||
if(reason===code){ | ||
return false; | ||
}else{ | ||
throw reason; | ||
} | ||
}); | ||
} | ||
module.exports = every; |
{ | ||
"name": "lie-every", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "every goddman lie", | ||
@@ -28,3 +28,4 @@ "main": "lib/every.js", | ||
"istanbul": "~0.1.44", | ||
"lie-resolve": "~0.1.0" | ||
"lie-resolve": "~0.1.0", | ||
"lie": "~2.0.7" | ||
}, | ||
@@ -31,0 +32,0 @@ "dependencies": { |
@@ -18,10 +18,13 @@ | ||
```javascript | ||
every(array, function) | ||
every(array[, function]) | ||
``` | ||
applies the function the the array of promies or values (or mix) and returns true if they are all truthy. | ||
Applies the function the the array of promies or values (or mix) and returns true if they are all truthy. | ||
It is lazy and will resolve as soon as the first falsy value is encountered. | ||
If the function is omited then it tests the truthiness of the values. | ||
## License | ||
MIT |
'use strict'; | ||
var every = require('../lib/every'); | ||
var resolve = require('lie-resolve'); | ||
var promise = require('lie'); | ||
require("mocha-as-promised")(); | ||
@@ -10,20 +11,71 @@ var chai = require("chai"); | ||
describe("every", function() { | ||
it("should become true", function() { | ||
return every([1,2,3,4],function(v){return v<5}).should.become(true); | ||
}); | ||
it("should become false 1", function() { | ||
return every([1,2,3,4],function(v){return v>1;}).should.become(false); | ||
}); | ||
it("should become false 3", function() { | ||
return every([1,2,3,4],function(v){return v<4;}).should.become(false); | ||
}); | ||
it("should become true", function() { | ||
return every([resolve(1),resolve(2),3,4],function(v){return v<5}).should.become(true); | ||
}); | ||
it("should become false 1", function() { | ||
return every([resolve(1),resolve(2),3,4],function(v){return v>1;}).should.become(false); | ||
}); | ||
it("should become false 3", function() { | ||
return every([resolve(1),resolve(2),3,4],function(v){return v<4;}).should.become(false); | ||
}); | ||
describe('basic', function() { | ||
it("should become true", function() { | ||
return every([1, 2, 3, 4], function(v) { | ||
return v < 5 | ||
}).should.become(true); | ||
}); | ||
it("should become false 1", function() { | ||
return every([1, 2, 3, 4], function(v) { | ||
return v > 1; | ||
}).should.become(false); | ||
}); | ||
it("should become false 2", function() { | ||
return every([1, 2, 3, 4], function(v) { | ||
return v < 4; | ||
}).should.become(false); | ||
}); | ||
}); | ||
describe('async', function() { | ||
it("should become true", function() { | ||
return every([resolve(1), resolve(2), 3, 4], function(v) { | ||
return v < 5 | ||
}).should.become(true); | ||
}); | ||
it("should become false 1", function() { | ||
return every([resolve(1), resolve(2), 3, 4], function(v) { | ||
return v > 1; | ||
}).should.become(false); | ||
}); | ||
it("should become false 2", function() { | ||
return every([resolve(1), resolve(2), 3, 4], function(v) { | ||
return v < 4; | ||
}).should.become(false); | ||
}); | ||
}); | ||
describe('no func', function() { | ||
it('should work',function(){ | ||
return every([resolve(1), resolve(2), 3, 4]).should.become(true); | ||
}); | ||
it('should fail 1',function(){ | ||
return every([resolve(1), resolve(2), 0, 4]).should.become(false); | ||
}); | ||
it('should fail 2',function(){ | ||
return every([resolve(1), resolve(0), 3, 4]).should.become(false); | ||
}); | ||
}); | ||
describe('lazy',function(){ | ||
it("should be lazy", function() { | ||
return every([promise(function(yes,no){ | ||
setTimeout(function(){ | ||
no('nope'); | ||
},50); | ||
}),promise(function(yes,no){ | ||
setTimeout(function(){ | ||
yes(2); | ||
},10); | ||
}),3,5],function(v){return v%2;}).should.become(false); | ||
}); | ||
it("should fail on a failure", function() { | ||
return every([promise(function(yes,no){ | ||
setTimeout(function(){ | ||
no('nope'); | ||
},10); | ||
}),promise(function(yes,no){ | ||
setTimeout(function(){ | ||
yes(2); | ||
},50); | ||
}),3,5],function(v){return v%2;}).should.be.be.rejected.and.become('nope'); | ||
}); | ||
}); | ||
}); |
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
6013
105
30
7