From 464e42ba1cc77a7b3172277061867e8aafcb8815 Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 10 Jun 2020 14:13:34 +0000 Subject: [PATCH 1/3] [fix] add types init values --- index.js | 10 +++++----- validator.test.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 803f21c..42d0543 100644 --- a/index.js +++ b/index.js @@ -4,11 +4,11 @@ const validator = {} module.exports = validator validator.Base = types.Base -validator.string = () => new types.StringType() -validator.number = () => new types.NumberType() -validator.boolean = () => new types.BooleanType() -validator.array = () => new types.ArrayType() -validator.object = () => new types.ObjectType() +validator.string = (...args) => new types.StringType(...args) +validator.number = (...args) => new types.NumberType(...args) +validator.boolean = (...args) => new types.BooleanType(...args) +validator.array = (...args) => new types.ArrayType(...args) +validator.object = (...args) => new types.ObjectType(...args) /** * validate diff --git a/validator.test.js b/validator.test.js index 51ac8cf..aa973e0 100644 --- a/validator.test.js +++ b/validator.test.js @@ -23,4 +23,21 @@ describe('test validator validate', () => { 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) + }) }) From cdbecea36d61c1af7f46524647e8cbe3c949c9cf Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 10 Jun 2020 14:15:02 +0000 Subject: [PATCH 2/3] [chore] add test set --- types/object.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/object.test.js b/types/object.test.js index 4e8cce8..2c9a573 100644 --- a/types/object.test.js +++ b/types/object.test.js @@ -24,5 +24,7 @@ describe('test validate type schema object', () => { }).required() throwFunc(obj.validate({ name: 'asd' })) + + expect(throwFunc(obj.validate({ name: 123 }))).toThrow() }) }) From 70cc97392748df177fceeec7a0563dc58e32c89a Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 10 Jun 2020 14:19:00 +0000 Subject: [PATCH 3/3] bump version and edit changelog --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f2d09e..a2ebfc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # ChangeLog +## 2020-06-10 (0.0.3) + +- add types init value + ## 2020-06-10 (0.0.2) - add string type pattern check function diff --git a/package.json b/package.json index 6984d49..1c47a62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mtfos-validator", - "version": "0.0.2", + "version": "0.0.3", "description": "", "main": "index.js", "scripts": {