Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

debug-it

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debug-it

Logging and validations decorators for nodejs services

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 03 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc