@plumjs/reflect
TypeScript reflection and type inspector library
Last updated 2 years ago by ktutnik .
MIT · Bugs · Original npm · Tarball · package.json
$ cnpm install @plumjs/reflect 
SYNC missed versions from official npm registry.

tinspector

TypeScript type inspector library

Build Status Coverage Status

Motivation

tinspector is a type inspector library, it can parse all exported functions and classes inside a module into Abstract Syntax Tree.

How to Use It

Example you have a file with classes like below:

//filename: src/mock.ts
export function myFun(firstPar: string, secondPar: string) { }
export function myOtherFun() { }

export class MyClass {
    myMethod(firstPar: string, secondPar: string) { }
    myOtherMethod(){}
}

You can retrieve AST from above module using:

//filename: src/index.ts
import {reflect} from "./reflect"

const result = reflect("./mock")

The result will be like below:

{
    type: 'Object',
    name: 'module',
    members: [{
        type: 'Function',
        name: 'myFun',
        parameters:
            [{ type: 'Parameter', name: 'firstPar' },
            { type: 'Parameter', name: 'secondPar' }]
    },
    { type: 'Function', name: 'myOtherFun', parameters: [] },
    {
        type: 'Class',
        name: 'MyClass',
        methods:
            [{
                type: 'Function',
                name: 'myMethod',
                parameters:
                    [{ type: 'Parameter', name: 'firstPar' },
                    { type: 'Parameter', name: 'secondPar' }]
            },
            { type: 'Function', name: 'myOtherMethod', parameters: [] }]
    }]
}

The parameter of the reflect method is the path of the module that will be parsed, it is respect the JavaScript import naming such as absolute "./module", "/path/of/module", relative "../../module" or global "module"

tinspector can handle TypeScript style decorator properly

import {decorateClass, decorateMethod, decorateParameter} from "./reflect"

@decorateClass({ url: "/animal" })
export class AnimalClass {
    @decorateMethod({ url: "/get" })
    myMethod(@decorateParameter({ required: true }) firstPar: string, @decorateParameter({ required: false }) secondPar: string) { }
    myOtherMethod(@decorateParameter({ required: true }) par1: string, par2: string) { }
}

The reflection result is like below:

{
    type: 'Class',
    name: 'AnimalClass',
    methods:
        [{
            type: 'Function',
            name: 'myMethod',
            parameters:
                [{
                    type: 'Parameter',
                    name: 'firstPar',
                    decorators:
                        [{ required: true }]
                },
                {
                    type: 'Parameter',
                    name: 'secondPar',
                    decorators:
                        [{ required: false }]
                }],
            decorators:
                [{ url: '/get' }]
        },
        {
            type: 'Function',
            name: 'myOtherMethod',
            parameters:
                [{
                    type: 'Parameter',
                    name: 'par1',
                    decorators:
                        [{ required: true }]
                },
                { type: 'Parameter', name: 'par2', decorators: [] }],
            decorators: []
        }],
    decorators:
        [{ url: '/animal' }]
}

Current Tags

  • 1.4.0-alpha.1bcecb6e                                ...           canary (2 years ago)
  • 1.4.1                                ...           latest (2 years ago)

28 Versions

  • 1.4.1                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.4.0-alpha.1bcecb6e                                ...           2 years ago
  • 1.4.0-alpha.9dad2c63                                ...           2 years ago
  • 1.4.0-alpha.93a6edbd                                ...           2 years ago
  • 1.4.0-alpha.56800706                                ...           2 years ago
  • 1.4.0-alpha.917ab04a                                ...           2 years ago
  • 1.4.0-alpha.7cef1761                                ...           2 years ago
  • 1.4.0-alpha.e8eb024f                                ...           2 years ago
  • 1.4.0-alpha.a1d8df90                                ...           2 years ago
  • 1.4.0-alpha.5c21ba07                                ...           2 years ago
  • 1.4.0-alpha.9f9383f0                                ...           2 years ago
  • 1.4.0-alpha.3f26c2c9                                ...           2 years ago
  • 1.4.0-alpha.3202365f                                ...           2 years ago
  • 1.4.0-alpha.fecd14a5                                ...           2 years ago
  • 1.4.0-alpha.d1c9bcf4                                ...           2 years ago
  • 1.4.0-alpha.82f2f2c1                                ...           2 years ago
  • 1.4.0-alpha.292e1ec3                                ...           2 years ago
  • 1.4.0-alpha.7020144f                                ...           2 years ago
  • 1.4.0-alpha.9aaa0a15                                ...           2 years ago
  • 1.4.0-alpha.dbe9c682                                ...           2 years ago
  • 1.4.0-alpha.b45edf92                                ...           2 years ago
  • 1.4.0-alpha.a709e511                                ...           2 years ago
  • 1.4.0-alpha.10b371a0                                ...           2 years ago
  • 1.4.0-alpha.e8d121b4                                ...           2 years ago
  • 1.4.0-alpha.56f2ec99                                ...           2 years ago
  • 1.4.0-alpha.a486b022                                ...           2 years ago
  • 1.4.0-alpha.0614ea60                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (2)
Dev Dependencies (3)

Copyright 2014 - 2016 © taobao.org |