Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allnulled/hook-by-priority
Hooking system using priority numbers.
https://github.com/allnulled/hook-by-priority
Last synced: 1 day ago
JSON representation
Hooking system using priority numbers.
- Host: GitHub
- URL: https://github.com/allnulled/hook-by-priority
- Owner: allnulled
- Created: 2020-05-25T14:05:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-25T14:49:30.000Z (over 4 years ago)
- Last Synced: 2024-10-04T06:49:50.014Z (about 1 month ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hook-by-priority
Hooking system using priority numbers.
## Advantages
- **Asynchronous hooks.**
- **Parameters passed along the cycle of hooks.**
- **Less than 50 lines of code.**
- **For `node.js` or `browser`.**
- **No dependencies at all.**## Installation
`$ npm install -s hook-by-priority`
## Usage
This example appends a character for each hook asynchronously.
It also uses `priority` option to order the `hooks` added to the created hooks-manager.
```js
const Hooks = require("hook-by-priority");
const hooks = Hooks.create();const add = function(char, data) {
return new Promise(function(ok, fail) {
data.msg += char;
setTimeout(ok, 100);
});
};hooks.add("on:init", async params => await add("e", params), 90);
hooks.add("on:init", async params => await add("!", params), 50);
hooks.add("on:init", async params => await add("l", params), 70);
hooks.add("on:init", async params => await add("o", params), 60);
hooks.add("on:init", async params => await add("l", params), 80);
hooks.add("on:init", async params => await add("H", params), 100);
hooks.use("on:init", { msg: "" }).then(output => console.log(output.msg));
```This script is also under `test/readme.test.js` file of the project.
## License
This project is released under [WTFPL (or *What The Fuck Public License*)](https://es.wikipedia.org/wiki/WTFPL), which means **do what you want**.
## Issues
Please, address your issues [here](https://github.com/allnulled/hook-by-priority/issues).