https://github.com/coderaiser/zames
converts callback-based functions to Promises and apply currying to arguments
https://github.com/coderaiser/zames
converts-callback curry functional functional-programming nodejs promisify
Last synced: 3 months ago
JSON representation
converts callback-based functions to Promises and apply currying to arguments
- Host: GitHub
- URL: https://github.com/coderaiser/zames
- Owner: coderaiser
- License: mit
- Created: 2016-11-16T14:55:13.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-09-20T11:17:06.000Z (about 6 years ago)
- Last Synced: 2025-05-15T05:09:23.062Z (5 months ago)
- Topics: converts-callback, curry, functional, functional-programming, nodejs, promisify
- Language: JavaScript
- Size: 21.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
README
# Zames [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
`zames` converts callback-based functions to Promises and apply currying to arguments.
`zames` = [currify][currify] + [promisify][promisify].
## Install
`npm i zames --save`
## API
### zames(fn [,ctx])
- `fn` - function
- `ctx` - context`zames` can take just a `function`:
```js
const zames = require('zames');const promise = zames((a, b, fn) => {
fn(null, a + b);
});const add = promise('hello ');
add('world').then((a) => {
console.log(a);
// output
'hello world';
});```
Or can be used with `ctx` as well:
```js
const ctx = {
error: 'hello',
log: function(a, b, fn) {
fn(this.error);
}
}const withContext = zames(ctx.log, ctx);
withContext(1, 2)
.catch((e) => {
console.error(e.message);
// output
'hello';
});```
## Related
- [currify](https://github.com/coderaiser/currify "currify") - translate the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single or more arguments.
- [fullstore](https://github.com/coderaiser/fullstore "fullstore") - functional variables.
- [wraptile](https://github.com/coderaiser/wraptile "wraptile") - translate the evaluation of a function that takes multiple arguments into evaluating a sequence of 2 functions, each with a any count of arguments.
## License
MIT
[NPMIMGURL]: https://img.shields.io/npm/v/zames.svg?style=flat
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/zames/master.svg?style=flat
[DependencyStatusIMGURL]: https://img.shields.io/david/coderaiser/zames.svg?style=flat
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[NPMURL]: https://npmjs.org/package/zames "npm"
[BuildStatusURL]: https://travis-ci.org/coderaiser/zames "Build Status"
[DependencyStatusURL]: https://david-dm.org/coderaiser/zames "Dependency Status"
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"[CoverageURL]: https://coveralls.io/github/coderaiser/zames?branch=master
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/zames/badge.svg?branch=master&service=github[currify]: https://en.wikipedia.org/wiki/Currying "Currying"
[promisify]: https://github.com/digitaldesignlabs/es6-promisify "Promisify"