hotfix/array-check-contains-type #20

Merged
root merged 8 commits from hotfix/array-check-contains-type into develop 2020-07-05 05:31:08 +00:00
5 changed files with 29 additions and 6 deletions
Showing only changes of commit 564578c160 - Show all commits

View File

@ -1,5 +1,9 @@
# ChangeLog # ChangeLog
## 2020-06-10 (0.0.3)
- add types init value
## 2020-06-10 (0.0.2) ## 2020-06-10 (0.0.2)
- add string type pattern check function - add string type pattern check function

View File

@ -4,11 +4,11 @@ const validator = {}
module.exports = validator module.exports = validator
validator.Base = types.Base validator.Base = types.Base
validator.string = () => new types.StringType() validator.string = (...args) => new types.StringType(...args)
validator.number = () => new types.NumberType() validator.number = (...args) => new types.NumberType(...args)
validator.boolean = () => new types.BooleanType() validator.boolean = (...args) => new types.BooleanType(...args)
validator.array = () => new types.ArrayType() validator.array = (...args) => new types.ArrayType(...args)
validator.object = () => new types.ObjectType() validator.object = (...args) => new types.ObjectType(...args)
/** /**
* validate * validate

View File

@ -1,6 +1,6 @@
{ {
"name": "mtfos-validator", "name": "mtfos-validator",
"version": "0.0.2", "version": "0.0.3",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -24,5 +24,7 @@ describe('test validate type schema object', () => {
}).required() }).required()
throwFunc(obj.validate({ name: 'asd' })) throwFunc(obj.validate({ name: 'asd' }))
expect(throwFunc(obj.validate({ name: 123 }))).toThrow()
}) })
}) })

View File

@ -23,4 +23,21 @@ describe('test validator validate', () => {
expect(() => validator.validate(data, schema)).toThrow() expect(() => validator.validate(data, schema)).toThrow()
}) })
test('validate test 3', () => {
const data = {
str: '123',
strWithPattern: 'asd',
objWithChild: {
name: 'asd'
}
}
const schema = {
str: validator.string().required(),
strWithPattern: validator.string().pattern(/^asd$/).required(),
objWithChild: validator.object({ name: validator.string().required() }).required()
}
validator.validate(data, schema)
})
}) })