@carecard/validate 1.0.1 → 2.0.2
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/index.js +4 -0
- package/lib/validate.js +190 -0
- package/lib/validateProperties.js +106 -0
- package/package.json +14 -40
- package/readme.md +22 -4
- 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/index.js
ADDED
package/lib/validate.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
const isImageUrl = imageUrl => {
|
|
2
|
+
if (imageUrl === undefined || typeof imageUrl !== "string" || imageUrl.length === 0) return false;
|
|
3
|
+
|
|
4
|
+
const imageUrlRegex = /^[a-zA-Z0-9-_./]+$/;
|
|
5
|
+
return imageUrlRegex.test(imageUrl);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const isInteger = number => {
|
|
9
|
+
return Number.isInteger(number);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const isValidJsonString = str => {
|
|
13
|
+
if (str === undefined || typeof str !== "string" || str.length === 0) return false;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const json = JSON.parse(str);
|
|
17
|
+
return (typeof json === 'object');
|
|
18
|
+
} catch (error) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const isValidIntegerString = str => {
|
|
24
|
+
if (str === undefined || typeof str !== "string" || str.length === 0) return false;
|
|
25
|
+
return (/^\d+$/g.test(str));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const isValidUuidString = str => {
|
|
29
|
+
if (str === undefined || typeof str !== "string" || str.length === 0) return false;
|
|
30
|
+
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));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isCharactersString = str => {
|
|
34
|
+
if (str === undefined || typeof str !== "string" || str.length === 0) return false;
|
|
35
|
+
return (/^[\da-zA-Z _-]+$/.test(str));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isNameString = str => {
|
|
39
|
+
if (str === undefined || typeof str !== "string" || str.length === 0 || str.length > 1000) return false;
|
|
40
|
+
return (/^[A-Za-z][0-9a-zA-Z-_.,'() ]+$/.test(str.trim()));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const isSafeSearchString = str => {
|
|
44
|
+
if (str === undefined || typeof str !== "string" || str.length === 0) return false;
|
|
45
|
+
return /^[A-Za-z][0-9a-zA-Z\-_.,'()@ ]{1,100}$/.test(str.trim());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const isEmailString = email => {
|
|
49
|
+
if (email === undefined || typeof email !== "string" || email.length === 0 || email.length > 1000) return false;
|
|
50
|
+
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,}))$/;
|
|
51
|
+
return regExpEmail.test(String(email).toLowerCase());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isJwtString = (jwt) => {
|
|
55
|
+
if (jwt === '' || jwt.trim() === '') return false;
|
|
56
|
+
const jwtRegex = /^eyJ[a-zA-Z0-9-_.]+$/;
|
|
57
|
+
return jwtRegex.test(jwt);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const isPasswordString = password => {
|
|
61
|
+
if (password === undefined || typeof password !== "string" || password.length === 0) return false;
|
|
62
|
+
const regExPassword = /^(?=.*[a-zA-Z0-9])(?=.*[!@#$%^&*_-])[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
63
|
+
return regExPassword.test(String(password));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const isSimplePasswordString = password => {
|
|
67
|
+
if (password === undefined || typeof password !== "string" || password.length === 0) return false;
|
|
68
|
+
const regExPassword = /^[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
69
|
+
return regExPassword.test(String(password));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const isPasswordStringFailureMessage = (password) => {
|
|
73
|
+
if (!isPasswordString(password)) {
|
|
74
|
+
return "Total 6 to 32 characters, numbers and one of !@#$%^&*_-";
|
|
75
|
+
} else {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const isSimplePasswordStringFailureMessage = (password) => {
|
|
81
|
+
if (!isPasswordString(password)) {
|
|
82
|
+
return "Total 6 to 32 characters, numbers or !@#$%^&*_-";
|
|
83
|
+
} else {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const isUsernameString = str => {
|
|
89
|
+
if (str === undefined || typeof str !== "string" || str.length === 0) return false;
|
|
90
|
+
return (/^[0-9a-zA-Z]+$/.test(str));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function isPhoneNumber(str) {
|
|
94
|
+
if (str === undefined || typeof str !== "string" || str.length === 0) return false;
|
|
95
|
+
return (/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/.test(str));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const isUrlSafeString = (inputString) => {
|
|
99
|
+
if (inputString === '' || inputString.trim() === '') return false;
|
|
100
|
+
const jwtRegex = /^[a-zA-Z0-9-_.]+$/;
|
|
101
|
+
return jwtRegex.test(inputString);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const isString6To24CharacterLong = (password) => {
|
|
105
|
+
if (password === undefined || typeof password !== "string" || password.length === 0) return false;
|
|
106
|
+
return 6 <= password.length && password.length <= 24;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const isString6To16CharacterLong = (password) => {
|
|
110
|
+
if (password === undefined || typeof password !== "string" || password.length === 0) return false;
|
|
111
|
+
return 6 <= password.length && password.length <= 16;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const isProvinceString = (inputString) => {
|
|
115
|
+
const provinces = ['on', 'qc'];
|
|
116
|
+
|
|
117
|
+
if (isNameString(inputString)) {
|
|
118
|
+
return provinces.includes(inputString.toLowerCase());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return false
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const isBoolValue = (inputValue) => {
|
|
125
|
+
return !(inputValue === undefined || typeof inputValue !== "boolean");
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const isPostalCodeString = (inputString) => {
|
|
129
|
+
|
|
130
|
+
const postalCodeRegex = /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$/i;
|
|
131
|
+
|
|
132
|
+
if (isNameString(inputString)) {
|
|
133
|
+
return postalCodeRegex.test(inputString);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return false;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const isSafeString = (str) => {
|
|
140
|
+
|
|
141
|
+
if (str === undefined || typeof str !== "string" || str.length === 0) return false;
|
|
142
|
+
return (/^[\da-zA-Z-_.,#*'()\[\]: ]+$/.test(str));
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const isInStringArray = (StringArray, inputString) => {
|
|
147
|
+
|
|
148
|
+
if (isNameString(inputString)) {
|
|
149
|
+
return StringArray.includes(inputString.toLowerCase());
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return false
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const isCountryCodeString = (str) => {
|
|
156
|
+
|
|
157
|
+
if (str === undefined || typeof str !== "string" || str.length === 0) return false;
|
|
158
|
+
|
|
159
|
+
const postalCodeRegex = /^\+[1-9][0-9]{0,2}$/i;
|
|
160
|
+
|
|
161
|
+
return postalCodeRegex.test(str);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
module.exports = {
|
|
165
|
+
isImageUrl,
|
|
166
|
+
isInteger,
|
|
167
|
+
isValidJsonString,
|
|
168
|
+
isValidIntegerString,
|
|
169
|
+
isValidUuidString,
|
|
170
|
+
isCharactersString,
|
|
171
|
+
isNameString,
|
|
172
|
+
isSafeSearchString,
|
|
173
|
+
isEmailString,
|
|
174
|
+
isJwtString,
|
|
175
|
+
isPasswordString,
|
|
176
|
+
isSimplePasswordString,
|
|
177
|
+
isPasswordStringFailureMessage,
|
|
178
|
+
isSimplePasswordStringFailureMessage,
|
|
179
|
+
isUsernameString,
|
|
180
|
+
isPhoneNumber,
|
|
181
|
+
isUrlSafeString,
|
|
182
|
+
isString6To24CharacterLong,
|
|
183
|
+
isString6To16CharacterLong,
|
|
184
|
+
isProvinceString,
|
|
185
|
+
isBoolValue,
|
|
186
|
+
isPostalCodeString,
|
|
187
|
+
isSafeString,
|
|
188
|
+
isInStringArray,
|
|
189
|
+
isCountryCodeString
|
|
190
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Validate the property values format.
|
|
2
|
+
const {
|
|
3
|
+
isEmailString,
|
|
4
|
+
isPhoneNumber,
|
|
5
|
+
isUrlSafeString,
|
|
6
|
+
isValidUuidString,
|
|
7
|
+
isSimplePasswordString,
|
|
8
|
+
isPasswordString,
|
|
9
|
+
isString6To16CharacterLong,
|
|
10
|
+
isNameString,
|
|
11
|
+
isSafeSearchString,
|
|
12
|
+
isCharactersString,
|
|
13
|
+
isValidIntegerString,
|
|
14
|
+
isValidJsonString, isImageUrl
|
|
15
|
+
} = require( "./validate" );
|
|
16
|
+
|
|
17
|
+
function validateProperties( obj ) {
|
|
18
|
+
let returnObj = {};
|
|
19
|
+
|
|
20
|
+
for ( let [ key, value ] of Object.entries( obj || {} ) ) {
|
|
21
|
+
|
|
22
|
+
switch ( key ) {
|
|
23
|
+
case "first_name" :
|
|
24
|
+
case "username" :
|
|
25
|
+
case "newStatus":
|
|
26
|
+
case "description":
|
|
27
|
+
case "comment":
|
|
28
|
+
case "status":
|
|
29
|
+
case "name":
|
|
30
|
+
case "title" :
|
|
31
|
+
case "brand":
|
|
32
|
+
case "short_description" :
|
|
33
|
+
isNameString( value ) ?
|
|
34
|
+
returnObj[ key ] = value : null;
|
|
35
|
+
break;
|
|
36
|
+
case "search_string":
|
|
37
|
+
case "searchString":
|
|
38
|
+
isSafeSearchString( value ) ?
|
|
39
|
+
returnObj[ key ] = value : null;
|
|
40
|
+
break;
|
|
41
|
+
case "password" :
|
|
42
|
+
case "new_password" :
|
|
43
|
+
isString6To16CharacterLong( value ) && isSimplePasswordString( value ) ?
|
|
44
|
+
returnObj[ key ] = value : null;
|
|
45
|
+
break;
|
|
46
|
+
case "strong_password" :
|
|
47
|
+
isString6To16CharacterLong( value ) && isPasswordString( value ) ?
|
|
48
|
+
returnObj[ key ] = value : null;
|
|
49
|
+
break;
|
|
50
|
+
case "email" :
|
|
51
|
+
isEmailString( value ) ?
|
|
52
|
+
returnObj[ key ] = value : null;
|
|
53
|
+
break;
|
|
54
|
+
case "phone_number":
|
|
55
|
+
isPhoneNumber( value ) ?
|
|
56
|
+
returnObj[ key ] = value : null;
|
|
57
|
+
break;
|
|
58
|
+
case "token":
|
|
59
|
+
case "email_confirm_token":
|
|
60
|
+
case "verification_token":
|
|
61
|
+
isUrlSafeString( value ) ?
|
|
62
|
+
returnObj[ key ] = value : null;
|
|
63
|
+
break;
|
|
64
|
+
case "uuid":
|
|
65
|
+
case "item_id":
|
|
66
|
+
case "user_id":
|
|
67
|
+
case "userId":
|
|
68
|
+
case "image_id":
|
|
69
|
+
case "itemId":
|
|
70
|
+
case "userId":
|
|
71
|
+
case "orderId":
|
|
72
|
+
case "category_id":
|
|
73
|
+
case "parent_id":
|
|
74
|
+
isValidUuidString( value ) ?
|
|
75
|
+
returnObj[ key ] = value : null;
|
|
76
|
+
break;
|
|
77
|
+
case "period":
|
|
78
|
+
isCharactersString( value ) ?
|
|
79
|
+
returnObj[ key ] = value : null;
|
|
80
|
+
break;
|
|
81
|
+
case "offset_number":
|
|
82
|
+
case "number_of_orders":
|
|
83
|
+
case "price":
|
|
84
|
+
isValidIntegerString( value ) ?
|
|
85
|
+
returnObj[ key ] = value : null;
|
|
86
|
+
break;
|
|
87
|
+
case "about":
|
|
88
|
+
isValidJsonString( value ) ? returnObj[ key ] = value.trim() : null;
|
|
89
|
+
break;
|
|
90
|
+
case "weight":
|
|
91
|
+
case "dimensions":
|
|
92
|
+
case "permission":
|
|
93
|
+
isValidJsonString( JSON.stringify( value ) ) ? returnObj[ key ] = value : null;
|
|
94
|
+
break;
|
|
95
|
+
case "image_url":
|
|
96
|
+
isImageUrl( value ) ? returnObj[ key ] = value : null;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return returnObj;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = {
|
|
105
|
+
validateProperties
|
|
106
|
+
};
|
package/package.json
CHANGED
|
@@ -1,49 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carecard/validate",
|
|
3
|
-
"version": "
|
|
4
|
-
"private": false,
|
|
5
|
-
"description": "Validate functions",
|
|
6
|
-
"license": "ISC",
|
|
7
|
-
"author": "PK Singh",
|
|
3
|
+
"version": "2.0.2",
|
|
8
4
|
"repository": {
|
|
9
5
|
"type": "git",
|
|
10
|
-
"url": "git+https
|
|
11
|
-
},
|
|
12
|
-
"type": "module",
|
|
13
|
-
"publishConfig": {
|
|
14
|
-
"access": "public"
|
|
6
|
+
"url": "git+https://github.com/CareCard-ca/pkg-validate.git"
|
|
15
7
|
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"types": "./dist/esm/index.d.ts",
|
|
19
|
-
"exports": {
|
|
20
|
-
".": {
|
|
21
|
-
"import": "./dist/esm/index.js",
|
|
22
|
-
"require": "./dist/cjs/index.cjs",
|
|
23
|
-
"types": "./dist/esm/index.d.ts"
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"files": [
|
|
27
|
-
"dist"
|
|
28
|
-
],
|
|
8
|
+
"description": "Validate data",
|
|
9
|
+
"main": "index.js",
|
|
29
10
|
"scripts": {
|
|
30
|
-
"
|
|
31
|
-
"build:esm": "tsc -p tsconfig.esm.json",
|
|
32
|
-
"build:cjs": "tsc -p tsconfig.cjs.json && node ./scripts/rename-cjs.js",
|
|
33
|
-
"test": "NODE_NO_WARNINGS=1 jest --coverage",
|
|
34
|
-
"format": "prettier --write .",
|
|
35
|
-
"format:check": "prettier --check .",
|
|
36
|
-
"lint": "eslint",
|
|
37
|
-
"prepare": "husky"
|
|
11
|
+
"test": "export NODE_ENV=test && mocha --watch --recursive"
|
|
38
12
|
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"validate",
|
|
15
|
+
"data"
|
|
16
|
+
],
|
|
17
|
+
"author": "CareCard team",
|
|
18
|
+
"license": "ISC",
|
|
39
19
|
"devDependencies": {
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"typescript": "5.9.3",
|
|
44
|
-
"typescript-eslint": "8.50.1",
|
|
45
|
-
"prettier": "3.7.4",
|
|
46
|
-
"eslint": "9.39.2",
|
|
47
|
-
"husky": "9.1.7"
|
|
48
|
-
}
|
|
20
|
+
"mocha": "11.7.5"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {}
|
|
49
23
|
}
|
package/readme.md
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
#Validate
|
|
2
|
+
### Functions
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
It works with js or ts and commonjs and esm.
|
|
4
|
+
All functions return boolean value, false on failure
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
- Validates that a string is string of characters
|
|
7
|
+
```js
|
|
8
|
+
isStringOfCharacters(str)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- Validates that a string is fit for username
|
|
12
|
+
```js
|
|
13
|
+
isStringOfUsername(str)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- Validates that string is an email
|
|
17
|
+
```js
|
|
18
|
+
isEmail(email)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Validates that string is fit for password
|
|
22
|
+
```js
|
|
23
|
+
isStringOfPassword(password)
|
|
24
|
+
```
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./validate"), exports);
|
|
18
|
-
__exportStar(require("./validateProperties"), exports);
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/validate.cjs
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCountryCodeString = exports.isInStringArray = exports.isSafeString = exports.isPostalCodeString = exports.isBoolValue = exports.isProvinceString = exports.isString6To16CharacterLong = exports.isString6To24CharacterLong = exports.isUrlSafeString = exports.isUsernameString = exports.isSimplePasswordStringFailureMessage = exports.isPasswordStringFailureMessage = exports.isSimplePasswordString = exports.isPasswordString = exports.isJwtString = exports.isEmailString = exports.isSafeSearchString = exports.isNameString = exports.isCharactersString = exports.isValidUuidString = exports.isValidIntegerString = exports.isValidJsonString = exports.isInteger = exports.isImageUrl = void 0;
|
|
4
|
-
exports.isPhoneNumber = isPhoneNumber;
|
|
5
|
-
const isImageUrl = (imageUrl) => {
|
|
6
|
-
if (imageUrl === undefined || typeof imageUrl !== 'string' || imageUrl.length === 0)
|
|
7
|
-
return false;
|
|
8
|
-
const imageUrlRegex = /^[a-zA-Z0-9-_./]+$/;
|
|
9
|
-
return imageUrlRegex.test(imageUrl);
|
|
10
|
-
};
|
|
11
|
-
exports.isImageUrl = isImageUrl;
|
|
12
|
-
const isInteger = (number) => {
|
|
13
|
-
return Number.isInteger(number);
|
|
14
|
-
};
|
|
15
|
-
exports.isInteger = isInteger;
|
|
16
|
-
const isValidJsonString = (str) => {
|
|
17
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
18
|
-
return false;
|
|
19
|
-
try {
|
|
20
|
-
const json = JSON.parse(str);
|
|
21
|
-
return typeof json === 'object';
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
exports.isValidJsonString = isValidJsonString;
|
|
28
|
-
const isValidIntegerString = (str) => {
|
|
29
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
30
|
-
return false;
|
|
31
|
-
return /^\d+$/g.test(str);
|
|
32
|
-
};
|
|
33
|
-
exports.isValidIntegerString = isValidIntegerString;
|
|
34
|
-
const isValidUuidString = (str) => {
|
|
35
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
36
|
-
return false;
|
|
37
|
-
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);
|
|
38
|
-
};
|
|
39
|
-
exports.isValidUuidString = isValidUuidString;
|
|
40
|
-
const isCharactersString = (str) => {
|
|
41
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
42
|
-
return false;
|
|
43
|
-
return /^[\da-zA-Z _-]+$/.test(str);
|
|
44
|
-
};
|
|
45
|
-
exports.isCharactersString = isCharactersString;
|
|
46
|
-
const isNameString = (str) => {
|
|
47
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
48
|
-
return false;
|
|
49
|
-
return /^[A-Za-z][0-9a-zA-Z-_.,'() ]+$/.test(str.trim());
|
|
50
|
-
};
|
|
51
|
-
exports.isNameString = isNameString;
|
|
52
|
-
const isSafeSearchString = (str) => {
|
|
53
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
54
|
-
return false;
|
|
55
|
-
return /^[A-Za-z][0-9a-zA-Z\-_.,'()@ ]{1,100}$/.test(str.trim());
|
|
56
|
-
};
|
|
57
|
-
exports.isSafeSearchString = isSafeSearchString;
|
|
58
|
-
const isEmailString = (email) => {
|
|
59
|
-
if (email === undefined || typeof email !== 'string' || email.length === 0)
|
|
60
|
-
return false;
|
|
61
|
-
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,}))$/;
|
|
62
|
-
return regExpEmail.test(String(email).toLowerCase());
|
|
63
|
-
};
|
|
64
|
-
exports.isEmailString = isEmailString;
|
|
65
|
-
const isJwtString = (jwt) => {
|
|
66
|
-
if (jwt === '' || jwt.trim() === '')
|
|
67
|
-
return false;
|
|
68
|
-
const jwtRegex = /^eyJ[a-zA-Z0-9-_.]+$/;
|
|
69
|
-
return jwtRegex.test(jwt);
|
|
70
|
-
};
|
|
71
|
-
exports.isJwtString = isJwtString;
|
|
72
|
-
const isPasswordString = (password) => {
|
|
73
|
-
if (password === undefined || typeof password !== 'string' || password.length === 0)
|
|
74
|
-
return false;
|
|
75
|
-
const regExPassword = /^(?=.*[a-zA-Z0-9])(?=.*[!@#$%^&*_-])[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
76
|
-
return regExPassword.test(String(password));
|
|
77
|
-
};
|
|
78
|
-
exports.isPasswordString = isPasswordString;
|
|
79
|
-
const isSimplePasswordString = (password) => {
|
|
80
|
-
if (password === undefined || typeof password !== 'string' || password.length === 0)
|
|
81
|
-
return false;
|
|
82
|
-
const regExPassword = /^[a-zA-Z0-9!@#$%^&*_-]{6,32}$/;
|
|
83
|
-
return regExPassword.test(String(password));
|
|
84
|
-
};
|
|
85
|
-
exports.isSimplePasswordString = isSimplePasswordString;
|
|
86
|
-
const isPasswordStringFailureMessage = (password) => {
|
|
87
|
-
if (!(0, exports.isPasswordString)(password)) {
|
|
88
|
-
return 'Total 6 to 32 characters, numbers and one of !@#$%^&*_-';
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
exports.isPasswordStringFailureMessage = isPasswordStringFailureMessage;
|
|
95
|
-
const isSimplePasswordStringFailureMessage = (password) => {
|
|
96
|
-
if (!(0, exports.isPasswordString)(password)) {
|
|
97
|
-
return 'Total 6 to 32 characters, numbers or !@#$%^&*_-';
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
exports.isSimplePasswordStringFailureMessage = isSimplePasswordStringFailureMessage;
|
|
104
|
-
const isUsernameString = (str) => {
|
|
105
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
106
|
-
return false;
|
|
107
|
-
return /^[0-9a-zA-Z]+$/.test(str);
|
|
108
|
-
};
|
|
109
|
-
exports.isUsernameString = isUsernameString;
|
|
110
|
-
function isPhoneNumber(str) {
|
|
111
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
112
|
-
return false;
|
|
113
|
-
return /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/.test(str);
|
|
114
|
-
}
|
|
115
|
-
const isUrlSafeString = (inputString) => {
|
|
116
|
-
if (inputString === '' || inputString.trim() === '')
|
|
117
|
-
return false;
|
|
118
|
-
const jwtRegex = /^[a-zA-Z0-9-_.]+$/;
|
|
119
|
-
return jwtRegex.test(inputString);
|
|
120
|
-
};
|
|
121
|
-
exports.isUrlSafeString = isUrlSafeString;
|
|
122
|
-
const isString6To24CharacterLong = (password) => {
|
|
123
|
-
if (password === undefined || typeof password !== 'string' || password.length === 0)
|
|
124
|
-
return false;
|
|
125
|
-
return 6 <= password.length && password.length <= 24;
|
|
126
|
-
};
|
|
127
|
-
exports.isString6To24CharacterLong = isString6To24CharacterLong;
|
|
128
|
-
const isString6To16CharacterLong = (password) => {
|
|
129
|
-
if (password === undefined || typeof password !== 'string' || password.length === 0)
|
|
130
|
-
return false;
|
|
131
|
-
return 6 <= password.length && password.length <= 16;
|
|
132
|
-
};
|
|
133
|
-
exports.isString6To16CharacterLong = isString6To16CharacterLong;
|
|
134
|
-
const isProvinceString = (inputString) => {
|
|
135
|
-
const provinces = ['on', 'qc'];
|
|
136
|
-
if ((0, exports.isNameString)(inputString)) {
|
|
137
|
-
return provinces.includes(inputString.toLowerCase());
|
|
138
|
-
}
|
|
139
|
-
return false;
|
|
140
|
-
};
|
|
141
|
-
exports.isProvinceString = isProvinceString;
|
|
142
|
-
const isBoolValue = (inputValue) => {
|
|
143
|
-
return !(inputValue === undefined || typeof inputValue !== 'boolean');
|
|
144
|
-
};
|
|
145
|
-
exports.isBoolValue = isBoolValue;
|
|
146
|
-
const isPostalCodeString = (inputString) => {
|
|
147
|
-
const postalCodeRegex = /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] ?[0-9][A-Z][0-9]$/i;
|
|
148
|
-
if ((0, exports.isNameString)(inputString)) {
|
|
149
|
-
return postalCodeRegex.test(inputString);
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
152
|
-
};
|
|
153
|
-
exports.isPostalCodeString = isPostalCodeString;
|
|
154
|
-
const isSafeString = (str) => {
|
|
155
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
156
|
-
return false;
|
|
157
|
-
return /^[\da-zA-Z-_.,#*'()\[\]: ]+$/.test(str);
|
|
158
|
-
};
|
|
159
|
-
exports.isSafeString = isSafeString;
|
|
160
|
-
const isInStringArray = (StringArray, inputString) => {
|
|
161
|
-
if ((0, exports.isNameString)(inputString)) {
|
|
162
|
-
return StringArray.includes(inputString.toLowerCase());
|
|
163
|
-
}
|
|
164
|
-
return false;
|
|
165
|
-
};
|
|
166
|
-
exports.isInStringArray = isInStringArray;
|
|
167
|
-
const isCountryCodeString = (str) => {
|
|
168
|
-
if (str === undefined || typeof str !== 'string' || str.length === 0)
|
|
169
|
-
return false;
|
|
170
|
-
const postalCodeRegex = /^\+[1-9][0-9]{0,2}$/i;
|
|
171
|
-
return postalCodeRegex.test(str);
|
|
172
|
-
};
|
|
173
|
-
exports.isCountryCodeString = isCountryCodeString;
|
package/dist/cjs/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;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateProperties = validateProperties;
|
|
4
|
-
// Validate the property values format.
|
|
5
|
-
const validate_1 = require("./validate");
|
|
6
|
-
function validateProperties(obj = {}) {
|
|
7
|
-
let returnObj = {};
|
|
8
|
-
for (let [key, value] of Object.entries(obj || {})) {
|
|
9
|
-
switch (key) {
|
|
10
|
-
case 'first_name':
|
|
11
|
-
case 'username':
|
|
12
|
-
case 'newStatus':
|
|
13
|
-
case 'description':
|
|
14
|
-
case 'comment':
|
|
15
|
-
case 'status':
|
|
16
|
-
case 'name':
|
|
17
|
-
case 'title':
|
|
18
|
-
case 'brand':
|
|
19
|
-
case 'short_description':
|
|
20
|
-
(0, validate_1.isNameString)(value) ? (returnObj[key] = value) : null;
|
|
21
|
-
break;
|
|
22
|
-
case 'search_string':
|
|
23
|
-
case 'searchString':
|
|
24
|
-
(0, validate_1.isSafeSearchString)(value) ? (returnObj[key] = value) : null;
|
|
25
|
-
break;
|
|
26
|
-
case 'password':
|
|
27
|
-
case 'new_password':
|
|
28
|
-
(0, validate_1.isString6To16CharacterLong)(value) && (0, validate_1.isSimplePasswordString)(value)
|
|
29
|
-
? (returnObj[key] = value)
|
|
30
|
-
: null;
|
|
31
|
-
break;
|
|
32
|
-
case 'strong_password':
|
|
33
|
-
(0, validate_1.isString6To16CharacterLong)(value) && (0, validate_1.isPasswordString)(value)
|
|
34
|
-
? (returnObj[key] = value)
|
|
35
|
-
: null;
|
|
36
|
-
break;
|
|
37
|
-
case 'email':
|
|
38
|
-
(0, validate_1.isEmailString)(value) ? (returnObj[key] = value) : null;
|
|
39
|
-
break;
|
|
40
|
-
case 'phone_number':
|
|
41
|
-
(0, validate_1.isPhoneNumber)(value) ? (returnObj[key] = value) : null;
|
|
42
|
-
break;
|
|
43
|
-
case 'token':
|
|
44
|
-
case 'email_confirm_token':
|
|
45
|
-
case 'verification_token':
|
|
46
|
-
(0, validate_1.isUrlSafeString)(value) ? (returnObj[key] = value) : null;
|
|
47
|
-
break;
|
|
48
|
-
case 'uuid':
|
|
49
|
-
case 'item_id':
|
|
50
|
-
case 'user_id':
|
|
51
|
-
case 'image_id':
|
|
52
|
-
case 'itemId':
|
|
53
|
-
case 'userId':
|
|
54
|
-
case 'orderId':
|
|
55
|
-
case 'category_id':
|
|
56
|
-
case 'parent_id':
|
|
57
|
-
(0, validate_1.isValidUuidString)(value) ? (returnObj[key] = value) : null;
|
|
58
|
-
break;
|
|
59
|
-
case 'period':
|
|
60
|
-
(0, validate_1.isCharactersString)(value) ? (returnObj[key] = value) : null;
|
|
61
|
-
break;
|
|
62
|
-
case 'offset_number':
|
|
63
|
-
case 'number_of_orders':
|
|
64
|
-
case 'price':
|
|
65
|
-
(0, validate_1.isValidIntegerString)(value) ? (returnObj[key] = value) : null;
|
|
66
|
-
break;
|
|
67
|
-
case 'about':
|
|
68
|
-
(0, validate_1.isValidJsonString)(value) ? (returnObj[key] = value.trim()) : null;
|
|
69
|
-
break;
|
|
70
|
-
case 'weight':
|
|
71
|
-
case 'dimensions':
|
|
72
|
-
case 'permission':
|
|
73
|
-
(0, validate_1.isValidJsonString)(JSON.stringify(value)) ? (returnObj[key] = value) : null;
|
|
74
|
-
break;
|
|
75
|
-
case 'image_url':
|
|
76
|
-
(0, validate_1.isImageUrl)(value) ? (returnObj[key] = value) : null;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return returnObj;
|
|
81
|
-
}
|
package/dist/esm/index.d.ts
DELETED
package/dist/esm/index.js
DELETED
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
|
-
}
|