@mara/schema-utils

1.0.2 • Public • Published

Schema Utils

JSON Schema Validator. Extracted from webpack.

Feature: Customize error messages with the description properties.

Install

yarn add @mara/schema-utils

Usage

schema.json

{
  "type": "object",
  "properties": {
    "name": {
      // custom error message
      "description": "name description",
      "type": "string"
    },
    "test": {
      "anyOf": [
        { "type": "array" },
        { "type": "string" },
        { "instanceof": "RegExp" }
      ]
    },
    "transform": {
      "instanceof": "Function"
    },
    "sourceMap": {
      "type": "boolean"
    }
  },
  "additionalProperties": false
}
import schema from 'path/to/schema.json'
import validateOptions from '@mara/schema-utils'

const inputOptions = {
  name: 'hello'
}
const valid = validateOptions(schema, inputOptions, 'Config Filename')

if (valid) {
  // do something...
}

/@mara/schema-utils/

    Package Sidebar

    Install

    npm i @mara/schema-utils

    Weekly Downloads

    2

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    13.1 kB

    Total Files

    5

    Last publish

    Collaborators

    • holmeshaw
    • xiaojue
    • lq0611
    • vv314
    • happybang
    • limy1997
    • tingyu3