New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

papilio-util

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

papilio-util

Better for human write schema define

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

schema util

schema dsl parse

var schema = require('schema-util').schema;

var json = schema(`
  array(foo) {
    href(href),
    title(title),
    img.image(image url),
    amount(money amout)
  }
`);
// json should be so:
/**
  {
    type: 'array',
    description: 'foo',
    properties: {
      href: { description: 'href', type: 'string' },
      title: { description: 'title', type: 'string' },
      img: { description: 'image url', type: 'image' },
      amount: { description: 'money amount', type: 'string' }
    }
  }
*/

And nest rule supported:

var json = schema(`
  object(abc) {
    title(title),
    user.object(user) {
      name(user name),
      age.number(user age)
    }
  }
`, ['number']);

The secend argument, you can add some more type support, such as age.number, background.color.

schema(`array(foo) { a(a)}`, types)

The defaultType is 'string', If you want change this, you need send the secend argument like this:

schema(`array(foo) { a(a)}`, {
  defaultType: 'number',
  supported: ['string']
});

Keywords

schema

FAQs

Package last updated on 25 May 2015

Related posts