hookx

2.0.0 • Public • Published

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.

Package Sidebar

Install

npm i hookx

Weekly Downloads

4

Version

2.0.0

License

MIT

Unpacked Size

5.78 kB

Total Files

4

Last publish

Collaborators

  • jacksontian