JSPM

  • Created
  • Published
  • Downloads 3193
  • Score
    100M100P100Q113711F
  • License MIT

Just compile TypeScript code string to JS. That's all!

Package Exports

  • typescript-simple
  • typescript-simple/package.json

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (typescript-simple) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

typescript-simple NPM version build status Dependency Status

Just compile TypeScript code string to JavaScript. That's all!

Description

TypeScirpt 1.4 has official compiler API, but it isn't easy to compile tiny TypeScript code string. typescript-simple provides just one method that accepts TypeScript code string and returns JavaScript code.

Install

$ npm install typescript-simple

Usage

Simple usage.

var tss = require('typescript-simple');
var js = tss.compile('var n: number = 1;');
console.log(js); // 'var n = 1;'

Specify compiler options.

var js = tss.compile('var n: number = 1;', {noImplicitAny: true});

If the code causes errors, typescript-simple throws errors.

try {
    var js = tss.compile('var n: number = "str";');
} catch (e) {
    console.error(e); // Error: L1: Type 'string' is not assignable to type 'number'.
}

Limitaions

typescript-simple cannot compile multiple source files.

API

compile(code: string, options?: typescript.CompilerOptions): string

  • code: TypeScript input source code string
  • options: TypeScript compiler options
  • return : JavaScript output code string

Following is full compiler options, but some are ignored in the current implementation.

interface CompilerOptions {
    allowNonTsExtensions?: boolean;
    charset?: string;
    codepage?: number;
    declaration?: boolean;
    diagnostics?: boolean;
    emitBOM?: boolean;
    help?: boolean;
    locale?: string;
    mapRoot?: string;
    module?: ModuleKind;
    noEmitOnError?: boolean;
    noErrorTruncation?: boolean;
    noImplicitAny?: boolean;
    noLib?: boolean;
    noLibCheck?: boolean;
    noResolve?: boolean;
    out?: string;
    outDir?: string;
    preserveConstEnums?: boolean;
    removeComments?: boolean;
    sourceMap?: boolean;
    sourceRoot?: string;
    suppressImplicitAnyIndexErrors?: boolean;
    target?: ScriptTarget;
    version?: boolean;
    watch?: boolean;
    [option: string]: string | number | boolean;
}

Note

This implementation is derived from code in an official wiki page.

License

MIT License: Teppei Sato <teppeis@gmail.com>