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 🙏

© 2025 – Pkg Stats / Ryan Hefner

decorator-inspectors

v0.2.0

Published

Inspect data about decorated objects

Downloads

31

Readme

The decorator-inspectors package contain TypeScript decorators which let you print out detailed information about decorated objects. These decorators were developed in conjunction with writing an article series, Deep introduction to TypeScript decorators, metadata, and runtime data validation with decorators, which is a deep look into using and implementing TypeScript decorators.

The primary use for this package is when developing decorators. The inspectors help you to see the data you can get ahold of via the decorators.

INSTALLATION

To install this package: npm install decorator-inspectors --save (or the yarn equivalent)

USAGE

To use this package in your application:

import * as inspectors from 'decorator-inspectors';

You then use the decorators as @inspectors.DecoratorName.

To see examples visit the repository at https://github.com/robogeek/typescript-decorators-examples

API: Functions

The decorator-inspectors package provides five functions which can be used inside a hybrid decorator to determine the context it is being used in. It is observed that based on the types for the decorator parameters, one can determine the sort of object to which the decorator has been attached. This makes it possible to create a hybrid decorator which can be attached to any object.

The method signature for the hybrid decorator function is:

(target: Object,
    propertyKey?: string | symbol,
    descriptor?: number | PropertyDescriptor)

This signature handles every variant of parameters for decorator functions.

There is an example of using these functions in the repository, in the simple/lib/hybrid directory.

isClassDecorator(target: Object,
    propertyKey?: string | symbol,
    descriptor?: number | PropertyDescriptor);

Type Guard that detects whether the decorator is attached to a class definition.

isPropertyDecorator(target: Object,
    propertyKey?: string | symbol,
    descriptor?: number | PropertyDescriptor);

Type Guard that detects whether the decorator is attached to a property definition.

isParameterDecorator(target: Object,
    propertyKey?: string | symbol,
    descriptor?: number | PropertyDescriptor);

Type Guard that detects whether the decorator is attached to a method parameter.

isMethodDecorator(target: Object,
    propertyKey?: string | symbol,
    descriptor?: number | PropertyDescriptor);

Type Guard that detects whether the decorator is attached to a method definition.

isAccessorDecorator(target: Object,
    propertyKey?: string | symbol,
    descriptor?: number | PropertyDescriptor);

Type Guard that detects whether the decorator is attached to a accessor definition.

API: Decorators

@inspectors.LogClassInspector
class ClassName { .. }

This prints detailed information about the class, at class construction time. It is not printed when class instances are created.

const data = @inspectors.ClassInspector(ClassName)

This function can be called in regular code to gather the same data shown using the @LogClassInspector.

class ClassName {
    @inspectors.LogAccessorInspector
    get accessor() { .. }
    set accessor(val: type) { .. }
}

This prints data about the accessor, including its PropertyDescriptor object.

const data = @inspectors.AccessorInspector(ClassName)

This function can be called in regular code to gather the same data shown using the @LogAccessorInspector.

class ClassName {
    @inspectors.AccessorSpy<type>()
    get accessor() { .. }
    set accessor(val: type) { .. }
}

This prints data for every invocation of get or set on the accessor. The type passed through the Generic must match the type for the accessor.

class ClassName {
    @inspectors.LogPropertyInspector
    propertyName: type;
}

This prints data about the property. There is no PropertyDescriptor available through this decorator.

const data = @inspectors.PropertyInspector(ClassName)

This function can be called in regular code to gather the same data shown using the @LogPropertyInspector.

class ClassName {
    @inspectors.LogMethodInspector
    methodName() { ... }
}

This prints data about the method, including its PropertyDescriptor object.

const data = @inspectors.MethodInspector(ClassName)

This function can be called in regular code to gather the same data shown using the @LogMethodInspector.

class ClassName {
    methodName(
        @inspectors.LogParameterInspector
        param1: type,
        @inspectors.LogParameterInspector
        param2: type) { ... }
}

This prints data about the parameter.

const data = @inspectors.ParameterInspector(ClassName)

This function can be called in regular code to gather the same data shown using the @LogParameterInspector.