Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/boneskull/promwrap
Proxy-Powered Promisification for your Pleasure
https://github.com/boneskull/promwrap
callback nodeback promise promises promisification promisify promisifyall wrapper
Last synced: 16 days ago
JSON representation
Proxy-Powered Promisification for your Pleasure
- Host: GitHub
- URL: https://github.com/boneskull/promwrap
- Owner: boneskull
- Created: 2017-08-24T03:13:37.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-21T20:27:06.000Z (over 4 years ago)
- Last Synced: 2024-10-10T01:58:12.387Z (about 1 month ago)
- Topics: callback, nodeback, promise, promises, promisification, promisify, promisifyall, wrapper
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# promwrap
Wraps modules, and other objects, full of callback functions in promises.
```javascript
let fun = (x, cb) => cb(null, x)
let _module = {fun, prop: 'test'}test('test basics', async t => {
t.plan(4)
let mod = promwrap(_module)
t.same(mod.prop, 'test')
t.same(mod.prop, 'test')
t.same(await mod.fun('test1'), 'test1')
t.same(await promwrap(fun)('test2'), 'test2')
})
```## API
### `promwrap(value, {exclude: string[]|string, excludeMain: bool, own: bool}): T`
Promisify all function properties of `value`. If `value` is a `Function`,
it will be promisified instead. Members of `Object.prototype` are *not*
promisified.Returns `value`, wrapped by a `Proxy`.
- If `exclude` is supplied, do not promisify this prop/list of props.
- If `excludeMain` is truthy and `value` is a `Function`, treat `value` like a
plain `Object` and promisify its props instead of `value` itself. In
addition, members of `Function.prototype` will *not* be promisified.
- If `own` is truthy, *only* promisify the `Object`'s "own" (in the
`Object.hasOwnProperty()` sense) props