@johnny.reina/ajv-types
TypeScript icon, indicating that this package has built-in type declarations

0.2.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

Package Sidebar

Install

npm i @johnny.reina/ajv-types

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

12.9 kB

Total Files

9

Last publish

Collaborators

  • johnny.reina