@mara/schema-utils
v1.0.2
Published
Marauder Validation Utils
Downloads
4
Readme
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...
}