@wmfs/json-to-vuelidate 1.21.0 → 1.22.3
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 +64 -0
- package/lib/index.js +36 -9
- package/package.json +9 -8
- package/renovate.json +26 -0
- package/test/test.js +52 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
## [1.22.3](https://github.com/wmfs/json-to-vuelidate/compare/v1.22.2...v1.22.3) (2021-10-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 🐛 Bug Fixes
|
|
5
|
+
|
|
6
|
+
* compare dates to be inclusive and precise to the day ([10fb6aa](https://github.com/wmfs/json-to-vuelidate/commit/10fb6aa3e512704d40915f6591a4000368bff49c))
|
|
7
|
+
|
|
8
|
+
## [1.22.2](https://github.com/wmfs/json-to-vuelidate/compare/v1.22.1...v1.22.2) (2021-10-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### 🐛 Bug Fixes
|
|
12
|
+
|
|
13
|
+
* simpler logic of comparing min/max dates ([f1d1a2e](https://github.com/wmfs/json-to-vuelidate/commit/f1d1a2e632858f631a4f6785ea2ce6398da6c505))
|
|
14
|
+
|
|
15
|
+
## [1.22.1](https://github.com/wmfs/json-to-vuelidate/compare/v1.22.0...v1.22.1) (2021-10-18)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### 🐛 Bug Fixes
|
|
19
|
+
|
|
20
|
+
* if undefined then return true because nothing to validate ([a49a51c](https://github.com/wmfs/json-to-vuelidate/commit/a49a51ce8a70bbcd6373b0ef51f205a1605ea3ac))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### 📦 Code Refactoring
|
|
24
|
+
|
|
25
|
+
* simplify re-used functions ([9661070](https://github.com/wmfs/json-to-vuelidate/commit/96610707dfa9323391dfd60a8c73a9fe602148ce))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### 🚨 Tests
|
|
29
|
+
|
|
30
|
+
* add tests for min/max date validations ([c33de28](https://github.com/wmfs/json-to-vuelidate/commit/c33de2858257bcf6b2e37c3a72220fe765a8b2ef))
|
|
31
|
+
|
|
32
|
+
# [1.22.0](https://github.com/wmfs/json-to-vuelidate/compare/v1.21.0...v1.22.0) (2021-10-18)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### ✨ Features
|
|
36
|
+
|
|
37
|
+
* accept minimum date and maximum date conditions ([0874fb9](https://github.com/wmfs/json-to-vuelidate/commit/0874fb9682a06144a1de800f005454978967efd2))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### 🛠 Builds
|
|
41
|
+
|
|
42
|
+
* **deps-dev:** bump codecov from 3.8.2 to 3.8.3 ([bdc99f5](https://github.com/wmfs/json-to-vuelidate/commit/bdc99f5a494fdc73a0cc5d2af3342cd9823e28aa))
|
|
43
|
+
* **deps-dev:** bump mocha from 9.0.0 to 9.0.1 ([ce3af3a](https://github.com/wmfs/json-to-vuelidate/commit/ce3af3a91fade4eb31e52c22102a71cf51b87765))
|
|
44
|
+
* **deps-dev:** bump mocha from 9.0.1 to 9.0.2 ([98f1a0b](https://github.com/wmfs/json-to-vuelidate/commit/98f1a0baa7ef8df39d29757302143670dd770166))
|
|
45
|
+
* **deps-dev:** bump mocha from 9.0.2 to 9.0.3 ([0606aa5](https://github.com/wmfs/json-to-vuelidate/commit/0606aa50207b52089d426405211a88cbe1167bb5))
|
|
46
|
+
* **deps-dev:** bump semantic-release from 17.4.3 to 17.4.4 ([8a194a7](https://github.com/wmfs/json-to-vuelidate/commit/8a194a70ecc1637240ee8b43b3453520ef736bd7))
|
|
47
|
+
* **deps-dev:** update dependency [@semantic-release](https://github.com/semantic-release)/changelog to v6 ([8316cdd](https://github.com/wmfs/json-to-vuelidate/commit/8316cdd04dc1236caa185265404eccdc20322ef1))
|
|
48
|
+
* **deps-dev:** update dependency [@semantic-release](https://github.com/semantic-release)/git to v10 ([0a1054d](https://github.com/wmfs/json-to-vuelidate/commit/0a1054dbee6e78bc82f3832405ed15c84e04411f))
|
|
49
|
+
* **deps-dev:** update dependency [@semantic-release](https://github.com/semantic-release)/git to v9.0.1 ([4d3bd51](https://github.com/wmfs/json-to-vuelidate/commit/4d3bd51d14c098e41753c8012fde303922cf545e))
|
|
50
|
+
* **deps-dev:** update dependency mocha to v9.1.0 ([64f713c](https://github.com/wmfs/json-to-vuelidate/commit/64f713c629a0ae2b6210a2a3c00f71b1fe5c0381))
|
|
51
|
+
* **deps-dev:** update dependency mocha to v9.1.1 ([399a620](https://github.com/wmfs/json-to-vuelidate/commit/399a620afc572bc0687b3610f406e536211a3dbd))
|
|
52
|
+
* **deps-dev:** update dependency mocha to v9.1.2 ([1cdd405](https://github.com/wmfs/json-to-vuelidate/commit/1cdd40586cfbac2161daaea34cb27af2012f8725))
|
|
53
|
+
* **deps-dev:** update dependency mocha to v9.1.3 ([ba794f5](https://github.com/wmfs/json-to-vuelidate/commit/ba794f5f4f4116e348829972fb4c0bf163a652e1))
|
|
54
|
+
* **deps-dev:** update dependency semantic-release to v17.4.5 ([1a092e0](https://github.com/wmfs/json-to-vuelidate/commit/1a092e0c2459fdeb9324f3d486cae3e45cc1786b))
|
|
55
|
+
* **deps-dev:** update dependency semantic-release to v17.4.6 ([01c56c7](https://github.com/wmfs/json-to-vuelidate/commit/01c56c759d4d59adbac5e83463a84a22a4b9db3e))
|
|
56
|
+
* **deps-dev:** update dependency semantic-release to v17.4.7 ([7775707](https://github.com/wmfs/json-to-vuelidate/commit/777570759878e478d1d48af64303b6ab4c5b119d))
|
|
57
|
+
* **deps-dev:** update dependency semantic-release to v18 ([9becb66](https://github.com/wmfs/json-to-vuelidate/commit/9becb66e3fb1a869d852381ace22cd3a89e03877))
|
|
58
|
+
* **deps-dev:** update dependency standard to v16.0.4 ([e669ec4](https://github.com/wmfs/json-to-vuelidate/commit/e669ec48703797c6db5fd3b59721e74b580efc5d))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### ♻️ Chores
|
|
62
|
+
|
|
63
|
+
* add renovate config [ch6600] ([59769a7](https://github.com/wmfs/json-to-vuelidate/commit/59769a781465e1c3afc681f2a6bb3260c5794b30))
|
|
64
|
+
|
|
1
65
|
# [1.21.0](https://github.com/wmfs/json-to-vuelidate/compare/v1.20.1...v1.21.0) (2021-06-08)
|
|
2
66
|
|
|
3
67
|
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const validators = require('vuelidate/lib/validators')
|
|
2
2
|
const template = require('lodash.template')
|
|
3
3
|
const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance()
|
|
4
|
+
const moment = require('moment')
|
|
5
|
+
const isNotDefined = value => value === undefined || value === null || value === ''
|
|
6
|
+
const parseTemplate = (_template, data) => template(_template)(data)
|
|
4
7
|
|
|
5
8
|
module.exports = function (json) {
|
|
6
9
|
const result = {}
|
|
@@ -79,14 +82,11 @@ function parse (val, key) {
|
|
|
79
82
|
}
|
|
80
83
|
break
|
|
81
84
|
case 'required':
|
|
82
|
-
if (attributeValue)
|
|
83
|
-
result.required = validators.required
|
|
84
|
-
}
|
|
85
|
+
if (attributeValue) result.required = validators.required
|
|
85
86
|
break
|
|
86
87
|
case 'requiredIf':
|
|
87
88
|
result.requiredIf = validators.requiredIf(function () {
|
|
88
|
-
const
|
|
89
|
-
const result = compiled(this)
|
|
89
|
+
const result = parseTemplate('${' + attributeValue + '}', this)
|
|
90
90
|
return result === 'true'
|
|
91
91
|
})
|
|
92
92
|
break
|
|
@@ -98,16 +98,43 @@ function parse (val, key) {
|
|
|
98
98
|
break
|
|
99
99
|
case 'maximum.$':
|
|
100
100
|
result.maximum = function (value) {
|
|
101
|
-
if (value
|
|
101
|
+
if (isNotDefined(value)) return true
|
|
102
|
+
|
|
103
|
+
const result = parseTemplate('${' + attributeValue + '}', this)
|
|
104
|
+
|
|
105
|
+
return value <= +result
|
|
106
|
+
}
|
|
107
|
+
break
|
|
108
|
+
case 'minimumDate': {
|
|
109
|
+
result.minimumDate = function (value) {
|
|
110
|
+
if (isNotDefined(value)) return true
|
|
111
|
+
|
|
112
|
+
const mValue = moment(value)
|
|
113
|
+
const mMin = moment(attributeValue)
|
|
114
|
+
|
|
115
|
+
if (!mValue || !mValue.isValid() || !mMin || !mMin.isValid()) {
|
|
102
116
|
return false
|
|
103
117
|
}
|
|
104
118
|
|
|
105
|
-
|
|
106
|
-
|
|
119
|
+
return mMin.isBefore(mValue, 'day') || mMin.isSame(mValue, 'day')
|
|
120
|
+
}
|
|
121
|
+
break
|
|
122
|
+
}
|
|
123
|
+
case 'maximumDate': {
|
|
124
|
+
result.maximumDate = function (value) {
|
|
125
|
+
if (isNotDefined(value)) return true
|
|
107
126
|
|
|
108
|
-
|
|
127
|
+
const mValue = moment(value)
|
|
128
|
+
const mMax = moment(attributeValue)
|
|
129
|
+
|
|
130
|
+
if (!mValue || !mValue.isValid() || !mMax || !mMax.isValid()) {
|
|
131
|
+
return false
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return mValue.isBefore(mMax, 'day') || mValue.isSame(mMax, 'day')
|
|
109
135
|
}
|
|
110
136
|
break
|
|
137
|
+
}
|
|
111
138
|
case 'minLength':
|
|
112
139
|
result.minLength = validators.minLength(attributeValue)
|
|
113
140
|
break
|
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.22.3",
|
|
5
5
|
"author": "West Midlands Fire Service",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tymly",
|
|
@@ -11,21 +11,22 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"vuelidate": "0.7.6",
|
|
13
13
|
"lodash.template": "4.5.0",
|
|
14
|
-
"google-libphonenumber": "3.2.21"
|
|
14
|
+
"google-libphonenumber": "3.2.21",
|
|
15
|
+
"moment": "2.29.1"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"babel-register": "6.26.0",
|
|
18
19
|
"babel-preset-env": "1.7.0",
|
|
19
20
|
"chai": "4.3.4",
|
|
20
|
-
"codecov": "3.8.
|
|
21
|
+
"codecov": "3.8.3",
|
|
21
22
|
"conventional-changelog-metahub": "4.0.1",
|
|
22
23
|
"cz-conventional-changelog": "3.3.0",
|
|
23
|
-
"mocha": "9.
|
|
24
|
+
"mocha": "9.1.3",
|
|
24
25
|
"nyc": "15.1.0",
|
|
25
|
-
"semantic-release": "
|
|
26
|
-
"standard": "16.0.
|
|
27
|
-
"@semantic-release/changelog": "
|
|
28
|
-
"@semantic-release/git": "
|
|
26
|
+
"semantic-release": "18.0.0",
|
|
27
|
+
"standard": "16.0.4",
|
|
28
|
+
"@semantic-release/changelog": "6.0.0",
|
|
29
|
+
"@semantic-release/git": "10.0.0"
|
|
29
30
|
},
|
|
30
31
|
"scripts": {
|
|
31
32
|
"lint": "standard",
|
package/renovate.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"config:base"
|
|
4
|
+
],
|
|
5
|
+
"dependencyDashboard": true,
|
|
6
|
+
"enabledManagers": ["npm"],
|
|
7
|
+
"packageRules": [
|
|
8
|
+
{
|
|
9
|
+
"matchDepTypes": ["devDependencies"],
|
|
10
|
+
"automerge": true,
|
|
11
|
+
"semanticCommitType": "build",
|
|
12
|
+
"semanticCommitScope": "deps-dev",
|
|
13
|
+
"labels": ["devDependencies"]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"matchDepTypes": ["dependencies"],
|
|
17
|
+
"semanticCommitType": "build",
|
|
18
|
+
"semanticCommitScope": "deps",
|
|
19
|
+
"labels": ["dependencies"],
|
|
20
|
+
"reviewers": ["team:tymly-reviewers"]
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"vulnerabilityAlerts": {
|
|
24
|
+
"labels": ["security"]
|
|
25
|
+
}
|
|
26
|
+
}
|
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,47 @@ 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
|
+
it('test the validation function for minimum date', () => {
|
|
80
|
+
const fn = vuelidate.min3DaysAgo.minimumDate
|
|
81
|
+
|
|
82
|
+
const oneWeekAgo = moment().subtract(7, 'day')
|
|
83
|
+
const today = moment()
|
|
84
|
+
const tomorrow = moment().add(1, 'day')
|
|
85
|
+
const threeDaysAgo = moment().subtract(3, 'days')
|
|
86
|
+
|
|
87
|
+
const oneWeekAgoResult = fn(oneWeekAgo)
|
|
88
|
+
expect(oneWeekAgoResult).to.eql(false)
|
|
89
|
+
|
|
90
|
+
const threeDaysAgoResult = fn(threeDaysAgo)
|
|
91
|
+
expect(threeDaysAgoResult).to.eql(true)
|
|
92
|
+
|
|
93
|
+
const todayResult = fn(today)
|
|
94
|
+
expect(todayResult).to.eql(true)
|
|
95
|
+
|
|
96
|
+
const tomorrowResult = fn(tomorrow)
|
|
97
|
+
expect(tomorrowResult).to.eql(true)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('test the validation function for maximum date', () => {
|
|
101
|
+
const fn = vuelidate.dateOfBirth.maximumDate
|
|
102
|
+
|
|
103
|
+
const yesterday = moment().subtract(1, 'day')
|
|
104
|
+
const today = moment()
|
|
105
|
+
const tomorrow = moment().add(1, 'day')
|
|
106
|
+
|
|
107
|
+
const yesterdayResult = fn(yesterday)
|
|
108
|
+
expect(yesterdayResult).to.eql(true)
|
|
109
|
+
|
|
110
|
+
const todayResult = fn(today)
|
|
111
|
+
expect(todayResult).to.eql(true)
|
|
112
|
+
|
|
113
|
+
const tomorrowResult = fn(tomorrow)
|
|
114
|
+
expect(tomorrowResult).to.eql(false)
|
|
64
115
|
})
|
|
65
116
|
})
|