Comparing version 2.2.4 to 2.3.0
@@ -499,2 +499,8 @@ var abbott = require('abbott'); | ||
righto.fail = function(error){ | ||
return righto(function(error, done){ | ||
done(error); | ||
}, error); | ||
}; | ||
righto.isRighto = isRighto; | ||
@@ -501,0 +507,0 @@ righto.isThenable = isThenable; |
{ | ||
"name": "righto", | ||
"version": "2.2.4", | ||
"version": "2.3.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -480,2 +480,18 @@ # Righto | ||
## Fail | ||
A shorthand way to provide a failed result. | ||
This is handy for rejecting in .get methods. | ||
``` | ||
var something = someRighto.get(function(value){ | ||
if(!value){ | ||
return righto.fail('was falsey'); | ||
} | ||
return value; | ||
}); | ||
``` | ||
## Proxy support | ||
@@ -482,0 +498,0 @@ |
@@ -1313,2 +1313,28 @@ var test = require('tape'), | ||
t.notOk(righto.isResolvable(null), 'null is not a resolvable'); | ||
}); | ||
test('righto.fail', function(t){ | ||
t.plan(1); | ||
var falure = righto.fail('reasons'); | ||
falure(function(error){ | ||
t.equal(error, 'reasons'); | ||
}); | ||
}); | ||
test('righto.fail resolvable', function(t){ | ||
t.plan(1); | ||
var eventualFailData = righto(function(done){ | ||
setTimeout(function(){ | ||
done(null, 'reasons'); // Return the error in the result, not the rejection. | ||
}, 100); | ||
}); | ||
var falure = righto.fail(eventualFailData); | ||
falure(function(error){ | ||
t.equal(error, 'reasons'); | ||
}); | ||
}); |
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
58302
1525
635