1.1.1 • Published 6 years ago

yaml-joi v1.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

yaml-joi

Alita NPM version NPM downloads Build Status Coverage Status License

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.