@cranberry-money/shared-utils 3.0.1 → 3.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/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@
4
4
  export * from './formatters';
5
5
  export * from './helpers';
6
6
  export * from './portfolio';
7
+ export * from './validation';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@
4
4
  export * from './formatters';
5
5
  export * from './helpers';
6
6
  export * from './portfolio';
7
+ export * from './validation';
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Validation utility functions
3
+ * Common validation logic for forms and data
4
+ */
5
+ import type { PasswordValidation, TokenValidation } from '@cranberry-money/shared-types';
6
+ /**
7
+ * Validation rule constants
8
+ */
9
+ export declare const VALIDATION_RULES: {
10
+ readonly PASSWORD_MIN_LENGTH: 8;
11
+ readonly TOKEN_MIN_LENGTH: 6;
12
+ readonly TOKEN_MAX_LENGTH: 20;
13
+ };
14
+ /**
15
+ * Checks if a string contains only numeric characters
16
+ * @param str - The string to validate
17
+ * @returns true if the string contains only digits, false otherwise
18
+ */
19
+ export declare const isNumericOnly: (str: string) => boolean;
20
+ /**
21
+ * Validates password strength based on application requirements
22
+ * @param password - The password to validate
23
+ * @returns An object containing validation results
24
+ */
25
+ export declare const validatePassword: (password: string) => PasswordValidation;
26
+ /**
27
+ * Validates if a verification token is in the expected format
28
+ * @param token - The verification token to validate
29
+ * @returns true if token appears to be valid format, false otherwise
30
+ */
31
+ export declare const isValidTokenFormat: (token: string) => boolean;
32
+ /**
33
+ * Formats a verification token by removing whitespace and converting to uppercase
34
+ * @param token - The token to format
35
+ * @returns The formatted token
36
+ */
37
+ export declare const formatVerificationToken: (token: string) => string;
38
+ /**
39
+ * Validates email confirmation form data
40
+ * @param token - The verification token
41
+ * @returns An object containing validation results
42
+ */
43
+ export declare const validateEmailConfirmation: (token: string) => TokenValidation;
44
+ /**
45
+ * Validates email format
46
+ * @param email - The email to validate
47
+ * @returns true if email format is valid
48
+ */
49
+ export declare const isValidEmail: (email: string) => boolean;
50
+ /**
51
+ * Validates phone number format (basic validation)
52
+ * @param phone - The phone number to validate
53
+ * @returns true if phone format is valid
54
+ */
55
+ export declare const isValidPhone: (phone: string) => boolean;
56
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEzF;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;CAInB,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,KAAG,OAE3C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,KAAG,kBAKnD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,OAQlD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,MAEvD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,OAAO,MAAM,KAAG,eAQzD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,OAG5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,OAK5C,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Validation utility functions
3
+ * Common validation logic for forms and data
4
+ */
5
+ /**
6
+ * Validation rule constants
7
+ */
8
+ export const VALIDATION_RULES = {
9
+ PASSWORD_MIN_LENGTH: 8,
10
+ TOKEN_MIN_LENGTH: 6,
11
+ TOKEN_MAX_LENGTH: 20,
12
+ };
13
+ /**
14
+ * Checks if a string contains only numeric characters
15
+ * @param str - The string to validate
16
+ * @returns true if the string contains only digits, false otherwise
17
+ */
18
+ export const isNumericOnly = (str) => {
19
+ return /^\d+$/.test(str);
20
+ };
21
+ /**
22
+ * Validates password strength based on application requirements
23
+ * @param password - The password to validate
24
+ * @returns An object containing validation results
25
+ */
26
+ export const validatePassword = (password) => {
27
+ return {
28
+ lengthValid: password.length >= VALIDATION_RULES.PASSWORD_MIN_LENGTH,
29
+ notNumeric: !isNumericOnly(password),
30
+ };
31
+ };
32
+ /**
33
+ * Validates if a verification token is in the expected format
34
+ * @param token - The verification token to validate
35
+ * @returns true if token appears to be valid format, false otherwise
36
+ */
37
+ export const isValidTokenFormat = (token) => {
38
+ const trimmedToken = token.trim();
39
+ // Tokens are alphanumeric and within length limits
40
+ return (trimmedToken.length >= VALIDATION_RULES.TOKEN_MIN_LENGTH &&
41
+ trimmedToken.length <= VALIDATION_RULES.TOKEN_MAX_LENGTH &&
42
+ /^[a-zA-Z0-9]+$/.test(trimmedToken));
43
+ };
44
+ /**
45
+ * Formats a verification token by removing whitespace and converting to uppercase
46
+ * @param token - The token to format
47
+ * @returns The formatted token
48
+ */
49
+ export const formatVerificationToken = (token) => {
50
+ return token.trim().toUpperCase();
51
+ };
52
+ /**
53
+ * Validates email confirmation form data
54
+ * @param token - The verification token
55
+ * @returns An object containing validation results
56
+ */
57
+ export const validateEmailConfirmation = (token) => {
58
+ const formattedToken = formatVerificationToken(token);
59
+ return {
60
+ isValid: formattedToken.length > 0 && isValidTokenFormat(formattedToken),
61
+ isEmpty: formattedToken.length === 0,
62
+ isValidFormat: isValidTokenFormat(formattedToken),
63
+ };
64
+ };
65
+ /**
66
+ * Validates email format
67
+ * @param email - The email to validate
68
+ * @returns true if email format is valid
69
+ */
70
+ export const isValidEmail = (email) => {
71
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
72
+ return emailRegex.test(email);
73
+ };
74
+ /**
75
+ * Validates phone number format (basic validation)
76
+ * @param phone - The phone number to validate
77
+ * @returns true if phone format is valid
78
+ */
79
+ export const isValidPhone = (phone) => {
80
+ // Remove common formatting characters
81
+ const cleaned = phone.replace(/[\s\-\(\)]/g, '');
82
+ // Check if it's numeric and reasonable length
83
+ return /^\+?\d{10,15}$/.test(cleaned);
84
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cranberry-money/shared-utils",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Shared utility functions for MyPortfolio platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,7 +22,8 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@cranberry-money/shared-constants": "^3.0.0",
25
- "@cranberry-money/shared-services": "^3.0.0"
25
+ "@cranberry-money/shared-services": "^3.0.0",
26
+ "@cranberry-money/shared-types": "^3.0.4"
26
27
  },
27
28
  "devDependencies": {
28
29
  "typescript": "^5.0.0"