Code Monkey home page Code Monkey logo

debug-it's Introduction

debug-it

Build Status codecov

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

// create your service
const CalcService = {
  add,
};

// decorate it, it will mutate CalcService
decorate(CalcService, 'app:CalcService');

export default CalcService;

use service

import CalcService from './services/CalcService';


CalcService.add(1, 3); // returns 4

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


// create your service
const UserService = {
  getUser,
};

// decorate it, it will mutate UserService
decorate(UserService, 'app:UserService');

export default UserService;

use service

import UserService from './services/UserService';


await UserService.getUser(1); // returns { id: 1, username: 'john' }
await UserService.getUser(222); // returns { id: 222, username: 'john' }

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

debug-it's People

Contributors

lstkz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.