@stbmoz-onboarding/core 1.0.23 → 1.0.25
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/Dates/{DateFormater.js → dates.js} +14 -1
- package/Dates/index.js +3 -4
- package/Utilities/academicLevels.js +3 -5
- package/Utilities/activities.js +2 -6
- package/Utilities/contractTypes.js +2 -3
- package/Utilities/countries.js +3 -5
- package/Utilities/employmentTypes.js +2 -3
- package/Utilities/genders.js +2 -4
- package/Utilities/idDocuments.js +3 -5
- package/Utilities/index.js +19 -24
- package/Utilities/maritalStatus.js +2 -4
- package/Utilities/marriageRegime.js +2 -4
- package/Utilities/professions.js +2 -4
- package/Utilities/provinces.js +1 -3
- package/Utilities/segments.js +3 -5
- package/Validations/index.js +6 -215
- package/Validations/rules.js +216 -0
- package/package.json +1 -1
- package/Dates/DateValidator.js +0 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.DateFormater = (date, format) => {
|
|
2
2
|
try {
|
|
3
3
|
const months = ['Janeiro', 'Fevereiro', 'Marco', 'Abril', 'Maio', 'Junho',
|
|
4
4
|
'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro']
|
|
@@ -18,4 +18,17 @@ export default function DateFormater(date, format) {
|
|
|
18
18
|
} catch (e) {
|
|
19
19
|
return date
|
|
20
20
|
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports.ValidateDate = (values, key, errors, invalidDateMsg) => {
|
|
24
|
+
try {
|
|
25
|
+
const date = new Date(values[key])
|
|
26
|
+
if (date == "Invalid Date") {
|
|
27
|
+
errors[key] = invalidDateMsg
|
|
28
|
+
} else {
|
|
29
|
+
values[key] = date
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
errors[key] = invalidDateMsg
|
|
33
|
+
}
|
|
21
34
|
}
|
package/Dates/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export * from './DateFormater';
|
|
3
|
-
export { default as DateValidator } from './DateValidator';
|
|
4
|
-
export * from './DateValidator';
|
|
1
|
+
const { DateFormater, ValidateDate } = require("./dates")
|
|
5
2
|
|
|
3
|
+
|
|
4
|
+
module.exports = { DateFormater, ValidateDate }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.academicLevels = [
|
|
2
2
|
{
|
|
3
3
|
value: 'NIVEL MEDIO',
|
|
4
4
|
pt: 'Nível Médio',
|
|
@@ -20,11 +20,9 @@ export const academicLevels = [
|
|
|
20
20
|
},
|
|
21
21
|
]
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
module.exports.academicLevel = {
|
|
24
24
|
medium: 'NIVEL MEDIO',
|
|
25
25
|
graduate: 'LICENCIATURA',
|
|
26
26
|
master: 'MESTRE',
|
|
27
27
|
doctor: 'DOUTOR'
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default academicLevels
|
|
28
|
+
}
|
package/Utilities/activities.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.activities = [
|
|
2
2
|
{
|
|
3
3
|
value: 'STUDENT',
|
|
4
4
|
pt: 'Estudante',
|
|
@@ -32,7 +32,7 @@ export const activities = [
|
|
|
32
32
|
]
|
|
33
33
|
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
module.exports.activity = {
|
|
36
36
|
studant: 'STUDENT',
|
|
37
37
|
employed: 'EMPLOYED',
|
|
38
38
|
unemployed: 'UNEMPLOYED',
|
|
@@ -40,7 +40,3 @@ export const activity = {
|
|
|
40
40
|
pensioner: 'PENSIONER',
|
|
41
41
|
selfEmployed: 'SELF EMPLOYED'
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
export default activities
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.contractRegimes = [
|
|
2
2
|
{
|
|
3
3
|
value: "INDETERMINATED",
|
|
4
4
|
pt: "Indeterminado",
|
|
@@ -17,10 +17,9 @@ export const contractRegimes = [
|
|
|
17
17
|
]
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
module.exports.contractRegime = {
|
|
21
21
|
indeterminated: "INDETERMINATED",
|
|
22
22
|
determinated: "DETERMINATED",
|
|
23
23
|
temporary: "TEMPORARY"
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export default contractRegimes
|
package/Utilities/countries.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.countries = [
|
|
2
2
|
{
|
|
3
3
|
value: "MZ",
|
|
4
4
|
pt: "Moçambique",
|
|
@@ -17,8 +17,6 @@ export const countries = [
|
|
|
17
17
|
|
|
18
18
|
]
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
module.exports.country = {
|
|
21
21
|
mozambique: "MZ"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default countries
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.employmentTypes = [
|
|
2
2
|
{
|
|
3
3
|
value: "FORMAL",
|
|
4
4
|
pt: "Emprego Formal",
|
|
@@ -11,9 +11,8 @@ export const employmentTypes = [
|
|
|
11
11
|
}
|
|
12
12
|
]
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
module.exports.employmentType = {
|
|
15
15
|
formal: "FORMAL",
|
|
16
16
|
informal: "INFORMAL"
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export default employmentTypes
|
package/Utilities/genders.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.genders = [
|
|
2
2
|
{
|
|
3
3
|
value: "FEMALE",
|
|
4
4
|
pt: "Feminino",
|
|
@@ -11,9 +11,7 @@ export const genders = [
|
|
|
11
11
|
}
|
|
12
12
|
]
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
module.exports.gender = {
|
|
15
15
|
female: "FEMALE",
|
|
16
16
|
male: "MALE"
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
export default genders
|
package/Utilities/idDocuments.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.idDocuments = [
|
|
2
2
|
{
|
|
3
3
|
value: 2,
|
|
4
4
|
pt: "Bilhete de Identidade",
|
|
@@ -11,9 +11,7 @@ export const idDocuments = [
|
|
|
11
11
|
}
|
|
12
12
|
];
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
module.exports.idDocument = {
|
|
15
15
|
id: 2,
|
|
16
16
|
passport: 1
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default idDocuments
|
|
17
|
+
}
|
package/Utilities/index.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export * from './idDocuments';
|
|
21
|
-
export { default as genders } from './genders';
|
|
22
|
-
export * from './genders';
|
|
23
|
-
export { default as segments } from './segments';
|
|
24
|
-
export * from './segments';
|
|
1
|
+
const { academicLevel, academicLevels } = require("./academicLevels")
|
|
2
|
+
const { activities, activity } = require("./activities")
|
|
3
|
+
const { contractRegime, contractRegimes } = require("./contractTypes")
|
|
4
|
+
const { countries, country } = require("./countries")
|
|
5
|
+
const { employmentType, employmentTypes } = require("./employmentTypes")
|
|
6
|
+
const { gender, genders } = require("./genders")
|
|
7
|
+
const { idDocument, idDocuments } = require("./idDocuments")
|
|
8
|
+
const { maritalStatus, maritalStatuses } = require("./maritalStatus")
|
|
9
|
+
const { marriageRegimes, marriageRegime } = require("./marriageRegime")
|
|
10
|
+
const { professions } = require("./professions")
|
|
11
|
+
const { provinces } = require("./provinces")
|
|
12
|
+
const { segment, segments } = require("./segments")
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
academicLevel, academicLevels, activities, activity, contractRegime, contractRegimes,
|
|
16
|
+
countries, country, employmentType, employmentTypes, gender, genders, idDocument, idDocuments,
|
|
17
|
+
maritalStatus, maritalStatuses, marriageRegimes, marriageRegime, professions, provinces,
|
|
18
|
+
segment, segments
|
|
19
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.maritalStatuses = [
|
|
2
2
|
{
|
|
3
3
|
value: 1,
|
|
4
4
|
pt: {
|
|
@@ -46,11 +46,9 @@ export const maritalStatuses = [
|
|
|
46
46
|
}
|
|
47
47
|
]
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
module.exports.maritalStatus = {
|
|
50
50
|
single: 1,
|
|
51
51
|
married: 2,
|
|
52
52
|
divorced: 3,
|
|
53
53
|
widow: 4
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
export default maritalStatuses
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.marriageRegimes = [
|
|
2
2
|
{
|
|
3
3
|
value: 1,
|
|
4
4
|
pt: "Comunhão de bens",
|
|
@@ -21,11 +21,9 @@ export const marriageRegimes = [
|
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
module.exports.marriageRegime = {
|
|
25
25
|
communityProperty: 1,
|
|
26
26
|
ancWithAccrual: 2,
|
|
27
27
|
ancwithoutAccrual: 3,
|
|
28
28
|
unknown: 9
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
export default marriageRegime
|
package/Utilities/professions.js
CHANGED
package/Utilities/provinces.js
CHANGED
package/Utilities/segments.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
module.exports.segments = [
|
|
2
2
|
{
|
|
3
3
|
value: "INDIVIDUALS",
|
|
4
4
|
pt: "Particulares",
|
|
@@ -12,9 +12,7 @@ export const segments = [
|
|
|
12
12
|
]
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
module.exports.segment = {
|
|
16
16
|
individuals: "INDIVIDUALS",
|
|
17
17
|
soleProps: "SOLE-PROPS"
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default segments
|
|
18
|
+
}
|
package/Validations/index.js
CHANGED
|
@@ -1,215 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//Check is password is strong
|
|
12
|
-
export const isPasswordStrong = (password) => {
|
|
13
|
-
if (/[a-z]/.test(password) && // checks for a-z
|
|
14
|
-
/[0-9]/.test(password) && // checks for 0-9
|
|
15
|
-
/\W|_/.test(password) && // checks for special char
|
|
16
|
-
password.length >= 8 //Checks if is password 8 chars long
|
|
17
|
-
) {
|
|
18
|
-
return true
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const isSameAs = (value1, value2) => {
|
|
23
|
-
if (value1 === value2) return true
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//Checks if string containes white space
|
|
27
|
-
export const containesWhiteSpace = (string) => {
|
|
28
|
-
string = string.replace(/(\r\n|\n|\r)/gm, " ");
|
|
29
|
-
if (string.includes(' ')) return true
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
//Checks if value is greather then
|
|
33
|
-
export const isMinValue = (minValue, value2ToCheck) => {
|
|
34
|
-
if (minValue <= value2ToCheck) return true
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const isMinLength = (value, length) => {
|
|
38
|
-
let stringValue = value.toString()
|
|
39
|
-
stringValue = value.toLowerCase()
|
|
40
|
-
stringValue = stringValue.split('')
|
|
41
|
-
if (stringValue.length >= length) return true
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const isAboveMaxLength = (value, length) => {
|
|
45
|
-
let stringValue = value.toString()
|
|
46
|
-
stringValue = stringValue.toLowerCase()
|
|
47
|
-
stringValue = stringValue.split('')
|
|
48
|
-
if (stringValue.length > length) return true
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const isLength = (value, length) => {
|
|
52
|
-
let stringValue = value.toString()
|
|
53
|
-
stringValue = stringValue.toLowerCase()
|
|
54
|
-
stringValue = stringValue.split('')
|
|
55
|
-
if (stringValue.length === length) return true
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const allowedCharsOnly = (stringToTest, charSet) => {
|
|
59
|
-
try {
|
|
60
|
-
let stringToCheck = stringToTest.toString()
|
|
61
|
-
const dictionary = charSet.split('')
|
|
62
|
-
|
|
63
|
-
if (stringToCheck.length > 0) {
|
|
64
|
-
let phrase = stringToCheck.toLowerCase()
|
|
65
|
-
phrase = phrase.replace(/(\r\n|\n|\r)/gm, " ");
|
|
66
|
-
phrase = phrase.split('');
|
|
67
|
-
return !(phrase.some(function (item) {
|
|
68
|
-
if (!dictionary.includes(item)) {
|
|
69
|
-
return true
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
))
|
|
73
|
-
}
|
|
74
|
-
} catch (e) {
|
|
75
|
-
return false
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export const startsWith = (toBeChecked, startsWithThis) => {
|
|
80
|
-
toBeChecked = toBeChecked.toString()
|
|
81
|
-
if (toBeChecked.startsWith(startsWithThis)) return true
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export const isInteger = (number) => {
|
|
85
|
-
number = Number(number)
|
|
86
|
-
if (Number.isInteger(number)) return true
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const isIn = (value, optionsArray) => {
|
|
90
|
-
try {
|
|
91
|
-
return optionsArray.includes(value)
|
|
92
|
-
} catch (error) {
|
|
93
|
-
return false
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export const isContactValid = (number) => {
|
|
98
|
-
if (!number) {
|
|
99
|
-
return false
|
|
100
|
-
} else {
|
|
101
|
-
try {
|
|
102
|
-
const numb = String(number)
|
|
103
|
-
if (/^([0-9]{12})$/.test(number)) {
|
|
104
|
-
const prefix = numb.slice(0, 5)
|
|
105
|
-
|
|
106
|
-
if (isIn(prefix, AllowedPrefixes)) {
|
|
107
|
-
return true
|
|
108
|
-
}
|
|
109
|
-
return false
|
|
110
|
-
} else {
|
|
111
|
-
return false
|
|
112
|
-
}
|
|
113
|
-
} catch (e) {
|
|
114
|
-
return false
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export const WordsCount = (str) => {
|
|
120
|
-
try {
|
|
121
|
-
if (str) {
|
|
122
|
-
str = str.replace(/(^\s*)|(\s*$)/gi, "");
|
|
123
|
-
str = str.replace(/[ ]{2,}/gi, " ");
|
|
124
|
-
str = str.replace(/\n /, "\n");
|
|
125
|
-
return str.split(' ').length;
|
|
126
|
-
} else {
|
|
127
|
-
return 0
|
|
128
|
-
}
|
|
129
|
-
} catch (error) {
|
|
130
|
-
return 0
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function isMinor(dateOfBirth, ageLimit) {
|
|
135
|
-
let today = new Date()
|
|
136
|
-
let birthDate = new Date(dateOfBirth)
|
|
137
|
-
let age = today.getFullYear() - birthDate.getFullYear()
|
|
138
|
-
let m = today.getMonth() - birthDate.getMonth()
|
|
139
|
-
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
|
|
140
|
-
age--
|
|
141
|
-
}
|
|
142
|
-
if (age >= ageLimit) return true
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function isBIValid(BINumber) {
|
|
146
|
-
if (/^([0-9]{12})+([A-Z]\b)$/.test(BINumber)) {
|
|
147
|
-
return true
|
|
148
|
-
} else {
|
|
149
|
-
return false
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function isValidCertificateNumber(number) {
|
|
154
|
-
try {
|
|
155
|
-
if (/^([0-9]{9})$/.test(number)) return true
|
|
156
|
-
throw new Error()
|
|
157
|
-
} catch (error) {
|
|
158
|
-
return false
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function isPDF(filedata) {
|
|
163
|
-
let aux = filedata.name.split(".")
|
|
164
|
-
const extention = aux[aux.length - 1]
|
|
165
|
-
if (extention == "pdf" || extention == "PDF" && filedata.type == "application/pdf") {
|
|
166
|
-
return true
|
|
167
|
-
}
|
|
168
|
-
return false
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function isValidNuit(nuit) {
|
|
172
|
-
try {
|
|
173
|
-
const nuitNumber = nuit.toString()
|
|
174
|
-
if (nuitNumber.length != 9) {
|
|
175
|
-
return false
|
|
176
|
-
}
|
|
177
|
-
let a = parseInt(nuitNumber.substr(0, 1))
|
|
178
|
-
let b = parseInt(nuitNumber.substr(1, 1))
|
|
179
|
-
let c = parseInt(nuitNumber.substr(2, 1))
|
|
180
|
-
let d = parseInt(nuitNumber.substr(3, 1))
|
|
181
|
-
let e = parseInt(nuitNumber.substr(4, 1))
|
|
182
|
-
let f = parseInt(nuitNumber.substr(5, 1))
|
|
183
|
-
let g = parseInt(nuitNumber.substr(6, 1))
|
|
184
|
-
let h = parseInt(nuitNumber.substr(7, 1))
|
|
185
|
-
let checkDigit = parseInt(nuitNumber.substr(8, 1))
|
|
186
|
-
|
|
187
|
-
a = a * 3
|
|
188
|
-
b = b * 2
|
|
189
|
-
c = c * 7
|
|
190
|
-
d = d * 6
|
|
191
|
-
e = e * 5
|
|
192
|
-
f = f * 4
|
|
193
|
-
g = g * 3
|
|
194
|
-
h = h * 2
|
|
195
|
-
|
|
196
|
-
const digitsSum = a + b + c + d + e + f + g + h
|
|
197
|
-
const digitsMOD = digitsSum % 11
|
|
198
|
-
|
|
199
|
-
if (digitsMOD == 0 || digitsMOD == 1) {
|
|
200
|
-
|
|
201
|
-
if (digitsMOD == checkDigit) {
|
|
202
|
-
return true
|
|
203
|
-
}
|
|
204
|
-
} else {
|
|
205
|
-
const result = 11 - digitsMOD
|
|
206
|
-
if (result == checkDigit) {
|
|
207
|
-
return true
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
catch (err) {
|
|
213
|
-
return false
|
|
214
|
-
}
|
|
215
|
-
}
|
|
1
|
+
const {
|
|
2
|
+
isBIValid, isMinor, isPDF, isValidCertificateNumber, isValidNuit,
|
|
3
|
+
WordsCount, allowedCharsOnly, containesWhiteSpace, isAboveMaxLength,
|
|
4
|
+
isContactValid, isEmailValid, isIn, isInteger, isLength, isMinLength,
|
|
5
|
+
isMinValue, isPasswordStrong, isSameAs, startsWith
|
|
6
|
+
} = require("./rules")
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
|
|
2
|
+
//Allowed prefixes
|
|
3
|
+
const AllowedPrefixes = ['25884', '25885', '25886', '25887', '25882', '25883']
|
|
4
|
+
|
|
5
|
+
// Check is a guiven email is valid
|
|
6
|
+
module.exports.isEmailValid = (email) => {
|
|
7
|
+
if (/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(email)) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//Check is password is strong
|
|
13
|
+
module.exports.isPasswordStrong = (password) => {
|
|
14
|
+
if (/[a-z]/.test(password) && // checks for a-z
|
|
15
|
+
/[0-9]/.test(password) && // checks for 0-9
|
|
16
|
+
/\W|_/.test(password) && // checks for special char
|
|
17
|
+
password.length >= 8 //Checks if is password 8 chars long
|
|
18
|
+
) {
|
|
19
|
+
return true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports.isSameAs = (value1, value2) => {
|
|
24
|
+
if (value1 === value2) return true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//Checks if string containes white space
|
|
28
|
+
module.exports.containesWhiteSpace = (string) => {
|
|
29
|
+
string = string.replace(/(\r\n|\n|\r)/gm, " ");
|
|
30
|
+
if (string.includes(' ')) return true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//Checks if value is greather then
|
|
34
|
+
module.exports.isMinValue = (minValue, value2ToCheck) => {
|
|
35
|
+
if (minValue <= value2ToCheck) return true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports.isMinLength = (value, length) => {
|
|
39
|
+
let stringValue = value.toString()
|
|
40
|
+
stringValue = value.toLowerCase()
|
|
41
|
+
stringValue = stringValue.split('')
|
|
42
|
+
if (stringValue.length >= length) return true
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports.isAboveMaxLength = (value, length) => {
|
|
46
|
+
let stringValue = value.toString()
|
|
47
|
+
stringValue = stringValue.toLowerCase()
|
|
48
|
+
stringValue = stringValue.split('')
|
|
49
|
+
if (stringValue.length > length) return true
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports.isLength = (value, length) => {
|
|
53
|
+
let stringValue = value.toString()
|
|
54
|
+
stringValue = stringValue.toLowerCase()
|
|
55
|
+
stringValue = stringValue.split('')
|
|
56
|
+
if (stringValue.length === length) return true
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports.allowedCharsOnly = (stringToTest, charSet) => {
|
|
60
|
+
try {
|
|
61
|
+
let stringToCheck = stringToTest.toString()
|
|
62
|
+
const dictionary = charSet.split('')
|
|
63
|
+
|
|
64
|
+
if (stringToCheck.length > 0) {
|
|
65
|
+
let phrase = stringToCheck.toLowerCase()
|
|
66
|
+
phrase = phrase.replace(/(\r\n|\n|\r)/gm, " ");
|
|
67
|
+
phrase = phrase.split('');
|
|
68
|
+
return !(phrase.some(function (item) {
|
|
69
|
+
if (!dictionary.includes(item)) {
|
|
70
|
+
return true
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
))
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
return false
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports.startsWith = (toBeChecked, startsWithThis) => {
|
|
81
|
+
toBeChecked = toBeChecked.toString()
|
|
82
|
+
if (toBeChecked.startsWith(startsWithThis)) return true
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports.isInteger = (number) => {
|
|
86
|
+
number = Number(number)
|
|
87
|
+
if (Number.isInteger(number)) return true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
module.exports.isIn = (value, optionsArray) => {
|
|
91
|
+
try {
|
|
92
|
+
return optionsArray.includes(value)
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports.isContactValid = (number) => {
|
|
99
|
+
if (!number) {
|
|
100
|
+
return false
|
|
101
|
+
} else {
|
|
102
|
+
try {
|
|
103
|
+
const numb = String(number)
|
|
104
|
+
if (/^([0-9]{12})$/.test(number)) {
|
|
105
|
+
const prefix = numb.slice(0, 5)
|
|
106
|
+
|
|
107
|
+
if (isIn(prefix, AllowedPrefixes)) {
|
|
108
|
+
return true
|
|
109
|
+
}
|
|
110
|
+
return false
|
|
111
|
+
} else {
|
|
112
|
+
return false
|
|
113
|
+
}
|
|
114
|
+
} catch (e) {
|
|
115
|
+
return false
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports.WordsCount = (str) => {
|
|
121
|
+
try {
|
|
122
|
+
if (str) {
|
|
123
|
+
str = str.replace(/(^\s*)|(\s*$)/gi, "");
|
|
124
|
+
str = str.replace(/[ ]{2,}/gi, " ");
|
|
125
|
+
str = str.replace(/\n /, "\n");
|
|
126
|
+
return str.split(' ').length;
|
|
127
|
+
} else {
|
|
128
|
+
return 0
|
|
129
|
+
}
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return 0
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports.isMinor = (dateOfBirth, ageLimit) => {
|
|
136
|
+
let today = new Date()
|
|
137
|
+
let birthDate = new Date(dateOfBirth)
|
|
138
|
+
let age = today.getFullYear() - birthDate.getFullYear()
|
|
139
|
+
let m = today.getMonth() - birthDate.getMonth()
|
|
140
|
+
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
|
|
141
|
+
age--
|
|
142
|
+
}
|
|
143
|
+
if (age >= ageLimit) return true
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports.isBIValid = (BINumber) => {
|
|
147
|
+
if (/^([0-9]{12})+([A-Z]\b)$/.test(BINumber)) {
|
|
148
|
+
return true
|
|
149
|
+
} else {
|
|
150
|
+
return false
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
module.exports.isValidCertificateNumber = (number) => {
|
|
155
|
+
try {
|
|
156
|
+
if (/^([0-9]{9})$/.test(number)) return true
|
|
157
|
+
throw new Error()
|
|
158
|
+
} catch (error) {
|
|
159
|
+
return false
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
module.exports.isPDF = (filedata) => {
|
|
164
|
+
let aux = filedata.name.split(".")
|
|
165
|
+
const extention = aux[aux.length - 1]
|
|
166
|
+
if (extention == "pdf" || extention == "PDF" && filedata.type == "application/pdf") {
|
|
167
|
+
return true
|
|
168
|
+
}
|
|
169
|
+
return false
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
module.exports.isValidNuit = (nuit) => {
|
|
173
|
+
try {
|
|
174
|
+
const nuitNumber = nuit.toString()
|
|
175
|
+
if (nuitNumber.length != 9) {
|
|
176
|
+
return false
|
|
177
|
+
}
|
|
178
|
+
let a = parseInt(nuitNumber.substr(0, 1))
|
|
179
|
+
let b = parseInt(nuitNumber.substr(1, 1))
|
|
180
|
+
let c = parseInt(nuitNumber.substr(2, 1))
|
|
181
|
+
let d = parseInt(nuitNumber.substr(3, 1))
|
|
182
|
+
let e = parseInt(nuitNumber.substr(4, 1))
|
|
183
|
+
let f = parseInt(nuitNumber.substr(5, 1))
|
|
184
|
+
let g = parseInt(nuitNumber.substr(6, 1))
|
|
185
|
+
let h = parseInt(nuitNumber.substr(7, 1))
|
|
186
|
+
let checkDigit = parseInt(nuitNumber.substr(8, 1))
|
|
187
|
+
|
|
188
|
+
a = a * 3
|
|
189
|
+
b = b * 2
|
|
190
|
+
c = c * 7
|
|
191
|
+
d = d * 6
|
|
192
|
+
e = e * 5
|
|
193
|
+
f = f * 4
|
|
194
|
+
g = g * 3
|
|
195
|
+
h = h * 2
|
|
196
|
+
|
|
197
|
+
const digitsSum = a + b + c + d + e + f + g + h
|
|
198
|
+
const digitsMOD = digitsSum % 11
|
|
199
|
+
|
|
200
|
+
if (digitsMOD == 0 || digitsMOD == 1) {
|
|
201
|
+
|
|
202
|
+
if (digitsMOD == checkDigit) {
|
|
203
|
+
return true
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
const result = 11 - digitsMOD
|
|
207
|
+
if (result == checkDigit) {
|
|
208
|
+
return true
|
|
209
|
+
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
return false
|
|
215
|
+
}
|
|
216
|
+
}
|
package/package.json
CHANGED
package/Dates/DateValidator.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export default function ValidateDate(values, key, errors, invalidDateMsg) {
|
|
2
|
-
try {
|
|
3
|
-
const date = new Date(values[key])
|
|
4
|
-
if (date == "Invalid Date") {
|
|
5
|
-
errors[key] = invalidDateMsg
|
|
6
|
-
} else {
|
|
7
|
-
values[key] = date
|
|
8
|
-
}
|
|
9
|
-
} catch (error) {
|
|
10
|
-
errors[key] = invalidDateMsg
|
|
11
|
-
}
|
|
12
|
-
}
|