npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deborator

v1.0.20

Published

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

Downloads

22

Readme

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)

| option | description | example | |---|---|---| |log| A 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);} }) | |showReturnValues| Set this to true, if you also want to see return values in the log.| @deborator({showReturnValues: true }) | |showProperties| Set this to true, to also log get/set properties. This can be noisy!. | @deborator({showProperties: true }) | |decoratePrototype| Set 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

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