yaml-joi
v1.1.1
Published
Parse string in yaml format into Joi validator
Downloads
2
Maintainers
Readme
yaml-joi
Parse string in yaml format into Joi validator.
Install
$ npm install yaml-joi
or
$ yarn add yaml-joi
Example
import yamlToJoi from 'yaml-joi';
const yamlLoadOpts = {};
const yamlSchema = `
type: string
allowEmpty: true
limitation:
- min: 3
- max: 5
- regex: !!js/regexp /^(\S*)$/
`;
const validator = yamlToJoi(yamlSchema, yamlLoadOpts);
validator.validate(null).error === null;
validator.validate('a').error !== null;
validator.validate('abc').error === null;
validator.validate('a b c').error !== null;
validator.validate('abcdef').error !== null;
import yamlToJoi from 'yaml-joi';
const yamlSchema = `
type: object
limitation:
- keys:
name:
isSchema: true
type: string
allowEmpty: nothing
limitation:
- min: 5
- max: 24
`;
const validator = yamlToJoi(yamlSchema);
validator.validate({}).error === null;
validator.validate({ name: 'str' }).error !== null;
validator.validate({ name: 'Alita' }).error === null;
Get more at cases.yml.