@temboplus/frontend-core 0.2.1 → 0.2.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.
Files changed (170) hide show
  1. package/README.md +64 -25
  2. package/esm/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
  3. package/esm/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
  4. package/esm/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
  5. package/esm/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
  6. package/esm/src/data/banks_tz.d.ts.map +1 -0
  7. package/esm/src/data/countries.d.ts +6 -0
  8. package/esm/src/data/countries.d.ts.map +1 -0
  9. package/esm/src/data/countries.js +974 -0
  10. package/esm/src/data/currencies.d.ts +1901 -0
  11. package/esm/src/data/currencies.d.ts.map +1 -0
  12. package/esm/src/data/currencies.js +1073 -0
  13. package/esm/src/data/phone_patterns.d.ts +3809 -0
  14. package/esm/src/data/phone_patterns.d.ts.map +1 -0
  15. package/esm/src/data/phone_patterns.js +2325 -0
  16. package/esm/src/models/amount/amount.d.ts +10 -12
  17. package/esm/src/models/amount/amount.d.ts.map +1 -1
  18. package/esm/src/models/amount/amount.js +58 -96
  19. package/esm/src/models/bank/bank.d.ts +58 -53
  20. package/esm/src/models/bank/bank.d.ts.map +1 -1
  21. package/esm/src/models/bank/bank.js +49 -84
  22. package/esm/src/models/bank/index.d.ts +1 -1
  23. package/esm/src/models/bank/index.d.ts.map +1 -1
  24. package/esm/src/models/bank/index.js +1 -1
  25. package/esm/src/models/bank/service.d.ts +106 -0
  26. package/esm/src/models/bank/service.d.ts.map +1 -0
  27. package/esm/src/models/bank/service.js +240 -0
  28. package/esm/src/models/country/country.d.ts +568 -0
  29. package/esm/src/models/country/country.d.ts.map +1 -0
  30. package/esm/src/models/country/country.js +165 -0
  31. package/esm/src/models/country/country.test.d.ts.map +1 -0
  32. package/esm/src/models/country/index.d.ts +3 -0
  33. package/esm/src/models/country/index.d.ts.map +1 -0
  34. package/esm/src/models/country/index.js +2 -0
  35. package/esm/src/models/country/service.d.ts +75 -0
  36. package/esm/src/models/country/service.d.ts.map +1 -0
  37. package/esm/src/models/country/service.js +267 -0
  38. package/esm/src/models/currency/currency.d.ts +341 -0
  39. package/esm/src/models/currency/currency.d.ts.map +1 -0
  40. package/esm/src/models/currency/currency.js +225 -0
  41. package/esm/src/models/currency/currency.test.d.ts.map +1 -0
  42. package/esm/src/models/currency/index.d.ts +3 -0
  43. package/esm/src/models/currency/index.d.ts.map +1 -0
  44. package/esm/src/models/currency/index.js +2 -0
  45. package/esm/src/models/currency/service.d.ts +96 -0
  46. package/esm/src/models/currency/service.d.ts.map +1 -0
  47. package/esm/src/models/currency/service.js +194 -0
  48. package/esm/src/models/index.d.ts +2 -0
  49. package/esm/src/models/index.d.ts.map +1 -1
  50. package/esm/src/models/index.js +2 -0
  51. package/esm/src/models/phone_number/format.d.ts +14 -0
  52. package/esm/src/models/phone_number/format.d.ts.map +1 -0
  53. package/esm/src/models/phone_number/format.js +14 -0
  54. package/esm/src/models/phone_number/global/phone_number.d.ts +160 -0
  55. package/esm/src/models/phone_number/global/phone_number.d.ts.map +1 -0
  56. package/esm/src/models/phone_number/global/phone_number.js +453 -0
  57. package/esm/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
  58. package/esm/src/models/phone_number/global/service.d.ts +260 -0
  59. package/esm/src/models/phone_number/global/service.d.ts.map +1 -0
  60. package/esm/src/models/phone_number/global/service.js +477 -0
  61. package/esm/src/models/phone_number/global/service.test.d.ts.map +1 -0
  62. package/esm/src/models/phone_number/index.d.ts +5 -3
  63. package/esm/src/models/phone_number/index.d.ts.map +1 -1
  64. package/esm/src/models/phone_number/index.js +5 -3
  65. package/esm/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
  66. package/esm/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
  67. package/esm/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +2 -2
  68. package/esm/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
  69. package/esm/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
  70. package/{script/src/models/phone_number → esm/src/models/phone_number/tz}/phone_number.d.ts +46 -29
  71. package/esm/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
  72. package/esm/src/models/phone_number/{phone_number.js → tz/phone_number.js} +87 -41
  73. package/esm/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
  74. package/package.json +3 -3
  75. package/script/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
  76. package/script/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
  77. package/script/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
  78. package/script/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
  79. package/script/src/data/banks_tz.d.ts.map +1 -0
  80. package/script/src/data/countries.d.ts +6 -0
  81. package/script/src/data/countries.d.ts.map +1 -0
  82. package/script/src/data/countries.js +976 -0
  83. package/script/src/data/currencies.d.ts +1901 -0
  84. package/script/src/data/currencies.d.ts.map +1 -0
  85. package/script/src/data/currencies.js +1075 -0
  86. package/script/src/data/phone_patterns.d.ts +3809 -0
  87. package/script/src/data/phone_patterns.d.ts.map +1 -0
  88. package/script/src/data/phone_patterns.js +2327 -0
  89. package/script/src/models/amount/amount.d.ts +10 -12
  90. package/script/src/models/amount/amount.d.ts.map +1 -1
  91. package/script/src/models/amount/amount.js +60 -98
  92. package/script/src/models/bank/bank.d.ts +58 -53
  93. package/script/src/models/bank/bank.d.ts.map +1 -1
  94. package/script/src/models/bank/bank.js +49 -87
  95. package/script/src/models/bank/index.d.ts +1 -1
  96. package/script/src/models/bank/index.d.ts.map +1 -1
  97. package/script/src/models/bank/index.js +1 -1
  98. package/script/src/models/bank/service.d.ts +106 -0
  99. package/script/src/models/bank/service.d.ts.map +1 -0
  100. package/script/src/models/bank/service.js +247 -0
  101. package/script/src/models/country/country.d.ts +568 -0
  102. package/script/src/models/country/country.d.ts.map +1 -0
  103. package/script/src/models/country/country.js +169 -0
  104. package/script/src/models/country/country.test.d.ts.map +1 -0
  105. package/script/src/models/country/index.d.ts +3 -0
  106. package/script/src/models/country/index.d.ts.map +1 -0
  107. package/script/src/models/country/index.js +18 -0
  108. package/script/src/models/country/service.d.ts +75 -0
  109. package/script/src/models/country/service.d.ts.map +1 -0
  110. package/script/src/models/country/service.js +274 -0
  111. package/script/src/models/currency/currency.d.ts +341 -0
  112. package/script/src/models/currency/currency.d.ts.map +1 -0
  113. package/script/src/models/currency/currency.js +229 -0
  114. package/script/src/models/currency/currency.test.d.ts.map +1 -0
  115. package/script/src/models/currency/index.d.ts +3 -0
  116. package/script/src/models/currency/index.d.ts.map +1 -0
  117. package/script/src/models/currency/index.js +18 -0
  118. package/script/src/models/currency/service.d.ts +96 -0
  119. package/script/src/models/currency/service.d.ts.map +1 -0
  120. package/script/src/models/currency/service.js +201 -0
  121. package/script/src/models/index.d.ts +2 -0
  122. package/script/src/models/index.d.ts.map +1 -1
  123. package/script/src/models/index.js +2 -0
  124. package/script/src/models/phone_number/format.d.ts +14 -0
  125. package/script/src/models/phone_number/format.d.ts.map +1 -0
  126. package/script/src/models/phone_number/format.js +17 -0
  127. package/script/src/models/phone_number/global/phone_number.d.ts +160 -0
  128. package/script/src/models/phone_number/global/phone_number.d.ts.map +1 -0
  129. package/script/src/models/phone_number/global/phone_number.js +457 -0
  130. package/script/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
  131. package/script/src/models/phone_number/global/service.d.ts +260 -0
  132. package/script/src/models/phone_number/global/service.d.ts.map +1 -0
  133. package/script/src/models/phone_number/global/service.js +485 -0
  134. package/script/src/models/phone_number/global/service.test.d.ts.map +1 -0
  135. package/script/src/models/phone_number/index.d.ts +5 -3
  136. package/script/src/models/phone_number/index.d.ts.map +1 -1
  137. package/script/src/models/phone_number/index.js +5 -3
  138. package/script/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
  139. package/script/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
  140. package/script/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +1 -1
  141. package/script/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
  142. package/script/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
  143. package/{esm/src/models/phone_number → script/src/models/phone_number/tz}/phone_number.d.ts +46 -29
  144. package/script/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
  145. package/script/src/models/phone_number/{phone_number.js → tz/phone_number.js} +89 -43
  146. package/script/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
  147. package/esm/src/models/bank/banks.d.ts.map +0 -1
  148. package/esm/src/models/bank/utils.d.ts +0 -25
  149. package/esm/src/models/bank/utils.d.ts.map +0 -1
  150. package/esm/src/models/bank/utils.js +0 -35
  151. package/esm/src/models/phone_number/antd_validator.d.ts.map +0 -1
  152. package/esm/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
  153. package/esm/src/models/phone_number/network_operator.d.ts.map +0 -1
  154. package/esm/src/models/phone_number/phone_number.d.ts.map +0 -1
  155. package/esm/src/models/phone_number/phone_number.test.d.ts.map +0 -1
  156. package/script/src/models/bank/banks.d.ts.map +0 -1
  157. package/script/src/models/bank/utils.d.ts +0 -25
  158. package/script/src/models/bank/utils.d.ts.map +0 -1
  159. package/script/src/models/bank/utils.js +0 -41
  160. package/script/src/models/phone_number/antd_validator.d.ts.map +0 -1
  161. package/script/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
  162. package/script/src/models/phone_number/network_operator.d.ts.map +0 -1
  163. package/script/src/models/phone_number/phone_number.d.ts.map +0 -1
  164. package/script/src/models/phone_number/phone_number.test.d.ts.map +0 -1
  165. /package/esm/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
  166. /package/esm/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
  167. /package/esm/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
  168. /package/script/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
  169. /package/script/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
  170. /package/script/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
@@ -23,49 +23,66 @@
23
23
  * - Tigo: 65, 67, etc.
24
24
  * - Halotel: 62, etc.
25
25
  *
26
+ * 4. Phone numbers can be formatted in the following ways:
27
+ * - International format: "+255 XXX XXX XXX"
28
+ * - National format: "0XXX XXX XXX"
29
+ * - Compact format: "XXXXXXXXX"
30
+ * - RFC3966 format: "tel:+255XXXXXXXXX"
31
+ *
26
32
  * ## Solution
27
- * The PhoneNumber class provides:
33
+ * The TZPhoneNumber class provides:
28
34
  * 1. Parsing and validation of different input formats
29
35
  * 2. Standardized storage in compact format
30
36
  * 3. Formatting options for display and API use
31
37
  * 4. Network operator identification
32
38
  */
33
39
  import { type NetworkOperatorInfo } from "./network_operator.js";
34
- /**
35
- * Enumeration for various mobile number formats.
36
- * @enum {string}
37
- */
38
- export declare enum MobileNumberFormat {
39
- s255 = "255",// Mobile numbers prefixed with 255
40
- sp255 = "+255",// Mobile numbers prefixed with +255
41
- s0 = "0",// Mobile numbers prefixed with 0
42
- none = ""
43
- }
40
+ import { PhoneNumberFormat } from "../format.js";
44
41
  /**
45
42
  * Represents a TZ phone number
46
43
  */
47
- export declare class PhoneNumber {
44
+ export declare class TZPhoneNumber {
48
45
  /**
49
46
  * Stores the phone number in a compact format excluding country code and the initial '0'.
50
47
  */
51
- compactNumber: string;
48
+ private _compactNumber;
52
49
  /**
53
- * Constructs a new `PhoneNumber` instance.
50
+ * Private constructor to prevent direct instantiation.
51
+ * Use TZPhoneNumber.from() instead.
54
52
  *
55
53
  * @param compactNumber - The phone number in a compact format (e.g., "712345678").
56
54
  */
57
- constructor(compactNumber: string);
55
+ private constructor();
56
+ /**
57
+ * Gets the compact number (national number without formatting)
58
+ */
59
+ get compactNumber(): string;
58
60
  /**
59
- * Formats the compact phone number with the specified `MobileNumberFormat`.
61
+ * Formats the phone number according to the specified format
60
62
  *
61
- * @param format - The desired phone number format (e.g., `+255` or `255`).
62
- * @returns The phone number formatted as a string.
63
+ * @param format - The desired format from GlobalPhoneNumberFormat
64
+ * @returns The formatted phone number string
65
+ */
66
+ getWithFormat(format: PhoneNumberFormat): string;
67
+ /**
68
+ * Formats the phone number in international format with spaces
69
+ * Format: +255 XXX XXX XXX
70
+ */
71
+ private formatInternational;
72
+ /**
73
+ * Formats the phone number in national format with spaces
74
+ * Format: 0XXX XXX XXX
75
+ */
76
+ private formatNational;
77
+ /**
78
+ * Formats the phone number according to RFC3966
79
+ * Format: tel:+255XXXXXXXXX
63
80
  */
64
- getNumberWithFormat(format: MobileNumberFormat): string;
81
+ private formatRFC3966;
65
82
  /**
66
- * Returns the formatted label of the phone number using the `s255` format.
83
+ * Returns the formatted label of the phone number using the international format.
67
84
  *
68
- * @returns The phone number label in `255` format.
85
+ * @returns The phone number label in international format.
69
86
  */
70
87
  get label(): string;
71
88
  /**
@@ -75,12 +92,12 @@ export declare class PhoneNumber {
75
92
  */
76
93
  get networkOperator(): NetworkOperatorInfo;
77
94
  /**
78
- * Creates a `PhoneNumber` instance from a given string.
95
+ * Creates a `TZPhoneNumber` instance from a given string.
79
96
  *
80
97
  * @param s - The input phone number string in various formats (e.g., "+255712345678", "0712345678").
81
- * @returns A `PhoneNumber` instance if valid, otherwise `undefined`.
98
+ * @returns A `TZPhoneNumber` instance if valid, otherwise `undefined`.
82
99
  */
83
- static from(s: string): PhoneNumber | undefined;
100
+ static from(input: string): TZPhoneNumber | undefined;
84
101
  /**
85
102
  * Checks if a string can be constructed into a valid phone number object.
86
103
  * @param {string | undefined} input - The string to validate as a phone number.
@@ -89,16 +106,16 @@ export declare class PhoneNumber {
89
106
  */
90
107
  static canConstruct(input?: string | null): boolean;
91
108
  /**
92
- * Checks if an unknown value contains valid data to construct a PhoneNumber instance.
109
+ * Checks if an unknown value contains valid data to construct a TZPhoneNumber instance.
93
110
  * Validates the structural integrity of the phone number object.
94
111
  *
95
112
  * @param {unknown} obj - The value to validate.
96
- * @returns {obj is PhoneNumber} Type predicate indicating if the value has a valid phone number structure.
113
+ * @returns {obj is TZPhoneNumber} Type predicate indicating if the value has a valid phone number structure.
97
114
  *
98
115
  * @example
99
116
  * const maybePhone = JSON.parse(someData);
100
- * if (PhoneNumber.is(maybePhone)) {
101
- * // maybePhone is typed as PhoneNumber
117
+ * if (TZPhoneNumber.is(maybePhone)) {
118
+ * // maybePhone is typed as TZPhoneNumber
102
119
  * console.log(maybePhone.label);
103
120
  * }
104
121
  *
@@ -108,7 +125,7 @@ export declare class PhoneNumber {
108
125
  * - compactNumber is a 9-digit string
109
126
  * - Prefix matches a valid network operator
110
127
  */
111
- static is(obj: unknown): obj is PhoneNumber;
128
+ static is(obj: unknown): obj is TZPhoneNumber;
112
129
  /**
113
130
  * Checks the validity of the phone number data
114
131
  * @returns true if the phone number information is available and valid
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phone_number.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/phone_number/tz/phone_number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD;;GAEG;AACH,qBAAa,aAAa;IACxB;;OAEG;IACH,OAAO,CAAC,cAAc,CAAS;IAE/B;;;;;OAKG;IACH,OAAO;IAIP;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM;IAmBhD;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAQ3B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAMtB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;OAIG;IACH,IAAI,eAAe,IAAI,mBAAmB,CAMzC;IAED;;;;;OAKG;WACW,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAyC5D;;;;;OAKG;WACW,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAW1D;;;;;;;;;;;;;;;;;;;OAmBG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,aAAa;IAYpD;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B"}
@@ -24,33 +24,30 @@
24
24
  * - Tigo: 65, 67, etc.
25
25
  * - Halotel: 62, etc.
26
26
  *
27
+ * 4. Phone numbers can be formatted in the following ways:
28
+ * - International format: "+255 XXX XXX XXX"
29
+ * - National format: "0XXX XXX XXX"
30
+ * - Compact format: "XXXXXXXXX"
31
+ * - RFC3966 format: "tel:+255XXXXXXXXX"
32
+ *
27
33
  * ## Solution
28
- * The PhoneNumber class provides:
34
+ * The TZPhoneNumber class provides:
29
35
  * 1. Parsing and validation of different input formats
30
36
  * 2. Standardized storage in compact format
31
37
  * 3. Formatting options for display and API use
32
38
  * 4. Network operator identification
33
39
  */
34
40
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.PhoneNumber = exports.MobileNumberFormat = void 0;
41
+ exports.TZPhoneNumber = void 0;
36
42
  const network_operator_js_1 = require("./network_operator.js");
37
- /**
38
- * Enumeration for various mobile number formats.
39
- * @enum {string}
40
- */
41
- var MobileNumberFormat;
42
- (function (MobileNumberFormat) {
43
- MobileNumberFormat["s255"] = "255";
44
- MobileNumberFormat["sp255"] = "+255";
45
- MobileNumberFormat["s0"] = "0";
46
- MobileNumberFormat["none"] = "";
47
- })(MobileNumberFormat || (exports.MobileNumberFormat = MobileNumberFormat = {}));
43
+ const format_js_1 = require("../format.js");
48
44
  /**
49
45
  * Represents a TZ phone number
50
46
  */
51
- class PhoneNumber {
47
+ class TZPhoneNumber {
52
48
  /**
53
- * Constructs a new `PhoneNumber` instance.
49
+ * Private constructor to prevent direct instantiation.
50
+ * Use TZPhoneNumber.from() instead.
54
51
  *
55
52
  * @param compactNumber - The phone number in a compact format (e.g., "712345678").
56
53
  */
@@ -58,30 +55,76 @@ class PhoneNumber {
58
55
  /**
59
56
  * Stores the phone number in a compact format excluding country code and the initial '0'.
60
57
  */
61
- Object.defineProperty(this, "compactNumber", {
58
+ Object.defineProperty(this, "_compactNumber", {
62
59
  enumerable: true,
63
60
  configurable: true,
64
61
  writable: true,
65
62
  value: void 0
66
63
  });
67
- this.compactNumber = compactNumber;
64
+ this._compactNumber = compactNumber;
68
65
  }
69
66
  /**
70
- * Formats the compact phone number with the specified `MobileNumberFormat`.
67
+ * Gets the compact number (national number without formatting)
68
+ */
69
+ get compactNumber() {
70
+ return this._compactNumber;
71
+ }
72
+ /**
73
+ * Formats the phone number according to the specified format
71
74
  *
72
- * @param format - The desired phone number format (e.g., `+255` or `255`).
73
- * @returns The phone number formatted as a string.
75
+ * @param format - The desired format from GlobalPhoneNumberFormat
76
+ * @returns The formatted phone number string
74
77
  */
75
- getNumberWithFormat(format) {
76
- return `${format}${this.compactNumber}`;
78
+ getWithFormat(format) {
79
+ switch (format) {
80
+ case format_js_1.PhoneNumberFormat.INTERNATIONAL:
81
+ // Format: +255 XXX XXX XXX
82
+ return this.formatInternational();
83
+ case format_js_1.PhoneNumberFormat.NATIONAL:
84
+ // Format: 0XXX XXX XXX
85
+ return this.formatNational();
86
+ case format_js_1.PhoneNumberFormat.COMPACT:
87
+ // Format: XXXXXXXXX (just the 9 digits)
88
+ return this._compactNumber;
89
+ case format_js_1.PhoneNumberFormat.RFC3966:
90
+ // Format: tel:+255XXXXXXXXX
91
+ return this.formatRFC3966();
92
+ default:
93
+ return `+255${this._compactNumber}`;
94
+ }
77
95
  }
78
96
  /**
79
- * Returns the formatted label of the phone number using the `s255` format.
97
+ * Formats the phone number in international format with spaces
98
+ * Format: +255 XXX XXX XXX
99
+ */
100
+ formatInternational() {
101
+ const num = this._compactNumber;
102
+ // Insert spaces: +255 XXX XXX XXX
103
+ return `+255 ${num.substring(0, 3)} ${num.substring(3, 6)} ${num.substring(6)}`;
104
+ }
105
+ /**
106
+ * Formats the phone number in national format with spaces
107
+ * Format: 0XXX XXX XXX
108
+ */
109
+ formatNational() {
110
+ const num = this._compactNumber;
111
+ // Insert spaces: 0XXX XXX XXX
112
+ return `0${num.substring(0, 3)} ${num.substring(3, 6)} ${num.substring(6)}`;
113
+ }
114
+ /**
115
+ * Formats the phone number according to RFC3966
116
+ * Format: tel:+255XXXXXXXXX
117
+ */
118
+ formatRFC3966() {
119
+ return `tel:+255${this._compactNumber}`;
120
+ }
121
+ /**
122
+ * Returns the formatted label of the phone number using the international format.
80
123
  *
81
- * @returns The phone number label in `255` format.
124
+ * @returns The phone number label in international format.
82
125
  */
83
126
  get label() {
84
- return this.getNumberWithFormat(MobileNumberFormat.s255);
127
+ return this.getWithFormat(format_js_1.PhoneNumberFormat.INTERNATIONAL);
85
128
  }
86
129
  /**
87
130
  * Derives the network operator information associated with the phone number by checking its prefix.
@@ -89,21 +132,24 @@ class PhoneNumber {
89
132
  * @returns The `NetworkOperatorInfo` object that matches the phone number prefix.
90
133
  */
91
134
  get networkOperator() {
92
- const prefix = this.compactNumber.substring(0, 2);
135
+ const prefix = this._compactNumber.substring(0, 2);
93
136
  const result = Object.values(network_operator_js_1.NETWORK_OPERATOR_CONFIG).find((operator) => operator.mobileNumberPrefixes.includes(prefix));
94
137
  return result;
95
138
  }
96
139
  /**
97
- * Creates a `PhoneNumber` instance from a given string.
140
+ * Creates a `TZPhoneNumber` instance from a given string.
98
141
  *
99
142
  * @param s - The input phone number string in various formats (e.g., "+255712345678", "0712345678").
100
- * @returns A `PhoneNumber` instance if valid, otherwise `undefined`.
143
+ * @returns A `TZPhoneNumber` instance if valid, otherwise `undefined`.
101
144
  */
102
- static from(s) {
145
+ static from(input) {
103
146
  try {
104
- const number = removeSpaces(s.trim());
147
+ // Clean the input (remove all non-digits except the leading '+')
148
+ const hasPlus = input.trim().startsWith("+");
149
+ let number = input.replace(/\D/g, "");
150
+ number = hasPlus ? `+${number}` : number;
105
151
  if (number.length === 0)
106
- return;
152
+ return undefined;
107
153
  const isOnlyDigits = isOnlyDigitsOrPlus(number);
108
154
  if (!isOnlyDigits)
109
155
  return;
@@ -129,7 +175,7 @@ class PhoneNumber {
129
175
  const operator = Object.values(network_operator_js_1.NETWORK_OPERATOR_CONFIG).find((op) => op.mobileNumberPrefixes.includes(prefix));
130
176
  if (!operator)
131
177
  return;
132
- return new PhoneNumber(compactNumber);
178
+ return new TZPhoneNumber(compactNumber);
133
179
  }
134
180
  catch (_) {
135
181
  return;
@@ -147,20 +193,20 @@ class PhoneNumber {
147
193
  const text = removeSpaces(input.trim());
148
194
  if (text.length === 0)
149
195
  return false;
150
- const phone = PhoneNumber.from(text);
196
+ const phone = TZPhoneNumber.from(text);
151
197
  return phone !== undefined;
152
198
  }
153
199
  /**
154
- * Checks if an unknown value contains valid data to construct a PhoneNumber instance.
200
+ * Checks if an unknown value contains valid data to construct a TZPhoneNumber instance.
155
201
  * Validates the structural integrity of the phone number object.
156
202
  *
157
203
  * @param {unknown} obj - The value to validate.
158
- * @returns {obj is PhoneNumber} Type predicate indicating if the value has a valid phone number structure.
204
+ * @returns {obj is TZPhoneNumber} Type predicate indicating if the value has a valid phone number structure.
159
205
  *
160
206
  * @example
161
207
  * const maybePhone = JSON.parse(someData);
162
- * if (PhoneNumber.is(maybePhone)) {
163
- * // maybePhone is typed as PhoneNumber
208
+ * if (TZPhoneNumber.is(maybePhone)) {
209
+ * // maybePhone is typed as TZPhoneNumber
164
210
  * console.log(maybePhone.label);
165
211
  * }
166
212
  *
@@ -174,11 +220,11 @@ class PhoneNumber {
174
220
  if (!obj || typeof obj !== "object")
175
221
  return false;
176
222
  const maybePhone = obj;
177
- // Check if compactNumber exists and is string
178
- if (typeof maybePhone.compactNumber !== "string")
223
+ // Check if _compactNumber exists and is string
224
+ if (typeof maybePhone._compactNumber !== "string")
179
225
  return false;
180
- const compactNumber = maybePhone.compactNumber;
181
- return PhoneNumber.canConstruct(compactNumber);
226
+ const compactNumber = maybePhone._compactNumber;
227
+ return TZPhoneNumber.canConstruct(compactNumber);
182
228
  }
183
229
  /**
184
230
  * Checks the validity of the phone number data
@@ -186,14 +232,14 @@ class PhoneNumber {
186
232
  */
187
233
  validate() {
188
234
  try {
189
- return PhoneNumber.canConstruct(this.compactNumber);
235
+ return TZPhoneNumber.canConstruct(this._compactNumber);
190
236
  }
191
237
  catch (_) {
192
238
  return false;
193
239
  }
194
240
  }
195
241
  }
196
- exports.PhoneNumber = PhoneNumber;
242
+ exports.TZPhoneNumber = TZPhoneNumber;
197
243
  /**
198
244
  * Removes all whitespace characters from the given string.
199
245
  *
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phone_number.test.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/phone_number/tz/phone_number.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"banks.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/banks.js"],"names":[],"mappings":""}
@@ -1,25 +0,0 @@
1
- /**
2
- * Regex pattern to validate SWIFT codes.
3
- * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
4
- * @constant {RegExp}
5
- */
6
- export declare const SWIFT_CODE_REGEX: RegExp;
7
- /**
8
- * Retrieves all SWIFT codes from the TZ_BANKS list.
9
- * @returns {string[]} A list of all SWIFT codes in uppercase.
10
- */
11
- export declare function getAllSwiftCodes(): string[];
12
- /**
13
- * Checks whether a given SWIFT code is in the correct format.
14
- * @param {string} swiftCode The SWIFT code to check.
15
- * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
16
- */
17
- export declare function isValidSwiftCodeFormat(swiftCode: string): boolean;
18
- /**
19
- * Validates whether a given SWIFT code is correct.
20
- * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
21
- * @param {string} [swiftCode] The SWIFT code to validate.
22
- * @returns {boolean} `true` if valid, otherwise `false`.
23
- */
24
- export declare const validateSWIFTCode: (swiftCode?: string) => boolean;
25
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,OAQtD,CAAC"}
@@ -1,35 +0,0 @@
1
- import { Bank } from "./bank.js";
2
- /**
3
- * Regex pattern to validate SWIFT codes.
4
- * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
5
- * @constant {RegExp}
6
- */
7
- export const SWIFT_CODE_REGEX = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/;
8
- /**
9
- * Retrieves all SWIFT codes from the TZ_BANKS list.
10
- * @returns {string[]} A list of all SWIFT codes in uppercase.
11
- */
12
- export function getAllSwiftCodes() {
13
- return Bank.getAll().map((bank) => bank.swiftCode.toUpperCase());
14
- }
15
- /**
16
- * Checks whether a given SWIFT code is in the correct format.
17
- * @param {string} swiftCode The SWIFT code to check.
18
- * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
19
- */
20
- export function isValidSwiftCodeFormat(swiftCode) {
21
- return SWIFT_CODE_REGEX.test(swiftCode);
22
- }
23
- /**
24
- * Validates whether a given SWIFT code is correct.
25
- * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
26
- * @param {string} [swiftCode] The SWIFT code to validate.
27
- * @returns {boolean} `true` if valid, otherwise `false`.
28
- */
29
- export const validateSWIFTCode = (swiftCode) => {
30
- if (!swiftCode)
31
- return false;
32
- const normalizedCode = swiftCode.trim().toUpperCase();
33
- return (isValidSwiftCodeFormat(normalizedCode) &&
34
- getAllSwiftCodes().includes(normalizedCode));
35
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"antd_validator.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/antd_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,eAAO,MAAM,qBAAqB,QACkF,CAAC;AAErH,eAAO,MAAM,qBAAqB,SAC1B,UAAU,SACT,MAAM,GAAG,IAAI,GAAG,SAAS,KAC/B,OAAO,CAAC,WAAW,GAAG,SAAS,CAiBjC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"antdvalidator.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/antdvalidator.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"network_operator.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/network_operator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,eAAe;IACzB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,EAAE,EAAE,eAAe,CAAC;IAEpB,+DAA+D;IAC/D,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAE/B,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IAEpB,wDAAwD;IACxD,kBAAkB,EAAE,MAAM,CAAC;IAE3B,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,eAAe,EACf,mBAAmB,CA8BpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone_number.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,oBAAY,kBAAkB;IAC5B,IAAI,QAAQ,CAAE,mCAAmC;IACjD,KAAK,SAAS,CAAE,oCAAoC;IACpD,EAAE,MAAM,CAAE,iCAAiC;IAC3C,IAAI,KAAK;CACV;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;gBACS,aAAa,EAAE,MAAM;IAIjC;;;;;OAKG;IACH,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAIvD;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;OAIG;IACH,IAAI,eAAe,IAAI,mBAAmB,CAMzC;IAED;;;;;OAKG;WACW,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAqCtD;;;;;OAKG;WACW,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAW1D;;;;;;;;;;;;;;;;;;;OAmBG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW;IAYlD;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone_number.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"banks.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/banks.js"],"names":[],"mappings":""}
@@ -1,25 +0,0 @@
1
- /**
2
- * Regex pattern to validate SWIFT codes.
3
- * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
4
- * @constant {RegExp}
5
- */
6
- export declare const SWIFT_CODE_REGEX: RegExp;
7
- /**
8
- * Retrieves all SWIFT codes from the TZ_BANKS list.
9
- * @returns {string[]} A list of all SWIFT codes in uppercase.
10
- */
11
- export declare function getAllSwiftCodes(): string[];
12
- /**
13
- * Checks whether a given SWIFT code is in the correct format.
14
- * @param {string} swiftCode The SWIFT code to check.
15
- * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
16
- */
17
- export declare function isValidSwiftCodeFormat(swiftCode: string): boolean;
18
- /**
19
- * Validates whether a given SWIFT code is correct.
20
- * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
21
- * @param {string} [swiftCode] The SWIFT code to validate.
22
- * @returns {boolean} `true` if valid, otherwise `false`.
23
- */
24
- export declare const validateSWIFTCode: (swiftCode?: string) => boolean;
25
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,OAQtD,CAAC"}
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateSWIFTCode = exports.SWIFT_CODE_REGEX = void 0;
4
- exports.getAllSwiftCodes = getAllSwiftCodes;
5
- exports.isValidSwiftCodeFormat = isValidSwiftCodeFormat;
6
- const bank_js_1 = require("./bank.js");
7
- /**
8
- * Regex pattern to validate SWIFT codes.
9
- * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
10
- * @constant {RegExp}
11
- */
12
- exports.SWIFT_CODE_REGEX = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/;
13
- /**
14
- * Retrieves all SWIFT codes from the TZ_BANKS list.
15
- * @returns {string[]} A list of all SWIFT codes in uppercase.
16
- */
17
- function getAllSwiftCodes() {
18
- return bank_js_1.Bank.getAll().map((bank) => bank.swiftCode.toUpperCase());
19
- }
20
- /**
21
- * Checks whether a given SWIFT code is in the correct format.
22
- * @param {string} swiftCode The SWIFT code to check.
23
- * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
24
- */
25
- function isValidSwiftCodeFormat(swiftCode) {
26
- return exports.SWIFT_CODE_REGEX.test(swiftCode);
27
- }
28
- /**
29
- * Validates whether a given SWIFT code is correct.
30
- * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
31
- * @param {string} [swiftCode] The SWIFT code to validate.
32
- * @returns {boolean} `true` if valid, otherwise `false`.
33
- */
34
- const validateSWIFTCode = (swiftCode) => {
35
- if (!swiftCode)
36
- return false;
37
- const normalizedCode = swiftCode.trim().toUpperCase();
38
- return (isValidSwiftCodeFormat(normalizedCode) &&
39
- getAllSwiftCodes().includes(normalizedCode));
40
- };
41
- exports.validateSWIFTCode = validateSWIFTCode;
@@ -1 +0,0 @@
1
- {"version":3,"file":"antd_validator.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/antd_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,eAAO,MAAM,qBAAqB,QACkF,CAAC;AAErH,eAAO,MAAM,qBAAqB,SAC1B,UAAU,SACT,MAAM,GAAG,IAAI,GAAG,SAAS,KAC/B,OAAO,CAAC,WAAW,GAAG,SAAS,CAiBjC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"antdvalidator.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/antdvalidator.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"network_operator.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/network_operator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,eAAe;IACzB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,EAAE,EAAE,eAAe,CAAC;IAEpB,+DAA+D;IAC/D,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAE/B,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IAEpB,wDAAwD;IACxD,kBAAkB,EAAE,MAAM,CAAC;IAE3B,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,eAAe,EACf,mBAAmB,CA8BpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone_number.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,oBAAY,kBAAkB;IAC5B,IAAI,QAAQ,CAAE,mCAAmC;IACjD,KAAK,SAAS,CAAE,oCAAoC;IACpD,EAAE,MAAM,CAAE,iCAAiC;IAC3C,IAAI,KAAK;CACV;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;gBACS,aAAa,EAAE,MAAM;IAIjC;;;;;OAKG;IACH,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAIvD;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;OAIG;IACH,IAAI,eAAe,IAAI,mBAAmB,CAMzC;IAED;;;;;OAKG;WACW,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAqCtD;;;;;OAKG;WACW,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAW1D;;;;;;;;;;;;;;;;;;;OAmBG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW;IAYlD;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone_number.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.test.ts"],"names":[],"mappings":""}