@stbmoz-onboarding/core 1.0.32 → 1.0.35
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/Functions/functions.js +3 -5
- package/Validations/rules.js +19 -20
- package/package.json +1 -1
package/Functions/functions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { isAboveMaxLength, isMinLength,
|
|
1
|
+
const { isAboveMaxLength, isMinLength, allowedCharsOnly, isIn } = require("./../Validations")
|
|
2
2
|
|
|
3
3
|
const feedbacks = {
|
|
4
4
|
oversized: "Ultrapassou o limite de caracteres",
|
|
@@ -53,13 +53,11 @@ module.exports.Sanitize = (values, key, errors, isRequired, failMessage, _minLen
|
|
|
53
53
|
|
|
54
54
|
if (!values[key] && isRequired) {
|
|
55
55
|
errors[key] = feedbacks.required
|
|
56
|
-
} else if (
|
|
56
|
+
} else if (allowedCharsOnly(values[key], allowedChars)) {
|
|
57
57
|
if (!isMinLength(values[key], _minLength)) {
|
|
58
58
|
errors[key] = failMessage
|
|
59
|
-
} else {
|
|
60
|
-
if (!isAboveMaxLength(values[key], _maxLength)) {
|
|
59
|
+
} else if (isAboveMaxLength(values[key], _maxLength)) {
|
|
61
60
|
errors[key] = feedbacks.oversized
|
|
62
|
-
}
|
|
63
61
|
}
|
|
64
62
|
} else {
|
|
65
63
|
errors[key] = feedbacks.invalidChars
|
package/Validations/rules.js
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
//Allowed prefixes
|
|
3
3
|
const AllowedPrefixes = ['25884', '25885', '25886', '25887', '25882', '25883']
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
module.exports.isIn = (value, optionsArray) => {
|
|
7
|
+
try {
|
|
8
|
+
return optionsArray.includes(value)
|
|
9
|
+
} catch (error) {
|
|
10
|
+
return false
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
// Check is a guiven email is valid
|
|
6
15
|
module.exports.isEmailValid = (email) => {
|
|
7
16
|
if (/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(email)) {
|
|
@@ -59,18 +68,16 @@ module.exports.isLength = (value, length) => {
|
|
|
59
68
|
module.exports.allowedCharsOnly = (stringToTest, charSet) => {
|
|
60
69
|
try {
|
|
61
70
|
let stringToCheck = stringToTest.toString()
|
|
62
|
-
const dictionary = charSet
|
|
63
|
-
|
|
71
|
+
const dictionary = charSet
|
|
72
|
+
|
|
64
73
|
if (stringToCheck.length > 0) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
))
|
|
74
|
+
let phrase = stringToCheck.toLowerCase()
|
|
75
|
+
phrase = phrase.replace(/(\r\n|\n|\r)/gm, " ");
|
|
76
|
+
phrase = phrase.split('')
|
|
77
|
+
return !(phrase.some(item => {
|
|
78
|
+
return !(dictionary.includes(item))
|
|
79
|
+
}
|
|
80
|
+
))
|
|
74
81
|
}
|
|
75
82
|
} catch (e) {
|
|
76
83
|
return false
|
|
@@ -87,14 +94,6 @@ module.exports.isInteger = (number) => {
|
|
|
87
94
|
if (Number.isInteger(number)) return true
|
|
88
95
|
}
|
|
89
96
|
|
|
90
|
-
module.exports.isIn = (value, optionsArray) => {
|
|
91
|
-
try {
|
|
92
|
-
return optionsArray.includes(value)
|
|
93
|
-
} catch (error) {
|
|
94
|
-
return false
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
97
|
module.exports.isContactValid = (number) => {
|
|
99
98
|
if (!number) {
|
|
100
99
|
return false
|
|
@@ -104,7 +103,7 @@ module.exports.isContactValid = (number) => {
|
|
|
104
103
|
if (/^([0-9]{12})$/.test(number)) {
|
|
105
104
|
const prefix = numb.slice(0, 5)
|
|
106
105
|
|
|
107
|
-
if (isIn(prefix, AllowedPrefixes)) {
|
|
106
|
+
if (this.isIn(prefix, AllowedPrefixes)) {
|
|
108
107
|
return true
|
|
109
108
|
}
|
|
110
109
|
return false
|