Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@johnny.reina/ajv-types

0.1.0 • Public • Published

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

Install

npm i @johnny.reina/ajv-types

DownloadsWeekly Downloads

6

Version

0.1.0

License

MIT

Unpacked Size

12.5 kB

Total Files

9

Last publish

Collaborators

  • avatar