simple-compose
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

Forks Stargazers MIT License LinkedIn

Simple Compose

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:

  1. Redux compose is awesome, but is heavy;
  2. I searched for another composes libraries, but I don't find anything that I like;
  3. Come on, this "library" has less than 400 bytes what more do you want?

Built With

Vanilla Javascript and nothing more.

Installation

  1. Install the lib
    npm install simple-compose
    or
    yarn add simple-compose
  2. Use it
    import { compose } from 'simple-compose';
    
    /* Your code */
    
    export default compose(fn1, fn2, fn3, fn4, fn5, fn6, ..... f284)(mySimpleFunc)

Note

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:

Wrong 🔴

   function fn1(param1, param2, param3) {
      /** Implementation */
   }

   function fn2(param1, param2, param3) {
      /** Implementation */
   }

   compose(fn1, fn2)('foo', 'bar', 'xar');

Right ✅

   function fn1(param) {
      /** Implementation */
   }

   function fn2(param1, param2, param3) {
      /** Implementation */
   }

   compose(fn1, fn2)('foo', 'bar', 'xar');

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Emmanuel Kant Duarte - @emmanuelkantf - emmanuelkant.duarte@gmail.com

Project Link: https://github.com/emmanuelkant/simple-compose

Package Sidebar

Install

npm i simple-compose

Weekly Downloads

45

Version

1.2.2

License

MIT

Unpacked Size

8.79 kB

Total Files

6

Last publish

Collaborators

  • emmanuel_kant_duarte