JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q80422F
  • License ISC

Advanced JSON schema manipulation and validation library

Package Exports

  • @kravc/schema

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@kravc/schema) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@kravc/schema

Advanced JSON schema manipulation and validation library based on z-schema.

API

Install:

npm i --save @kravc/schema

Get started

const { Schema, Validator } = require('@kravc/schema')

const baseSchema    = new Schema({ name: { required: true } }, 'Base')
const profileSchema = baseSchema
  .extend({
    status: {
      enum: [ 'Pending', 'Active' ],
      default: 'Pending'
    }
  }, 'Profile')

const validator = new Validator([ profileSchema ])

const profile = validator.validate({ name: 'John' }, 'Profile')
console.log(profile)

Expected output:

{ name: 'John', status: 'Pending' }

Advanced usage examples