2.0.0 • Published 3 years ago
hookx v2.0.0
hookx
Hook(x) with Power.
Installation
Install it with npm first.
$ npm install hookx --saveUsage
Require it first.
const { hook, before, after } = require('hookx');You should have an async function defined like this:
var query = async function (sql) {
// TODO
};Hook it with before and after business logic.
var query = hook(query, async function (sql) {
console.time(sql);
}, async function (sql) {
console.timeEnd(sql);
});
await query(sql); // call the hooked async function like originHook with before business logic.
var counter = 0;
var query = before(query, async function (sql) {
counter++;
});
await query(sql);Hook with after business logic.
var counter = 0;
var query = after(query, async function (sql) {
counter--;
});
await query(sql);License
The MIT license.