0.0.7 • Published 6 years ago

ts-extract v0.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Extract JSON Schema from TypeScript

Generate a json schema from a TypeScript interface.

Supported features:

  • Literals ([], "foo", 123,...)
  • Keywords (number, string, boolean,...)
  • Union Types
  • Interfaces
  • Type Alias
  • Mapped Types (Record, Partial, Readonly, Pick)
  • extends
  • enums

Installation

# npm
npm install --save ts-extract

# yarn
yarn add ts-extract

Usage

ts-extract can be both used as a standard node module or as a cli binary.

Node

const path = require("path");
const { createSchema } = require("ts-extract");

const file = path.resolve("./path/to/my/source.ts");
const type = "Foo" // Type to extract
const schema = createSchema(file, type);
// Logs:
// {
//   "$schema": "http://json-schema.org/draft-06/schema#",
//   "definitions": { ... },
//   "type": "object",
//   "properties": { ... },
// }

CLI

$ ts-extract --help

ts-extract [options] -t MyType my/source.ts

Options:
  -t, --type     Name of type            [required]
  -c, --config   path to tsconfig.json   [string]
  -h, --help     Show help               [boolean]
  -v, --version  Show version            [boolean]

Example:
  ts-extract -t MyType my/source.ts

License

MIT, see License file.

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago