This is just a simple, zero dependency, vanilla JavaScript, 100% compatible with all browsers and straight forward compose of functions.
Here's why this exists:
- Redux compose is awesome, but is heavy;
- I searched for another composes libraries, but I don't find anything that I like;
- Come on, this "library" has less than 400 bytes what more do you want?
Vanilla Javascript and nothing more.
- Install the lib
or
npm install simple-compose
yarn add simple-compose
- Use it
import { compose } from 'simple-compose'; /* Your code */ export default compose(fn1, fn2, fn3, fn4, fn5, fn6, ..... f284)(mySimpleFunc)
In case you need. The function that is returned by the compose
function, can accept as many params as you want but the subsequence function doesn't. Those functions just accept only one param, which is the param that the last function returned. See the examples below:
function fn1(param1, param2, param3) {
/** Implementation */
}
function fn2(param1, param2, param3) {
/** Implementation */
}
compose(fn1, fn2)('foo', 'bar', 'xar');
function fn1(param) {
/** Implementation */
}
function fn2(param1, param2, param3) {
/** Implementation */
}
compose(fn1, fn2)('foo', 'bar', 'xar');
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Emmanuel Kant Duarte - @emmanuelkantf - emmanuelkant.duarte@gmail.com
Project Link: https://github.com/emmanuelkant/simple-compose