quben
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

Quben

More control on functions
A JavaScript and TypeScript library for measuring and scaling to functions.


Installation

Use the package manager npm to install quben.

npm install quben

Getting Started

import quben, { rules } from 'quben';

quben.addRule(rules.logger());

const factorial = quben(function recursive(num: number): number {
  if (num <= 1) return 1;
  return num * recursive(--num);
});

console.log(factorial(5));
// prints:
// recursive( 5 ) executed in 0.1371ms
// 120

You can add your custom rules

import quben from 'quben';

// This rule will be executed before function execution
quben.addBeforeRule((ctx, next) => {
  console.log('Before Function Execution');
  next();
});

// This rule will be executed after function execution
quben.addAfterRule((ctx, next) => {
  console.log('After Function Execution');
  next();
});

// This rule will be executed before and after function execution
quben.addRule((ctx, next) => {
  if (ctx.status == 'start') {
    console.log('before');
  } else if (ctx.status == 'end') {
    console.log('after');
  }
});

const f = quben(() => {
  console.log('Function block');
});

f();
// Before Function Execution
// before
// Function block
//After Function Execution
// after

For more example, you can check out the examples folder

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i quben

Weekly Downloads

1

Version

0.3.0

License

ISC

Unpacked Size

33 kB

Total Files

48

Last publish

Collaborators

  • ahmetcanozcan