Skip to content

vvakame/typescript-formatter

Repository files navigation

TypeScript Formatter (tsfmt)

npm Build Status Dependency Status npm GitHub stars

A TypeScript code formatter powered by TypeScript Compiler Service.

$ tsfmt --help
  Usage: tsfmt [options] [--] [files...]

  Options:

    -r, --replace         replace .ts file
    --verify              checking file format
    --baseDir <path>      config file lookup from <path>
    --stdin               get formatting content from stdin
    --no-tsconfig         don't read a tsconfig.json
    --no-tslint           don't read a tslint.json
    --no-editorconfig     don't read a .editorconfig
    --no-vscode           don't read a .vscode/settings.json
    --no-tsfmt            don't read a tsfmt.json
    --useTsconfig <path>  using specified config file instead of tsconfig.json
    --useTslint <path>    using specified config file instead of tslint.json
    --useTsfmt <path>     using specified config file instead of tsfmt.json
    --verbose             makes output more verbose

Installation

npm install -g typescript-formatter

Usage

Format or verify specific TypeScript files

$ cat sample.ts
class Sample {hello(word="world"){return "Hello, "+word;}}
new Sample().hello("TypeScript");
# basic. read file, output to stdout.
$ tsfmt sample.ts
class Sample { hello(word = "world") { return "Hello, " + word; } }
new Sample().hello("TypeScript");
# from stdin. read from stdin, output to stdout.
$ cat sample.ts | tsfmt --stdin
class Sample { hello(word = "world") {