@carecard/validate 2.0.1 → 2.0.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/lib/validate.js +60 -60
- package/package.json +1 -1
- package/coverage/clover.xml +0 -139
- package/coverage/coverage-final.json +0 -4
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -146
- package/coverage/lcov-report/index.ts.html +0 -91
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/validate.ts.html +0 -559
- package/coverage/lcov-report/validateProperties.ts.html +0 -370
- package/coverage/lcov.info +0 -378
- package/dist/cjs/index.cjs +0 -18
- package/dist/cjs/index.d.ts +0 -2
- package/dist/cjs/validate.cjs +0 -173
- package/dist/cjs/validate.d.ts +0 -25
- package/dist/cjs/validateProperties.cjs +0 -81
- package/dist/cjs/validateProperties.d.ts +0 -5
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.js +0 -2
- package/dist/esm/validate.d.ts +0 -25
- package/dist/esm/validate.js +0 -145
- package/dist/esm/validateProperties.d.ts +0 -5
- package/dist/esm/validateProperties.js +0 -78
package/dist/esm/validate.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export declare const isImageUrl: (imageUrl: string | any[]) => boolean;
|
|
2
|
-
export declare const isInteger: (number: number | string) => boolean;
|
|
3
|
-
export declare const isValidJsonString: (str: string | number | any[]) => boolean;
|
|
4
|
-
export declare const isValidIntegerString: (str: string | number | any[]) => boolean;
|
|
5
|
-
export declare const isValidUuidString: (str: string | number | any[]) => boolean;
|
|
6
|
-
export declare const isCharactersString: (str: string | number | any[]) => boolean;
|
|
7
|
-
export declare const isNameString: (str: string) => boolean;
|
|
8
|
-
export declare const isSafeSearchString: (str: string) => boolean;
|
|
9
|
-
export declare const isEmailString: (email: string | any[]) => boolean;
|
|
10
|
-
export declare const isJwtString: (jwt: string) => boolean;
|
|
11
|
-
export declare const isPasswordString: (password: string | any[]) => boolean;
|
|
12
|
-
export declare const isSimplePasswordString: (password: string | any[]) => boolean;
|
|
13
|
-
export declare const isPasswordStringFailureMessage: (password: string | any[]) => "Total 6 to 32 characters, numbers and one of !@#$%^&*_-" | null;
|
|
14
|
-
export declare const isSimplePasswordStringFailureMessage: (password: string | any[]) => "Total 6 to 32 characters, numbers or !@#$%^&*_-" | null;
|
|
15
|
-
export declare const isUsernameString: (str: string | any[]) => boolean;
|
|
16
|
-
export declare function isPhoneNumber(str: string | any[]): boolean;
|
|
17
|
-
export declare const isUrlSafeString: (inputString: string) => boolean;
|
|
18
|
-
export declare const isString6To24CharacterLong: (password: string | any[]) => boolean;
|
|
19
|
-
export declare const isString6To16CharacterLong: (password: string | any[]) => boolean;
|
|
20
|
-
export declare const isProvinceString: (inputString: string) => boolean;
|
|
21
|
-
export declare const isBoolValue: (inputValue: any) => inputValue is boolean;
|
|
22
|
-
export declare const isPostalCodeString: (inputString: string) => boolean;
|
|
23
|
-
export declare const isSafeString: (str: string | any[]) => boolean;
|
|
24
|
-
export declare const isInStringArray: (StringArray: string | any[], inputString: string) => boolean;
|
|
25
|
-
export declare const isCountryCodeString: (str: string | any[]) => boolean;
|
package/dist/esm/validate.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
export const isImageUrl = (imageUrl) => {
|
|
2
|
-
if (imageUrl === undefined || typeof imageUrl !== 'string' || imageUrl.length === 0)
|
|
3
|
-
return false;
|
|
4
|
-
const imageUrlRegex = /^[a-zA-Z0-9-_./]+$/;
|
|
5
|
-
return imageUrlRegex.test(imageUrl);
|
|
6
|
-
};
|
|
7
|
-
export const isInteger = (number) => {
|
|
8
|
-
return Number.isInteger(number);
|
|
9
|
-
};
|
|
10
|
-
export const isValidJsonString = (str) => {
|
|
11
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
12
|
-
return false;
|
|
13
|
-
try {
|
|
14
|
-
const json = JSON.parse(str);
|
|
15
|
-
return typeof json === 'object';
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
export const isValidIntegerString = (str) => {
|
|
22
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
23
|
-
return false;
|
|
24
|
-
return /^\d+$/g.test(str);
|
|
25
|
-
};
|
|
26
|
-
export const isValidUuidString = (str) => {
|
|
27
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
28
|
-
return false;
|
|
29
|
-
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str);
|
|
30
|
-
};
|
|
31
|
-
export const isCharactersString = (str) => {
|
|
32
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
33
|
-
return false;
|
|
34
|
-
return /^[\da-zA-Z _-]+$/.test(str);
|
|
35
|
-
};
|
|
36
|
-
export const isNameString = (str) => {
|
|
37
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
38
|
-
return false;
|
|
39
|
-
return /^[A-Za-z][0-9a-zA-Z-_.,'() ]+$/.test(str.trim());
|
|
40
|
-
};
|
|
41
|
-
export const isSafeSearchString = (str) => {
|
|
42
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
43
|
-
return false;
|
|
44
|
-
return /^[A-Za-z][0-9a-zA-Z\-_.,'()@ ]{1,100}$/.test(str.trim());
|
|
45
|
-
};
|
|
46
|
-
export const isEmailString = (email) => {
|
|
47
|
-
if (email === undefined || typeof email !== 'string' || email.length === 0)
|
|
48
|
-
return false;
|
|
49
|
-
const regExpEmail = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
50
|
-
return regExpEmail.test(String(email).toLowerCase());
|
|
51
|
-
};
|
|
52
|
-
export const isJwtString = (jwt) => {
|
|
53
|
-
if (jwt === '' || jwt.trim() === '')
|
|
54
|
-
return false;
|
|
55
|
-
const jwtRegex = /^eyJ[a-zA-Z0-9-_.]+$/;
|
|
56
|
-
return jwtRegex.test(jwt);
|
|
57
|
-
};
|
|
58
|
-
export const isPasswordString = (password) => {
|
|
59
|
-
if (password === undefined || typeof password !== 'string' || password.length === 0)
|
|
60
|
-
return false;
|
|
61
|
-
const regExPassword = /^(?=.*[a-zA-Z0-9])(?=.*[!@#$%^&*_-])[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
62
|
-
return regExPassword.test(String(password));
|
|
63
|
-
};
|
|
64
|
-
export const isSimplePasswordString = (password) => {
|
|
65
|
-
if (password === undefined || typeof password !== 'string' || password.length === 0)
|
|
66
|
-
return false;
|
|
67
|
-
const regExPassword = /^[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
68
|
-
return regExPassword.test(String(password));
|
|
69
|
-
};
|
|
70
|
-
export const isPasswordStringFailureMessage = (password) => {
|
|
71
|
-
if (!isPasswordString(password)) {
|
|
72
|
-
return 'Total 6 to 32 characters, numbers and one of !@#$%^&*_-';
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
export const isSimplePasswordStringFailureMessage = (password) => {
|
|
79
|
-
if (!isPasswordString(password)) {
|
|
80
|
-
return 'Total 6 to 32 characters, numbers or !@#$%^&*_-';
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
export const isUsernameString = (str) => {
|
|
87
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
88
|
-
return false;
|
|
89
|
-
return /^[0-9a-zA-Z]+$/.test(str);
|
|
90
|
-
};
|
|
91
|
-
export function isPhoneNumber(str) {
|
|
92
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
93
|
-
return false;
|
|
94
|
-
return /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/.test(str);
|
|
95
|
-
}
|
|
96
|
-
export const isUrlSafeString = (inputString) => {
|
|
97
|
-
if (inputString === '' || inputString.trim() === '')
|
|
98
|
-
return false;
|
|
99
|
-
const jwtRegex = /^[a-zA-Z0-9-_.]+$/;
|
|
100
|
-
return jwtRegex.test(inputString);
|
|
101
|
-
};
|
|
102
|
-
export const isString6To24CharacterLong = (password) => {
|
|
103
|
-
if (password === undefined || typeof password !== 'string' || password.length === 0)
|
|
104
|
-
return false;
|
|
105
|
-
return 6 <= password.length && password.length <= 24;
|
|
106
|
-
};
|
|
107
|
-
export const isString6To16CharacterLong = (password) => {
|
|
108
|
-
if (password === undefined || typeof password !== 'string' || password.length === 0)
|
|
109
|
-
return false;
|
|
110
|
-
return 6 <= password.length && password.length <= 16;
|
|
111
|
-
};
|
|
112
|
-
export const isProvinceString = (inputString) => {
|
|
113
|
-
const provinces = ['on', 'qc'];
|
|
114
|
-
if (isNameString(inputString)) {
|
|
115
|
-
return provinces.includes(inputString.toLowerCase());
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
};
|
|
119
|
-
export const isBoolValue = (inputValue) => {
|
|
120
|
-
return !(inputValue === undefined || typeof inputValue !== 'boolean');
|
|
121
|
-
};
|
|
122
|
-
export const isPostalCodeString = (inputString) => {
|
|
123
|
-
const postalCodeRegex = /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$/i;
|
|
124
|
-
if (isNameString(inputString)) {
|
|
125
|
-
return postalCodeRegex.test(inputString);
|
|
126
|
-
}
|
|
127
|
-
return false;
|
|
128
|
-
};
|
|
129
|
-
export const isSafeString = (str) => {
|
|
130
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
131
|
-
return false;
|
|
132
|
-
return /^[\da-zA-Z-_.,#*'()\[\]: ]+$/.test(str);
|
|
133
|
-
};
|
|
134
|
-
export const isInStringArray = (StringArray, inputString) => {
|
|
135
|
-
if (isNameString(inputString)) {
|
|
136
|
-
return StringArray.includes(inputString.toLowerCase());
|
|
137
|
-
}
|
|
138
|
-
return false;
|
|
139
|
-
};
|
|
140
|
-
export const isCountryCodeString = (str) => {
|
|
141
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
142
|
-
return false;
|
|
143
|
-
const postalCodeRegex = /^\+[1-9][0-9]{0,2}$/i;
|
|
144
|
-
return postalCodeRegex.test(str);
|
|
145
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// Validate the property values format.
|
|
2
|
-
import { isEmailString, isPhoneNumber, isUrlSafeString, isValidUuidString, isSimplePasswordString, isPasswordString, isString6To16CharacterLong, isNameString, isSafeSearchString, isCharactersString, isValidIntegerString, isValidJsonString, isImageUrl, } from './validate';
|
|
3
|
-
export function validateProperties(obj = {}) {
|
|
4
|
-
let returnObj = {};
|
|
5
|
-
for (let [key, value] of Object.entries(obj || {})) {
|
|
6
|
-
switch (key) {
|
|
7
|
-
case 'first_name':
|
|
8
|
-
case 'username':
|
|
9
|
-
case 'newStatus':
|
|
10
|
-
case 'description':
|
|
11
|
-
case 'comment':
|
|
12
|
-
case 'status':
|
|
13
|
-
case 'name':
|
|
14
|
-
case 'title':
|
|
15
|
-
case 'brand':
|
|
16
|
-
case 'short_description':
|
|
17
|
-
isNameString(value) ? (returnObj[key] = value) : null;
|
|
18
|
-
break;
|
|
19
|
-
case 'search_string':
|
|
20
|
-
case 'searchString':
|
|
21
|
-
isSafeSearchString(value) ? (returnObj[key] = value) : null;
|
|
22
|
-
break;
|
|
23
|
-
case 'password':
|
|
24
|
-
case 'new_password':
|
|
25
|
-
isString6To16CharacterLong(value) && isSimplePasswordString(value)
|
|
26
|
-
? (returnObj[key] = value)
|
|
27
|
-
: null;
|
|
28
|
-
break;
|
|
29
|
-
case 'strong_password':
|
|
30
|
-
isString6To16CharacterLong(value) && isPasswordString(value)
|
|
31
|
-
? (returnObj[key] = value)
|
|
32
|
-
: null;
|
|
33
|
-
break;
|
|
34
|
-
case 'email':
|
|
35
|
-
isEmailString(value) ? (returnObj[key] = value) : null;
|
|
36
|
-
break;
|
|
37
|
-
case 'phone_number':
|
|
38
|
-
isPhoneNumber(value) ? (returnObj[key] = value) : null;
|
|
39
|
-
break;
|
|
40
|
-
case 'token':
|
|
41
|
-
case 'email_confirm_token':
|
|
42
|
-
case 'verification_token':
|
|
43
|
-
isUrlSafeString(value) ? (returnObj[key] = value) : null;
|
|
44
|
-
break;
|
|
45
|
-
case 'uuid':
|
|
46
|
-
case 'item_id':
|
|
47
|
-
case 'user_id':
|
|
48
|
-
case 'image_id':
|
|
49
|
-
case 'itemId':
|
|
50
|
-
case 'userId':
|
|
51
|
-
case 'orderId':
|
|
52
|
-
case 'category_id':
|
|
53
|
-
case 'parent_id':
|
|
54
|
-
isValidUuidString(value) ? (returnObj[key] = value) : null;
|
|
55
|
-
break;
|
|
56
|
-
case 'period':
|
|
57
|
-
isCharactersString(value) ? (returnObj[key] = value) : null;
|
|
58
|
-
break;
|
|
59
|
-
case 'offset_number':
|
|
60
|
-
case 'number_of_orders':
|
|
61
|
-
case 'price':
|
|
62
|
-
isValidIntegerString(value) ? (returnObj[key] = value) : null;
|
|
63
|
-
break;
|
|
64
|
-
case 'about':
|
|
65
|
-
isValidJsonString(value) ? (returnObj[key] = value.trim()) : null;
|
|
66
|
-
break;
|
|
67
|
-
case 'weight':
|
|
68
|
-
case 'dimensions':
|
|
69
|
-
case 'permission':
|
|
70
|
-
isValidJsonString(JSON.stringify(value)) ? (returnObj[key] = value) : null;
|
|
71
|
-
break;
|
|
72
|
-
case 'image_url':
|
|
73
|
-
isImageUrl(value) ? (returnObj[key] = value) : null;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return returnObj;
|
|
78
|
-
}
|