Decorators Factory
Javascript package that makes the use of decorators a breath ^_^
It runs on node.js and doesn't require any transpiler such as Babel or Typescript ! It supports sync/async (factory)functions/methods.
Supported decorators:
- debug: logs inputs and outputs of your functions
- time: computes the running time with precision
- try_catch: throws & logs any error that occured
- retry: retries a function if it fails
There's a lot of room for improvement so any help: question/issue/comment/documentation(none of the decorators are documented at the moment)/PR is welcome.
The module does trick nonetheless. So enjoy :) !!
Install · Usage · Contributing
Functions · Factory functions · Methods
Decoration:Install
Install the decorators factory in your project as an NPM dependency :
npm install decorators-factory
You can also clone it into your project directory from decorators-factory GitHub repository:
git clone https://github.com/pasdechancee/decorators-factory.git
Usage
Setup
Quickly get up and started :
const Decorator = ;const decorate_functions decorate_methods = ;
You can also custom your decorators with your own config if you want. The configuration will get merged with the default one.
- Change the log levels of the decorators.
- Enable/Disable decorators without changing your source code ! For instance if you're in production and you don't want to waste ressources on debugging everything, you can do this:
const Decorator = ; const custom_config = debug: enabled: processenvNODE_ENV === "PRODUCTION" ? false : true start_log_level: "debug" // you can change these log levels. try_log_level: "debug" catch_log_level: "error" ; const decorate_functions decorate_methods = ;
Decorate simple functions
{ // do awesome stuff...} { // do awesome stuff...} const decorated_functions = ; const sync_simple_function: decorated_simple_function async_simple_function: decorated_async_simple_function } = decorated_functions; // run your decorated functions.;;
Decorate functions from factory
{ return ; { // do awesome stuff... }} const nested_simple_function = ; // run your decorated functions.;
Decorate methods
async { // do awesome stuff... } ; const my_class_instance = ;my_class_instance;
© MIT license Contact: pasdechancee.keyser-soze@protonmail.com