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

@zuu/mirror

v4.0.2

Published

Zuu's Reflection API

Downloads

41

Readme

@zuu/mirror

Gitter Version Downloads/week License

What is Mirror?

Mirror is a very powerfull reflection api created for typescript, mainly used with the zuu framework (for dependency injection, assertion and other cool stuff).

Want to contribute?

Here's how!

Usage

The basic principle is easy. Decorations are attached to classes, properties, methods and method parameters and can be reflected after by a very powerfull reflection engine (that also provides aditional information about the types, names, positions, etc).

The first step is to create a new decoration:

// just extend the IDecoration interface
interface GParameters extends IDecoration {
    x: number;
    y?: string;
};

After that we can define our decorator logic:

// just extend the AbstractDecorator<T> and provide a IDecoration type
class GDecorator extends AbstractDecorator<GParameters> {
    constructor() {
        // provide information about the MirrorType [CLASS, PROPERTY, METHOD, PARAMETER] and a namespace (must be unique)
        super(MirrorType.CLASS, "demos.class.g");
    };

    public annotate(instance: GParameters, target: any, key?: string | symbol, index?: number) {
        // here you can process your decoration placement
        console.log(instance);
    };
};

Now we can ask mirror to build our decorator: (don't forget to say please)

// Hey Mirror, sorry for bothering you, but can you please make a new decorator?
//  It will be a ClassDecorator and will bind to GParameters decoration :) Thanks
let G = Mirror.decorator<GParameters, ClassDecorator>(new GDecorator);

That's all :) Now you can use it on any class like so:

@G({x: 3, y: "abcd"})
class Dummy { };

It's a decorator factory actually... but you can convert it to a decorator just by calling it with the decoration:

let g = G({x: 0});

@g
class Dummy2 {};

You can now reflect on your class or class instances (also on specific methods and properties):

let reflection: ReflectedClass = Mirror.reflect<ReflectedClass>(Dummy);
console.log(reflection);

let instance = new Dummy2()
let instanceReflection: ReflectedClass = Mirror.reflectInstance<ReflectedClass>(instance);
console.log(instanceReflection);

Objects

| Object | Reflection | Decorator | |:------ |:----------:| ---------:| | type | ReflectedType | - | | class | ReflectedClass | ClassDecorator | | property | ReflectedProperty | PropertyDecorator | | method | ReflectedMethod | MethodDecorator | | parameter | ReflectedParameter | ParamterDecorator |