1.2.1 • Published 5 years ago

@jframe/reflection v1.2.1

Weekly downloads
-
License
-
Repository
-
Last release
5 years ago

The reflection api provides a set of methods to get meta information about all classes and their properties and methods. It uses a custom transformer which adds those information at compile time to a static __meta__ property. Due to the simplicity of the transformer, declaration merging is currently not support.

Installation

npm install -S @jframe/reflection

Using the Transformer

The custom transformer is necessary to add the additional TypeScript information like types, interfaces and visibilities to the plain JavaScript object. If you do not want to use the full reflection api, you can access the generated __meta__ property to get all information manually.

Webpack

const Transformer = require('@jframe/reflection').Transformer;

module.exports = {
    module: {
            rules: [
                {
                    test: /\.ts$/,
                    loader: 'ts-loader',
                    options: {
                        getCustomTransformers: function () {
                            return {
                                before: [Transformer]
                            };
                        }
                    }
                }
            ]
        },
}

Examples

Get class information from constructor

import {Reflection} from '@jframe/reflection';

class A {
    
}

// Constructor
const meta = Reflection.getClassMeta(A);

// OR 

// Instance
const a = new A();
const meta = Reflection.getClassMeta(a);


console.log(meta.getName()); // => A
1.2.1

5 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago