Hooki

⚓️ An advanced Javascript hook system.
Installation
npm install hooki --save
Usage
import Hooki from 'hooki';
import { before, after } from './hooks';
class Product {
constructor(name, price, stock) {
this.name = name;
this.price = price;
this.stock = stock;
}
buy(quantity) {
console.log(`${this.name} x${quantity}`);
}
}
export new Hooki(ProductClass, before, after);
export const before = {
buy: [
function verifyStock(context) {
if (context.params.quantity > context.self.quantity) {
throw Error('Amount exceeds stock!');
}
return context;
}
]
};
export const after = {
buy: [
function removeFromStock(context) {
context.self.quantity -= context.params.quantity;
return context
}
]
};
import Product from './product.class.js';
const bag = new Product('bag', 10.43, 5);
bag.buy(4);
console.log(bag.stock);
bag.buy(2);
Roadmap
Tests
target types
action types
hook types
features
plugins