3.1.1 • Published 1 year ago

generate-runtypes v3.1.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

lifecycle NPM version codecov

This library aims to provide an intuitive and easy way to generate 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:

Example

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:

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),
});
3.1.1

1 year ago

3.1.0

3 years ago

3.0.0

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.0.0-alpha.4

3 years ago

2.0.0-alpha.3

3 years ago

2.0.0-alpha.2

3 years ago

2.0.0-alpha.1

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago