debug-it
Debug-it is a simple library for logging input and output parameters of a decorated class.
It depends on debug.
This library is very similar to decorate-it but doesn't perform any validation and it can be used in the browser.
Installation
npm i --save debug-it
Sample usage
file services/CalcService.js
import decorate from 'debug-it';
function add(a, b) {
return a + b;
}
const CalcService = {
add,
};
decorate(CalcService, 'app:CalcService');
export default CalcService;
use service
import CalcService from './services/CalcService';
CalcService.add(1, 3);
See example under example/example1.js
. Run it using npm run example1
.
Async sample usage
file services/UserService.js
import decorate from '../src/decorator';
async function getUser(id) {
return await new Promise((resolve) => {
setTimeout(() => resolve({ id, username: 'john' }), 100);
});
}
getUser.params = ['id'];
const UserService = {
getUser,
};
decorate(UserService, 'app:UserService');
export default UserService;
use service
import UserService from './services/UserService';
await UserService.getUser(1);
await UserService.getUser(222);
See example under example/example2.js
. Run it using npm run example2
.
NOTE parameter names cannot be automatically retrieved from async
methods.
You must define them explicitly in params
property like this getUser.params = ['id'];
MIT License
Copyright (c) 2017 Łukasz Sentkiewicz