Socket
Socket
Sign inDemoInstall

decor

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0 to 0.0.1

.npmignore

2

index.js

@@ -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
```
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc