1.3.11 • Published 5 years ago

igata v1.3.11

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

Igata

npm version GitHub license CircleCI

Convert a JSON Schema to a Flow type definition.

Installation

npm install --save igata

Usage

import {convert} from 'igata';

convert({$id: 'String', type: 'string'});
// => export type String = string;

convert({$id: 'Enum', enum: [1, 2]});
// => export type Enum = 1 | 2;

convert({$id: 'Object', type: 'object', properties: {foo: {type: 'string'}}});
// => export type Object = {\n  foo?: string\n};

convert({$id: 'Array', type: 'array', items: {type: 'string'}});
// => export type Array = string[];

convert({$id: 'Tuple', type: 'array', items: [{type: 'string'}, {type: 'number'}]});
// => export type Tuple = [string, number];

convert({$id: 'Union', type: ['string', 'number']});
// => export type Union = string | number;

convert({$id: 'ComplexUnion', anyOf: [{type: 'number'}, {type: 'object', properties: {foo: {type: 'string'}}}]});
// => export type ComplexUnion = number | {\n  foo?: string\n};

Following example is a nullable type.

const jsonSchema = {
  $id: 'Nullable',
  type: ['string', 'null'],
};
convert(jsonSchema);
// => export type Nullable = string | null;

Following example is an exact object type.

const jsonSchema = {
  $id: 'ExactObject',
  type: 'object',
  additionalProperties: false,
  properties: {
    foo: {
      type: 'string',
    },
  },
};
convert(jsonSchema);
// => export type ExactObject = {|\n  foo?: string\n|};

Following example is a reference to a definition using $ref.

const jsonSchema = {
  $id: 'Definition',
  $ref: '#/definitions/foo',
  definitions: {
    foo: {
      type: 'object',
      properties: {
        bar: {
          type: 'string',
        },
      },
    },
  },
};
convert(jsonSchema);
// => export type Definition = {\n  bar?: string\n};

Test

npm run test

Demo

https://igata.netlify.com/

License

MIT license.

1.3.11

5 years ago

1.3.10

6 years ago

1.3.9

6 years ago

1.3.8

6 years ago

1.3.7

6 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago