1.0.20 • Published 7 years ago

deborator v1.0.20

Weekly downloads
-
License
MIT
Repository
bitbucket
Last release
7 years ago

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

setup

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

CD demo-app
install

run the app

run

relevant links

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

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago