@perfect-data/schema

2.7.2 • Public • Published

Perfect Data - Schema

Design and validate data using schema

Install

npm i @perfect-data/schema

Usage

import Schema, { SchemaType } from '@perfect-data/schema';

const itemSchema = new Schema({
  _id: String,
  name: {
    type: String,
    required: true,
    minLength: 3
  },
  qty: {
    type: SchemaType.Integer,
    minInteger: 0,
    defaultValue: 0
  },
  price: Number
});

const cartItemSchema = new Schema({
  itemId: String,
  qty: Number
});

const cartSchema = new Schema({
  _id: String,
  userId: String,
  items: SchemaTypes.ArrayOf(cartItemSchema)
})

const context = cartSchema.createContext();
const item = cartSchema.createModel({
  items: [{
    name: 'foo'
  }]
});


if (!context.validate(item)) {
  // context.isValid() == false
  console.error(context.getMessages());
}

Documentation

Coming soon...

license

MIT

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @perfect-data/schema

    Weekly Downloads

    1

    Version

    2.7.2

    License

    ISC

    Unpacked Size

    185 kB

    Total Files

    51

    Last publish

    Collaborators

    • yanickrochon