# ts-extract

> Generate json schema from TypeScript interfaces

Latest version **0.0.7** (published 2018-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-extract
pnpm add ts-extract
yarn add ts-extract
bun add ts-extract
```

Provides the command `ts-extract`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2018-01-04 |
| First published | 2017-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Marvin Hagemeister |
| Maintainers | marvinhagemeister |

## Links

- npm: https://www.npmjs.com/package/ts-extract
- Repository: https://github.com/marvinhagemeister/ts-json-schema
- Homepage: https://github.com/marvinhagemeister/ts-json-schema#readme
- Issues: https://github.com/marvinhagemeister/ts-json-schema/issues
- npm.io page: https://npm.io/package/ts-extract

## Dependencies (5)

- [mri](https://npm.io/package/mri.md) ^1.1.0
- [nicer-fs](https://npm.io/package/nicer-fs.md) ^1.1.1
- [deepmerge](https://npm.io/package/deepmerge.md) ^2.0.1
- [typescript](https://npm.io/package/typescript.md) ^2.6.1
- [@types/node](https://npm.io/package/@types/node.md) ^8.0.2

## Recent versions

- 0.0.7 (latest) — 2018-01-04
- 0.0.6 — 2018-01-04
- 0.0.5 — 2017-11-05
- 0.0.4 — 2017-11-05
- 0.0.3 — 2017-11-05
- 0.0.2 — 2017-11-05
- 0.0.1 — 2017-11-05

## README

# Extract JSON Schema from TypeScript

Generate a [json schema](http://json-schema.org/) 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

```bash
# 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

```js
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

```bash
$ 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](LICENSE.md).

---
_Source: https://npm.io/package/ts-extract · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
