3.4.6 • Published 5 years ago

schema-util v3.4.6

Weekly downloads
25
License
ISC
Repository
-
Last release
5 years ago

schema util

build status

依赖 schema-util 的应用列表:

Badges

TNPM version TNPM downloads install size


schema dsl parse

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 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

3.4.6

5 years ago

3.4.5

5 years ago

3.4.4

5 years ago

3.4.2

5 years ago

3.4.1

5 years ago

3.4.0

5 years ago

3.3.0

6 years ago

3.2.0

6 years ago

3.1.5

6 years ago

3.1.4

7 years ago

3.1.3

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.12

7 years ago

3.0.11

7 years ago

3.0.10

7 years ago

3.0.10-beta1

7 years ago

3.0.10-beta

7 years ago

3.0.9

7 years ago

3.0.9-beta

7 years ago

3.0.8

7 years ago

3.0.7

7 years ago

3.0.4

8 years ago

3.0.3

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

1.4.1

9 years ago

1.4.0

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago