deferize
deferize
will turn any nodish callback-based function into a jQuery Promise.
It seems I always need something like this in my projects as of late so I figured others probably do too and I decided to extract it into its own tiny module.
Install
npm install deferize --save
Usage
The most basic use of deferize
is by feeding it a function.
var fs = ;var open = ;
What you get is a new function that is no longer callback-based but returns a promise instead.
For instance, you'd use the previous example as follows:
;
No Error Argument
Sometimes a callback doesn't get an error as its first argument. In that case, you should call deferize.noerror
:
var fs = ;var exists = deferize;
The underlying promise will be resolved if the first argument is trueish and rejected otherwise:
;
Synchronous Functions
For those rare situations where you need to deferize a synchronous function, you can use deferize.sync
:
var divide = deferize; ;
License
Copyright (c) 2012 - 2014 Julian Aubourg Licensed under the MIT license.