npm.io
0.0.3 • Published 3 years ago

simple-shape

Licence
MIT
Version
0.0.3
Deps
1
Size
15 kB
Vulns
0
Weekly
0
Stars
1

simple-shape

A simple function for building JSON Schema.

Basic Usage

import Ajv from "ajv"
import { shape } from 'simple-shape'

const ajv = new Ajv()

const Message = shape({
  id: Number,
  type: anyOf('short', 'long'),
  text: String,
})

// TypeOf<typeof Message> -> { id: number, type: 'short' | 'long', text: string }

const message = {
    id: 1,
    type: 'short',
    text: 'Hello, world!',
}

ajv.validate(shape, message);