@wmfs/json-to-vuelidate 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/lib/index.js +10 -18
- package/package.json +5 -5
- package/test/test.js +40 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
+
# [1.23.0](https://github.com/wmfs/json-to-vuelidate/compare/v1.22.3...v1.23.0) (2021-12-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🛠 Builds
|
|
5
|
+
|
|
6
|
+
* **deps-dev:** update dependency semantic-release to v18.0.1 ([4fed5c6](https://github.com/wmfs/json-to-vuelidate/commit/4fed5c6439b66e3de4d339f30954dcc9edb149ac))
|
|
7
|
+
* **deps-dev:** update semantic-release monorepo ([8ca62db](https://github.com/wmfs/json-to-vuelidate/commit/8ca62dbb892ff384edb65ee1936f82e324a851bb))
|
|
8
|
+
* **deps:** update dependency vuelidate to v0.7.7 ([aedd1af](https://github.com/wmfs/json-to-vuelidate/commit/aedd1af0bf754447ec98f35eaf09904cb0576e9d))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### 🚨 Tests
|
|
12
|
+
|
|
13
|
+
* better labels for comparing min/max dates ([ccc5f43](https://github.com/wmfs/json-to-vuelidate/commit/ccc5f434c4ae9142ade2c7c62db7bf65a8915df9))
|
|
14
|
+
* enhance tests for min/max dates ([72ea867](https://github.com/wmfs/json-to-vuelidate/commit/72ea867adeaf4487927b33ae50fe894c6c030bb7))
|
|
15
|
+
|
|
16
|
+
## [1.22.3](https://github.com/wmfs/json-to-vuelidate/compare/v1.22.2...v1.22.3) (2021-10-27)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### 🐛 Bug Fixes
|
|
20
|
+
|
|
21
|
+
* compare dates to be inclusive and precise to the day ([10fb6aa](https://github.com/wmfs/json-to-vuelidate/commit/10fb6aa3e512704d40915f6591a4000368bff49c))
|
|
22
|
+
|
|
23
|
+
## [1.22.2](https://github.com/wmfs/json-to-vuelidate/compare/v1.22.1...v1.22.2) (2021-10-27)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### 🐛 Bug Fixes
|
|
27
|
+
|
|
28
|
+
* simpler logic of comparing min/max dates ([f1d1a2e](https://github.com/wmfs/json-to-vuelidate/commit/f1d1a2e632858f631a4f6785ea2ce6398da6c505))
|
|
29
|
+
|
|
30
|
+
## [1.22.1](https://github.com/wmfs/json-to-vuelidate/compare/v1.22.0...v1.22.1) (2021-10-18)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### 🐛 Bug Fixes
|
|
34
|
+
|
|
35
|
+
* if undefined then return true because nothing to validate ([a49a51c](https://github.com/wmfs/json-to-vuelidate/commit/a49a51ce8a70bbcd6373b0ef51f205a1605ea3ac))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### 📦 Code Refactoring
|
|
39
|
+
|
|
40
|
+
* simplify re-used functions ([9661070](https://github.com/wmfs/json-to-vuelidate/commit/96610707dfa9323391dfd60a8c73a9fe602148ce))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### 🚨 Tests
|
|
44
|
+
|
|
45
|
+
* add tests for min/max date validations ([c33de28](https://github.com/wmfs/json-to-vuelidate/commit/c33de2858257bcf6b2e37c3a72220fe765a8b2ef))
|
|
46
|
+
|
|
1
47
|
# [1.22.0](https://github.com/wmfs/json-to-vuelidate/compare/v1.21.0...v1.22.0) (2021-10-18)
|
|
2
48
|
|
|
3
49
|
|
package/lib/index.js
CHANGED
|
@@ -2,6 +2,8 @@ const validators = require('vuelidate/lib/validators')
|
|
|
2
2
|
const template = require('lodash.template')
|
|
3
3
|
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance()
|
|
4
4
|
const moment = require('moment')
|
|
5
|
+
const isNotDefined = value => value === undefined || value === null || value === ''
|
|
6
|
+
const parseTemplate = (_template, data) => template(_template)(data)
|
|
5
7
|
|
|
6
8
|
module.exports = function (json) {
|
|
7
9
|
const result = {}
|
|
@@ -80,14 +82,11 @@ function parse (val, key) {
|
|
|
80
82
|
}
|
|
81
83
|
break
|
|
82
84
|
case 'required':
|
|
83
|
-
if (attributeValue)
|
|
84
|
-
result.required = validators.required
|
|
85
|
-
}
|
|
85
|
+
if (attributeValue) result.required = validators.required
|
|
86
86
|
break
|
|
87
87
|
case 'requiredIf':
|
|
88
88
|
result.requiredIf = validators.requiredIf(function () {
|
|
89
|
-
const
|
|
90
|
-
const result = compiled(this)
|
|
89
|
+
const result = parseTemplate('${' + attributeValue + '}', this)
|
|
91
90
|
return result === 'true'
|
|
92
91
|
})
|
|
93
92
|
break
|
|
@@ -99,21 +98,16 @@ function parse (val, key) {
|
|
|
99
98
|
break
|
|
100
99
|
case 'maximum.$':
|
|
101
100
|
result.maximum = function (value) {
|
|
102
|
-
if (value
|
|
103
|
-
return false
|
|
104
|
-
}
|
|
101
|
+
if (isNotDefined(value)) return true
|
|
105
102
|
|
|
106
|
-
const
|
|
107
|
-
const result = compiled(this)
|
|
103
|
+
const result = parseTemplate('${' + attributeValue + '}', this)
|
|
108
104
|
|
|
109
105
|
return value <= +result
|
|
110
106
|
}
|
|
111
107
|
break
|
|
112
108
|
case 'minimumDate': {
|
|
113
109
|
result.minimumDate = function (value) {
|
|
114
|
-
if (value
|
|
115
|
-
return false
|
|
116
|
-
}
|
|
110
|
+
if (isNotDefined(value)) return true
|
|
117
111
|
|
|
118
112
|
const mValue = moment(value)
|
|
119
113
|
const mMin = moment(attributeValue)
|
|
@@ -122,15 +116,13 @@ function parse (val, key) {
|
|
|
122
116
|
return false
|
|
123
117
|
}
|
|
124
118
|
|
|
125
|
-
return
|
|
119
|
+
return mMin.isBefore(mValue, 'day') || mMin.isSame(mValue, 'day')
|
|
126
120
|
}
|
|
127
121
|
break
|
|
128
122
|
}
|
|
129
123
|
case 'maximumDate': {
|
|
130
124
|
result.maximumDate = function (value) {
|
|
131
|
-
if (value
|
|
132
|
-
return false
|
|
133
|
-
}
|
|
125
|
+
if (isNotDefined(value)) return true
|
|
134
126
|
|
|
135
127
|
const mValue = moment(value)
|
|
136
128
|
const mMax = moment(attributeValue)
|
|
@@ -139,7 +131,7 @@ function parse (val, key) {
|
|
|
139
131
|
return false
|
|
140
132
|
}
|
|
141
133
|
|
|
142
|
-
return
|
|
134
|
+
return mValue.isBefore(mMax, 'day') || mValue.isSame(mMax, 'day')
|
|
143
135
|
}
|
|
144
136
|
break
|
|
145
137
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wmfs/json-to-vuelidate",
|
|
3
3
|
"description": "Takes in a JSON object and products an object of vuelidate expressions.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.23.0",
|
|
5
5
|
"author": "West Midlands Fire Service",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tymly",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"main": "./lib/index.js",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"vuelidate": "0.7.
|
|
12
|
+
"vuelidate": "0.7.7",
|
|
13
13
|
"lodash.template": "4.5.0",
|
|
14
14
|
"google-libphonenumber": "3.2.21",
|
|
15
15
|
"moment": "2.29.1"
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"cz-conventional-changelog": "3.3.0",
|
|
24
24
|
"mocha": "9.1.3",
|
|
25
25
|
"nyc": "15.1.0",
|
|
26
|
-
"semantic-release": "18.0.
|
|
26
|
+
"semantic-release": "18.0.1",
|
|
27
27
|
"standard": "16.0.4",
|
|
28
|
-
"@semantic-release/changelog": "6.0.
|
|
29
|
-
"@semantic-release/git": "10.0.
|
|
28
|
+
"@semantic-release/changelog": "6.0.1",
|
|
29
|
+
"@semantic-release/git": "10.0.1"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"lint": "standard",
|
package/test/test.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const converter = require('./../lib/')
|
|
4
4
|
const expect = require('chai').expect
|
|
5
|
+
const moment = require('moment')
|
|
5
6
|
|
|
6
7
|
const JSON = {
|
|
7
8
|
numberBetween5And10: {
|
|
@@ -36,12 +37,20 @@ const JSON = {
|
|
|
36
37
|
required: true
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
},
|
|
41
|
+
dateOfBirth: {
|
|
42
|
+
maximumDate: new Date()
|
|
43
|
+
},
|
|
44
|
+
min3DaysAgo: {
|
|
45
|
+
minimumDate: moment().subtract(3, 'days').format('YYYY/MM/DD')
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
describe('Test the vuelidate converter', function () {
|
|
50
|
+
let vuelidate
|
|
51
|
+
|
|
43
52
|
it('Convert some JSON', () => {
|
|
44
|
-
|
|
53
|
+
vuelidate = converter(JSON)
|
|
45
54
|
|
|
46
55
|
console.log('\n------\n', vuelidate)
|
|
47
56
|
expect(vuelidate.numberBetween5And10.between).to.be.a('function')
|
|
@@ -61,5 +70,35 @@ describe('Test the vuelidate converter', function () {
|
|
|
61
70
|
|
|
62
71
|
expect(vuelidate.list.required).to.be.a('function')
|
|
63
72
|
expect(vuelidate.apiLookup.params.apiLookupList.required).to.be.a('function')
|
|
73
|
+
|
|
74
|
+
expect(vuelidate.dateOfBirth.maximumDate).to.be.a('function')
|
|
75
|
+
|
|
76
|
+
expect(vuelidate.min3DaysAgo.minimumDate).to.be.a('function')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const dates = [
|
|
80
|
+
['1 year ago', moment().subtract(1, 'year'), false, true],
|
|
81
|
+
['7 days ago', moment().subtract(7, 'day'), false, true],
|
|
82
|
+
['4 days ago', moment().subtract(4, 'day'), false, true],
|
|
83
|
+
['3 days ago', moment().subtract(3, 'day'), true, true],
|
|
84
|
+
['yesterday', moment().subtract(1, 'day'), true, true],
|
|
85
|
+
['today', moment(), true, true],
|
|
86
|
+
['tomorrow', moment().add(1, 'day'), true, false],
|
|
87
|
+
['3 days ahead', moment().add(3, 'day'), true, false],
|
|
88
|
+
['4 days ahead', moment().add(4, 'day'), true, false],
|
|
89
|
+
['7 days ahead', moment().add(7, 'day'), true, false],
|
|
90
|
+
['1 year ahead', moment().add(1, 'year'), true, false]
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
describe('Test the validation function for minimum date', () => {
|
|
94
|
+
for (const [label, date, minResult] of dates) {
|
|
95
|
+
it(`${label}, should${minResult ? '' : ' not'} be after 3 days ago`, () => expect(vuelidate.min3DaysAgo.minimumDate(date)).to.eql(minResult))
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('Test the validation function for maximum date', () => {
|
|
100
|
+
for (const [label, date, , maxResult] of dates) {
|
|
101
|
+
it(`${label}, should${maxResult ? '' : ' not'} be before today`, () => expect(vuelidate.dateOfBirth.maximumDate(date)).to.eql(maxResult))
|
|
102
|
+
}
|
|
64
103
|
})
|
|
65
104
|
})
|