@takentrade/takentrade-libs 3.2.2 → 3.2.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.
@@ -47,7 +47,7 @@ export declare const isValidTransactionReference: (ref: string) => boolean;
47
47
  * Sanitizes phone number to standard format
48
48
  * Converts to: 2348012345678
49
49
  */
50
- export declare const sanitizePhoneNumber: (phone: string) => string;
50
+ export declare const sanitizePhoneNumber: (phone: string, withPlus?: boolean) => string;
51
51
  /**
52
52
  * Validates date is not in the past
53
53
  */
@@ -66,10 +66,7 @@ const isStrongPassword = (password) => {
66
66
  const hasUpperCase = /[A-Z]/.test(password);
67
67
  const hasLowerCase = /[a-z]/.test(password);
68
68
  const hasNumber = /\d/.test(password);
69
- return (password.length >= minLength &&
70
- hasUpperCase &&
71
- hasLowerCase &&
72
- hasNumber);
69
+ return (password.length >= minLength && hasUpperCase && hasLowerCase && hasNumber);
73
70
  };
74
71
  exports.isStrongPassword = isStrongPassword;
75
72
  /**
@@ -91,19 +88,27 @@ exports.isValidTransactionReference = isValidTransactionReference;
91
88
  * Sanitizes phone number to standard format
92
89
  * Converts to: 2348012345678
93
90
  */
94
- const sanitizePhoneNumber = (phone) => {
95
- const cleaned = phone.replace(/[\s\-\(\)]/g, '');
96
- // Remove leading + if present
97
- let sanitized = cleaned.replace(/^\+/, '');
98
- // Convert 0801... to 234801...
99
- if (sanitized.startsWith('0')) {
100
- sanitized = '234' + sanitized.substring(1);
91
+ const sanitizePhoneNumber = (phone, withPlus = false) => {
92
+ if (!phone)
93
+ return '';
94
+ const digits = phone.replace(/\D/g, '');
95
+ if (digits.startsWith('234') && digits.length >= 13) {
96
+ return withPlus ? '+' + digits : digits;
97
+ }
98
+ if (digits.startsWith('0') && digits.length === 11) {
99
+ const result = '234' + digits.substring(1);
100
+ return withPlus ? '+' + result : result;
101
+ }
102
+ if (digits.length === 10 && /^[789]/.test(digits)) {
103
+ const result = '234' + digits;
104
+ return withPlus ? '+' + result : result;
101
105
  }
102
- // Ensure it starts with 234
103
- if (!sanitized.startsWith('234')) {
104
- sanitized = '234' + sanitized;
106
+ if (digits.startsWith('234')) {
107
+ return withPlus ? '+' + digits : digits;
105
108
  }
106
- return sanitized;
109
+ const cleaned = digits.replace(/^0+/, '').slice(0, 10);
110
+ const result = '234' + cleaned;
111
+ return withPlus ? '+' + result : result;
107
112
  };
108
113
  exports.sanitizePhoneNumber = sanitizePhoneNumber;
109
114
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takentrade/takentrade-libs",
3
- "version": "3.2.2",
3
+ "version": "3.2.3",
4
4
  "description": "TakeNTrade shared libraries",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",