@carecard/validate 2.2.11 → 3.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/index.d.ts +68 -0
- package/lib/validateProperties.js +6 -0
- package/package.json +9 -3
package/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for validating various types of strings and values.
|
|
3
|
+
*/
|
|
4
|
+
export const validate: {
|
|
5
|
+
/** Checks if the string is a valid image URL format. */
|
|
6
|
+
isImageUrl: (imageUrl: any) => boolean;
|
|
7
|
+
/** Checks if the value is an integer. */
|
|
8
|
+
isInteger: (number: any) => boolean;
|
|
9
|
+
/** Checks if the string is a valid JSON string and can be parsed into an object. */
|
|
10
|
+
isValidJsonString: (str: any) => boolean;
|
|
11
|
+
/** Checks if the string represents a valid integer. */
|
|
12
|
+
isValidIntegerString: (str: any) => boolean;
|
|
13
|
+
/** Checks if the string is a valid UUID. */
|
|
14
|
+
isValidUuidString: (str: any) => boolean;
|
|
15
|
+
/** Checks if the string contains only alphanumeric characters, spaces, underscores, or hyphens. */
|
|
16
|
+
isCharactersString: (str: any) => boolean;
|
|
17
|
+
/** Checks if the string is a valid name format. */
|
|
18
|
+
isNameString: (str: any) => boolean;
|
|
19
|
+
/** Checks if the string is safe for search queries. */
|
|
20
|
+
isSafeSearchString: (str: any) => boolean;
|
|
21
|
+
/** Checks if the string is a valid email address. */
|
|
22
|
+
isEmailString: (email: any) => boolean;
|
|
23
|
+
/** Checks if the string is a valid JWT format. */
|
|
24
|
+
isJwtString: (jwt: any) => boolean;
|
|
25
|
+
/** Checks if the string is a valid strong password. */
|
|
26
|
+
isPasswordString: (password: any) => boolean;
|
|
27
|
+
/** Checks if the string is a valid simple password. */
|
|
28
|
+
isSimplePasswordString: (password: any) => boolean;
|
|
29
|
+
/** Returns a failure message if the password is not strong enough. */
|
|
30
|
+
isPasswordStringFailureMessage: (password: any) => string | null;
|
|
31
|
+
/** Returns a failure message if the password is not valid as a simple password. */
|
|
32
|
+
isSimplePasswordStringFailureMessage: (password: any) => string | null;
|
|
33
|
+
/** Checks if the string is a valid username. */
|
|
34
|
+
isUsernameString: (str: any) => boolean;
|
|
35
|
+
/** Checks if the string is a valid phone number. */
|
|
36
|
+
isPhoneNumber: (str: any) => boolean;
|
|
37
|
+
/** Checks if the string is URL-safe. */
|
|
38
|
+
isUrlSafeString: (inputString: any) => boolean;
|
|
39
|
+
/** Checks if the string length is between 6 and 24 characters. */
|
|
40
|
+
isString6To24CharacterLong: (password: any) => boolean;
|
|
41
|
+
/** Checks if the string length is between 6 and 16 characters. */
|
|
42
|
+
isString6To16CharacterLong: (password: any) => boolean;
|
|
43
|
+
/** Checks if the string is a valid Canadian province abbreviation (ON, QC). */
|
|
44
|
+
isProvinceString: (inputString: any) => boolean;
|
|
45
|
+
/** Checks if the value is a boolean. */
|
|
46
|
+
isBoolValue: (inputValue: any) => boolean;
|
|
47
|
+
/** Checks if the string is a valid Canadian postal code. */
|
|
48
|
+
isPostalCodeString: (inputString: any) => boolean;
|
|
49
|
+
/** Checks if the string contains only allowed "safe" characters. */
|
|
50
|
+
isSafeString: (str: any) => boolean;
|
|
51
|
+
/** Checks if a string exists within a given array of strings (case-insensitive). */
|
|
52
|
+
isInStringArray: (StringArray: string[], inputString: any) => boolean;
|
|
53
|
+
/** Checks if the string is a valid country code (e.g., +1). */
|
|
54
|
+
isCountryCodeString: (str: any) => boolean;
|
|
55
|
+
/** Checks if the string is a valid domain name. */
|
|
56
|
+
isValidDomainName: (domain: any) => boolean;
|
|
57
|
+
/** Checks if the string is a valid ISO 8601 timestamp with time zone. */
|
|
58
|
+
isValidTimestampzString: (str: any) => boolean;
|
|
59
|
+
/** Checks if the string is a valid ISO 8601 timestamp without time zone. */
|
|
60
|
+
isValidTimestampString: (str: any) => boolean;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Utility function to validate multiple properties of an object at once.
|
|
65
|
+
*/
|
|
66
|
+
export const validateProperties: {
|
|
67
|
+
validateProperties: (obj?: Record<string, any>) => Record<string, any>;
|
|
68
|
+
};
|
|
@@ -16,6 +16,7 @@ const {
|
|
|
16
16
|
isValidDomainName,
|
|
17
17
|
isValidTimestampzString,
|
|
18
18
|
isValidTimestampString,
|
|
19
|
+
isBoolValue,
|
|
19
20
|
} = require('./validate');
|
|
20
21
|
|
|
21
22
|
function validateProperties(obj = {}) {
|
|
@@ -156,6 +157,11 @@ function validateProperties(obj = {}) {
|
|
|
156
157
|
returnObj[key] = value;
|
|
157
158
|
}
|
|
158
159
|
break;
|
|
160
|
+
case 'active':
|
|
161
|
+
if (isBoolValue(value)) {
|
|
162
|
+
returnObj[key] = value;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
159
165
|
}
|
|
160
166
|
}
|
|
161
167
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carecard/validate",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/CareCard-ca/pkg-validate.git"
|
|
7
7
|
},
|
|
8
8
|
"description": "Validate data",
|
|
9
9
|
"main": "index.js",
|
|
10
|
+
"types": "index.d.ts",
|
|
10
11
|
"scripts": {
|
|
11
|
-
"test": "export NODE_ENV=test && mocha --recursive"
|
|
12
|
+
"test": "export NODE_ENV=test && mocha --recursive",
|
|
13
|
+
"test:types": "tsc --noEmit && mocha -r ts-node/register test/types.test.ts"
|
|
12
14
|
},
|
|
13
15
|
"keywords": [
|
|
14
16
|
"validate",
|
|
@@ -17,6 +19,10 @@
|
|
|
17
19
|
"author": "CareCard team",
|
|
18
20
|
"license": "ISC",
|
|
19
21
|
"devDependencies": {
|
|
20
|
-
"mocha": "
|
|
22
|
+
"@types/mocha": "10.0.10",
|
|
23
|
+
"@types/node": "25.5.0",
|
|
24
|
+
"mocha": "11.7.5",
|
|
25
|
+
"ts-node": "10.9.2",
|
|
26
|
+
"typescript": "5.9.3"
|
|
21
27
|
}
|
|
22
28
|
}
|