SkillAgentSearch skills...

Hooki

⚓️ An advanced hook system for Javascript classes, objects and function

Install / Use

/learn @hookijs/Hooki
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Hooki

<a align="center" href="https://github.com/russiann/hooki"><img width="100%" src="https://cdn.pbrd.co/images/GECTIQj.png" alt="Hooki Logo"></a>

⚓️ An advanced Javascript hook system.

Installation

npm install hooki --save

Usage

// product.class.js

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);

// hooks.js

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
    }
  ]
};

// app.js

import Product from './product.class.js';

const bag = new Product('bag', 10.43, 5);

bag.buy(4); 
// -> bag x4
console.log(bag.stock); 
// -> 1
bag.buy(2); 
// -> Error: Amount exceeds stock!

Roadmap

Tests

  • [x] tests

target types

  • [x] object
  • [x] class
  • [ ] function

action types

  • [x] function
  • [x] get
  • [x] set
  • [x] getter
  • [x] setter
  • [x] construct

hook types

  • [x] after
  • [x] before
  • [x] errors

features

  • [ ] plugin system
  • [ ] async hooks (promises, callback)
  • [ ] extended hooks methods (target.after([hook]), target.before([hooks]))

plugins

  • [ ] hooki-events
  • [ ] hooki-validator
  • [ ] hooki-errors
  • [ ] hooki-lifecycle
  • [ ] hooki-modules
View on GitHub
GitHub Stars5
CategoryProduct
Updated4y ago
Forks1

Languages

JavaScript

Security Score

75/100

Audited on May 12, 2021

No findings