https://github.com/shepherdwind/schema-util-backup
Better for human write schema define
https://github.com/shepherdwind/schema-util-backup
Last synced: 9 months ago
JSON representation
Better for human write schema define
- Host: GitHub
- URL: https://github.com/shepherdwind/schema-util-backup
- Owner: shepherdwind
- Created: 2015-05-25T13:36:53.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-08-24T07:43:10.000Z (almost 11 years ago)
- Last Synced: 2025-09-27T15:25:51.896Z (9 months ago)
- Language: JavaScript
- Size: 180 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## schema util
[](https://travis-ci.org/shepherdwind/schema-util)
[](https://nodei.co/npm/schema-util/)
### schema dsl parse
```js
var schema = require('schema-util').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 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']
});
```
#### 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.