9 Commits

Author SHA1 Message Date
root 47348064c2 bump version and changelog
continuous-integration/drone/push Build is passing
2020-06-11 14:52:10 +00:00
root 93fe5b3f7f Merge pull request '[feat] modify types export, add package git repository' (#10) from feature/modify-export-types into develop
continuous-integration/drone/push Build is passing
2020-06-11 14:51:04 +00:00
root 0dae994202 [feat] modify types export, add package git repository
continuous-integration/drone/push Build is passing
2020-06-11 14:50:00 +00:00
root d2456c2844 Merge pull request 'bump version and edit changelog' (#9) from release/0.0.3 into develop
continuous-integration/drone/push Build is passing
2020-06-10 14:22:00 +00:00
root 70cc973927 bump version and edit changelog
continuous-integration/drone/push Build is passing
2020-06-10 14:19:00 +00:00
root 81bde1577c Merge pull request 'feature/modify-types-init-value' (#7) from feature/modify-types-init-value into develop
continuous-integration/drone/push Build is passing
2020-06-10 14:17:29 +00:00
root cdbecea36d [chore] add test set
continuous-integration/drone/push Build is passing
2020-06-10 14:15:02 +00:00
root 464e42ba1c [fix] add types init values 2020-06-10 14:13:34 +00:00
root a6d39d487a Merge pull request 'bump version and modify changelog' (#6) from release/0.0.2 into develop
continuous-integration/drone/push Build is passing
2020-06-10 13:39:21 +00:00
6 changed files with 46 additions and 21 deletions
+9
View File
@@ -1,5 +1,14 @@
# ChangeLog # ChangeLog
## 2020-06-11 (0.0.4)
- modify types export
- add package repository
## 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
+5 -5
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
+5 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "mtfos-validator", "name": "mtfos-validator",
"version": "0.0.2", "version": "0.0.4",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
@@ -12,5 +12,9 @@
"devDependencies": { "devDependencies": {
"jest": "^26.0.1", "jest": "^26.0.1",
"standard": "^12.0.1" "standard": "^12.0.1"
},
"repository": {
"type": "git",
"url": "https://git.trj.tw/nodejs/validator.git"
} }
} }
+8 -15
View File
@@ -1,15 +1,8 @@
const Base = require('./base.js') const types = {}
const StringType = require('./string.js') module.exports = types
const NumberType = require('./number.js') types.Base = require('./base.js')
const BooleanType = require('./boolean.js') types.StringType = require('./string.js')
const ObjectType = require('./object.js') types.NumberType = require('./number.js')
const ArrayType = require('./array.js') types.BooleanType = require('./boolean.js')
types.ObjectType = require('./object.js')
module.exports = { types.ArrayType = require('./array.js')
Base,
StringType,
NumberType,
BooleanType,
ObjectType,
ArrayType
}
+2
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()
}) })
}) })
+17
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)
})
}) })