0.0.5 • Published 7 years ago
datacontract v0.0.5
datacontract
Description
- it helps to generate mock data for front end so it won't need to wait when coding front end.
- it helps to validate data transfered between front end and server side.
- it helps to generate a large amout of data for test code.
Installation
npm install -g datacontract
Generate data by contract
var DataContract = require("datacontract")
var Book = {
name: {
type: "string"
}
}
var User = {
name: {
type: "string"
},
age: {
type: "int",
range: [0, 120]
},
books: {
type: [{type: Book}]
},
book: {
type: Book
},
remark: {
type: "string",
nullable: true,
undefable: true
}
}
var data = DataContract.generate(User, 100);
var data1 = DataContract.generate(User);
Validate data by contract
Data Type
##string
{
type: "string",
nullable: false,
undefable: false,
length: [1, 20],
auto: function (def) {} //custom generator
}
##int
{
type: "int",
nullable: false,
undefable: false,
range: [0, 120],
auto: function (def) {} //custom generator
}
##number
{
type: "int",
nullable: false,
undefable: false,
range: [0, 120],
auto: function (def) {} //custom generator
}
##array
{
type: [],//[{type: "int"}, {type: "string"}, {type: []}]
nullable: false,
undefable: false
}
##object
{
type: {},
nullable: false,
undefable: false
}
API
generate (contract, [defaultMaxNumberOfRowsForGenerateArray])
validate (contract, data)