# generate-runtypes

> A code generator tool for Runtypes types

Latest version **3.1.1** (published 2022-11-27) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install generate-runtypes
pnpm add generate-runtypes
yarn add generate-runtypes
bun add generate-runtypes
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2022-11-27 |
| First published | 2021-03-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 4 |
| Unpacked size | 148 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Maintainers | cobraz |

## Links

- npm: https://www.npmjs.com/package/generate-runtypes
- Repository: https://github.com/cobraz/generate-runtypes
- npm.io page: https://npm.io/package/generate-runtypes

## Dependencies (4)

- [jsesc](https://npm.io/package/jsesc.md) ^3.0.2
- [prettier](https://npm.io/package/prettier.md) ^2.3.1
- [runtypes](https://npm.io/package/runtypes.md) ^6.2.1
- [typescript](https://npm.io/package/typescript.md) ~4.3.2

## Recent versions

- 3.1.1 (latest) — 2022-11-27
- 2.0.0-alpha.4 (alpha) — 2021-04-10
- 3.1.0 — 2021-07-30
- 3.0.0 — 2021-06-10
- 2.1.0 — 2021-04-28
- 2.0.1 — 2021-04-23
- 2.0.0 — 2021-04-16
- 2.0.0-alpha.3 — 2021-03-28
- 2.0.0-alpha.2 — 2021-03-27
- 2.0.0-alpha.1 — 2021-03-25
- 1.1.1 — 2021-03-21
- 1.1.0 — 2021-03-21
- 1.0.0 — 2021-03-21

## README

<div align="center">
  <img width="520" src="./.github/header.svg" alt="Generate Runtypes types">
  
  A code generator for Runtypes types

[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![NPM version](https://img.shields.io/npm/v/generate-runtypes.svg)](https://www.npmjs.com/package/generate-runtypes)
[![codecov](https://codecov.io/gh/cobraz/generate-runtypes/branch/main/graph/badge.svg)](https://codecov.io/gh/cobraz/generate-runtypes)

</div>

This library aims to provide an intuitive and easy way to generate
[Runtypes][runtypes] types. This package aims to be a great utility for a
conversion package (e.g. JSON Schema to Runtypes).

We are thankful for all help with adding new functionality, fixing issues, or
improve the package. Feel free to open issues and pull requests ❤️

## Documentation

Apart from this README, you can find details and examples of using the SDK in
the following places:

- [API Documentation][docs]

## Example

```typescript
import { generateRuntypes } from 'generate-runtypes';

const sourceCode = generateRuntypes([
  {
    name: 'Comment',
    type: {
      kind: 'record',
      fields: [
        { name: 'author', type: { kind: 'string' } },
        { name: 'body', type: { kind: 'string' } },
        { name: 'timestamp', type: { kind: 'number' } },
      ],
    },
  },
  {
    name: 'Post',
    export: true,
    type: {
      kind: 'record',
      fields: [
        { name: 'title', type: { kind: 'string' } },
        { name: 'body', type: { kind: 'string' } },
        { name: 'author', type: { kind: 'string' } },
        {
          name: 'comments',
          type: { kind: 'array', type: { kind: 'named', name: 'Comment' } },
        },
      ],
    },
  },
]);
```

The generated code looks like this after formatting:

```typescript
import * as rt from 'runtypes';

const Comment = rt.Record({
  author: rt.String,
  body: rt.String,
  timestamp: rt.Number,
});

export const Post = rt.Record({
  title: rt.String,
  body: rt.String,
  author: rt.String,
  comments: rt.Array(Comment),
});
```

[runtypes]: https://github.com/pelotom/runtypes
[docs]: ./docs

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