yaml-joi
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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.

Package Sidebar

Install

npm i yaml-joi

Weekly Downloads

4

Version

1.1.1

License

MIT

Unpacked Size

18.6 kB

Total Files

16

Last publish

Collaborators

  • imhele