0.2.0 • Published 3 years ago

@johnny.reina/ajv-types v0.2.0

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

AJV-types @johnny.reina/ajv-types

Schema types and factory functions for AJV

An animated gif showing Intellisense usage for creating an AJV schema

Why?

Reading the AJV docs is a massive chore and it can be hard to defined a schema correctly.

Installation

npm i @johnny.reina/ajv-types

Usage

import A from "@johnny.reina/ajv-types";
const An = A; // Optional but nice to read if that's your thing
              // also you can name these whatever you want

const schema = An.Object({
  additionalProperties: false,
  properties: {
    username: A.String({ minLength: 3 }),
    password: A.String({ minLength: 16 }),
    profile: An.Object({
      additionalProperties: false,
      properties: {
        birthday: A.Format.Email,
        interests: An.Array({
          items: A.String()
        })
      }
    })
  }
});

Using just the types

The types can be used standalone to provide compile-type schema validation. Just import from @johnny.reina/ajv-types/types;

import { ObjectSchema } from "@johnny.reina/ajv-types";

An animated gif showing Intellisense usage for creating an AJV schema without factory functions