Comparing version 0.0.0 to 0.0.1
@@ -1,1 +0,1 @@ | ||
module.exports = function(){}; | ||
module.exports = require('./lib/decor'); |
{ | ||
"name": "decor", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "assorted function decorators", | ||
"repository": "git@github.com:nomilous/decor.git", | ||
"main": "index.js", | ||
@@ -10,3 +11,10 @@ "scripts": { | ||
"author": "", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"dependencies": { | ||
"q": "~0.9.7" | ||
}, | ||
"devDependencies": { | ||
"ipso": "0.0.20", | ||
"should": "~2.1.1" | ||
} | ||
} |
@@ -5,1 +5,87 @@ decor | ||
assorted function decorators | ||
### `decor.deferred(fn)` | ||
* Decorates a function to be promisable | ||
* Injects as **a new first argument** the promise handler (`action`) | ||
* action. `resolve()`, `reject()` and `notify()` as usual from within | ||
* calling the decorated function returns the promise, availing `.then` to the caller | ||
* using [q](https://github.com/kriskowal/q) for the promising | ||
```coffee | ||
{deferred} = require 'decor' | ||
promisingFunction = deferred (action, arg1, argN) -> | ||
doSomethingAsync arg1, (err, res) -> | ||
# action.notify('50% complete') | ||
return action.reject err if err? | ||
return action.resolve res | ||
promisingFunction( 'arg1' ).then -> # as usual | ||
# | ||
# or, more fully | ||
# | ||
promisingFunction( 'arg1' ).then( | ||
(result) -> | ||
(error) -> | ||
(notify) -> | ||
) | ||
``` | ||
#### Before and After | ||
**Before** | ||
```coffee | ||
{defer} = require 'q' | ||
fn = (arg1) -> | ||
deferral = defer() | ||
doSomethingAsync arg1, (err, res) -> | ||
deferral.resolve res | ||
return deferral.promise | ||
fn('arg1').then ... | ||
``` | ||
**After** | ||
```coffee | ||
{deferred} = require 'decor' | ||
fn = deferred ({resolve, reject}, arg1) -> | ||
doSomethingAsync arg1, (err, res) -> | ||
resolve res | ||
fn('arg1').then ... | ||
``` | ||
### Dev | ||
``` | ||
# sudo npm install ipso-cli -g | ||
ipso -m | ||
``` |
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
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
4909
13
37
91
0
1
2