Skip to content

ant-motion/schema-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

schemas utile

Badges

NPM version npm download

--------------------

schema dsl parse

var schema = require('schemas-utile').schema;

var json = schema(`
  Array(foo) {
    href(href),
    title(title),
    img(image url): Image,
    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(user): Object {
      name(user name),
      age(user age): Number
    }
  }
`, ['number']);

The secend argument, you can add some more type support, such asage.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']
});

export support

Write code like this example, you can get a object, which have to properties a and b. Each property have the value of schema object.

schema(`
  export a Object(hello) { ... }

  export b Array(hello b) { ... }
`);

mock

mock schema data

mock(schema, config)

config can set default type value, for example, config set to { image: 'xx.png' }, then schema mock image type value will be xx.png.

config value can be an function.

walk

walk every property of schema.

merge

merge old / new datas.

formatOldDataWithNewSchema

format old data with new schema

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published