Socket
Socket
Sign inDemoInstall

deborator

Package Overview
Dependencies
0
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    deborator

a TypeScript decorator, to add console.log() to all methods and properties of a class.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

deborator readme

deborator (DEBug decORATOR) is a TypeScript decorator, to add console.log() to all methods and properties of a TypeScript class.

If you find yourself writing a lot of console.log() entries during debugging, then deborator may save you time!

This can be especially useful when regular debugging via breakpoints is not really practical

examples:

  • developing drag'n'drop features in a browser since browsers like Chrome tend not to exit the 'dragging' state, if they hit a breakpoint

  • developing real-time sites, when debugging via breakpoints is not practical

note: deborator should NOT be deployed to Production (as there may be performance/security impact because of the logging)

usage

Install deborator via yarn:

yarn add deborator

Import deborator into the TypeScript file, and apply the decorator to the class you want to debug:

import { deborator } from "deborator";

@deborator({})
class MyCalculator {
    constructor(private value: number) {}

    add(value: number) {
        this.value += value;
    }
}

// using your class:
const calc = new MyCalculator(1);
calc.add(5);

Now if you hit F12, you will see console log entries for your class, as it is being used:

>DB> new MyCalculator( 1 )
>DB> MyCalculator.add( 5 )
>DB>   MyCalculator.add( 5 ) => ( {"value":6} )

advanced usage

deborator options: (all are optional)

optiondescriptionexample
logA function that accepts a string (a message generated by deborator). This overrides the default behaviour (logging to console).@deborator({log: (text: string) => {console.info(text);} })
showReturnValuesSet this to true, if you also want to see return values in the log.@deborator({showReturnValues: true })
showPropertiesSet this to true, to also log get/set properties. This can be noisy!.@deborator({showProperties: true })
decoratePrototypeSet this to true, to also log inherited methods (does not work with React components).@deborator({decoratePrototype: true })

known issues

  • import into react project - right now need to do this (import source rather than compiled js): import { deborator } from "deborator/src/deborator";
  • dist folder (npm package): the index.js does not work from one unit test project workaround: copy the source file 'deborator.ts' into the project

running the demo app

To see deborator in action, you can get the source code and run the demo app.

  • get the source code:
git clone https://bitbucket.org/str/deborator

dependencies

  • node [v6.10.3 is OK]
  • yarn [0.27.5 is OK]

setup

On a Windows box (Unix should be similar ...)

CD demo-app
install

run the app

run

sourcecode in git: https://bitbucket.org/str/deborator

npm package: https://www.npmjs.com/package/deborator

TypeScript decorators: https://www.typescriptlang.org/docs/handbook/decorators.html

https://gist.github.com/remojansen/16c661a7afd68e22ac6e

demo app

The demo app was based on a really nice react-typescript starter kit by Jack Franklin

https://github.com/javascript-playground/react-typescript-jest-demo

https://javascriptplayground.com/blog/2017/04/react-typescript/

license

MIT

Keywords

FAQs

Last updated on 25 Aug 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc