Code Monkey home page Code Monkey logo

metadatatransformer's Introduction

MetaDataTransformer

A typescript transpiler wrapper with reflection capabilities

Build Status Build Status Dependabot Status Codacy Badge Coverage Status

Important notice

This project is not stable and there are no plans to support the same features as the typescript cli. Maybe when the typescript team has decided on if, how and when they will support easy transformers pluggability I will tear the transformer out of this project and provide it standalone.

Prerequisites

  • node js

How to run the sample application

  • Run npm run test to restore, build and test all files.
  • Open the path "MetaDataTransformer/MetaDataTransformerUsage" in a command line terminal
  • Run npm run pack to build a js bundle for the test.html file
  • Open "MetaDataTransformer/MetaDataTransformerUsage/test.html" in a browser and take a look at the console output

CLI

usage: tsca [-h] [-v] <command> ...

Typescript transpiler with reflection capabilities.

Positional arguments:
  <command>
    build        Transpiles the given typescript files

Optional arguments:
  -h, --help     Show this help message and exit.
  -v, --verbose  Show extra logging detail
  
usage: tsca build [-h] [--env ENV] [--emit-decorator-metadata]
                  [--experimental-decorators] [--inline-source-map]
                  [--include INCLUDE] [--out-dir OUTDIR] [--out-file OUTFILE]
                  [--root-dir ROOTDIR]
                  [--module {None,CommonJS,AMD,UMD,System,ES2015,ESNext}]
                  [--module-resolution {Classic,NodeJs}]
                  [--target {ES3,ES5,ES2015,ES2016,ES2017,ES2018,ESNext,JSON,Latest}]
                  [--source-map] [--source-root SOURCEROOT]
                  [--map-root MAPROOT] [--types TYPES]
                  [--type-roots TYPEROOTS]

Reflection API

export interface ITypeDeclaration {
    properties: {
        [id: string]: IPropertyDeclaration;
    };
}
export interface IPropertyDeclaration {
    isOptional: boolean;
    isStatic: boolean;
    accessModifier: AccessModifier;
}
export declare enum AccessModifier {
    Public = 0,
    Protected = 1,
    Private = 2
}
export interface IType<T> extends Function {
    new (...args: (object | string | number | boolean)[]): T;
}
export declare const reflection: {
    canCast: <T>(obj: object, type: IType<T>) => boolean;
    getType: <T>(type: IType<T>) => ITypeDeclaration;
    isType: <T>(type: IType<T>) => boolean;
};

Reflection API usage

import { reflection } from 'metadatatransformer';

class Test {
  ...
}

if(reflection.isType(Test)) {
  reflection.getType(Test);
  reflection.canCast({ }, Test);
}

metadatatransformer's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar ntfrex avatar

Watchers

 avatar

Forkers

codacy-badger

metadatatransformer's Issues

Fix jest types import

`import '@types/jest' needed in tests and replace needed after transpile.
How can this be solved cleaner?

Improve test coverage report

  • multiple coverage reports without jest projects flag? (most likely flag is needed to resolve base path in coveralls source viewer)
  • include untestet files
  • main.ts wron test coverage?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.