@takentrade/takentrade-libs 3.1.0 → 3.2.1

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.
@@ -1,2 +1,10 @@
1
- export declare function formatPhoneNumber(phone: string): string;
2
- export declare function maskPhoneNumber(phone: string): string;
1
+ /**
2
+ * Formats phone number for display
3
+ * 2348012345678 → +234 801 234 5678
4
+ */
5
+ export declare const formatPhoneNumber: (phone: string) => string;
6
+ /**
7
+ * Masks phone number for security
8
+ * +2348012345678 → +234****5678
9
+ */
10
+ export declare const maskPhoneNumber: (phone: string) => string;
@@ -1,17 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maskPhoneNumber = exports.formatPhoneNumber = void 0;
4
+ /**
5
+ * Formats phone number for display
6
+ * 2348012345678 → +234 801 234 5678
7
+ */
8
+ const formatPhoneNumber = (phone) => {
9
+ const cleaned = phone.replace(/[\s\-\(\)]/g, '');
10
+ // Ensure it starts with 234
11
+ let formatted = cleaned;
12
+ if (formatted.startsWith('0')) {
13
+ formatted = '234' + formatted.substring(1);
14
+ }
15
+ // Format as +234 801 234 5678
16
+ if (formatted.startsWith('234')) {
17
+ return `+234 ${formatted.substring(3, 6)} ${formatted.substring(6, 9)} ${formatted.substring(9)}`;
18
+ }
19
+ return phone;
20
+ };
3
21
  exports.formatPhoneNumber = formatPhoneNumber;
22
+ /**
23
+ * Masks phone number for security
24
+ * +2348012345678 → +234****5678
25
+ */
26
+ const maskPhoneNumber = (phone) => {
27
+ const cleaned = phone.replace(/[\s\-\(\)]/g, '');
28
+ if (cleaned.length < 8)
29
+ return phone;
30
+ const prefix = cleaned.substring(0, 4);
31
+ const suffix = cleaned.slice(-4);
32
+ return `${prefix}****${suffix}`;
33
+ };
4
34
  exports.maskPhoneNumber = maskPhoneNumber;
5
- function formatPhoneNumber(phone) {
6
- // Remove any non-digit characters
7
- const cleaned = phone.replace(/\D/g, '');
8
- // Ensure the number starts with country code
9
- if (!cleaned.startsWith('234') && cleaned.startsWith('0')) {
10
- return '234' + cleaned.slice(1);
11
- }
12
- return cleaned;
13
- }
14
- function maskPhoneNumber(phone) {
15
- const cleaned = formatPhoneNumber(phone);
16
- return (cleaned.slice(0, 4) + '*'.repeat(cleaned.length - 7) + cleaned.slice(-3));
17
- }