JacksonTian / hookx

Hook(x) with Power.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hookx

Hook(x) with Power.

NPM version npm download build status codecov

Installation

Install it with npm first.

$ npm install hookx --save

Usage

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 origin

Hook 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.

About

Hook(x) with Power.

License:MIT License


Languages

Language:JavaScript 100.0%