https://github.com/danielearwicker/node-funkify
Like thunkify-wrap, but (a) doesn't modify the original object and (b) copes with functions that have function properties
https://github.com/danielearwicker/node-funkify
Last synced: 27 days ago
JSON representation
Like thunkify-wrap, but (a) doesn't modify the original object and (b) copes with functions that have function properties
- Host: GitHub
- URL: https://github.com/danielearwicker/node-funkify
- Owner: danielearwicker
- License: mit
- Created: 2014-06-23T13:32:14.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-06-23T14:03:47.000Z (almost 12 years ago)
- Last Synced: 2025-02-26T14:41:51.572Z (over 1 year ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## funkify
To thunkify an individual function you can use [thunkify](https://www.npmjs.org/package/thunkify).
What if you want to easily thunkify all the functions of a module or other object?
One popular solution I tried was [thunkify-wrap](https://www.npmjs.org/package/thunkify-wrap). It modifies the original object, overwriting its functions with the thunkified replacements. This could break some libraries if one exported function calls another. Also makes it difficult to keep the original object so you can opt to directly call the non-thunkified functions when you need to. Also it doesn't deal correctly with functions that have function properties of their own. e.g. [request](https://www.npmjs.org/package/request).
So I created funkify to avoid these issues. It always returns a new object, leaving the original untouched. Also it deals with modules that are really just functions with their own function properties.
## Installation
[](https://nodei.co/npm/funkify/)
## Usage
```javascript
var funkify = require('funkify');
// request() and request.post() get wrapped
var request = funkify(require('request'));
// redis client gets wrapped
var redis = funkify(require('redis').createClient());
// in a generator
var myListLength = yield redis.llen('myList');
```