@temboplus/frontend-core 0.2.1 → 0.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.
Files changed (200) hide show
  1. package/README.md +126 -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/mod.d.ts +2 -0
  6. package/esm/mod.d.ts.map +1 -1
  7. package/esm/mod.js +2 -0
  8. package/esm/src/config/config_service.d.ts +11 -0
  9. package/esm/src/config/config_service.d.ts.map +1 -0
  10. package/esm/src/config/config_service.js +19 -0
  11. package/esm/src/config/index.d.ts +2 -0
  12. package/esm/src/config/index.d.ts.map +1 -0
  13. package/esm/src/config/index.js +1 -0
  14. package/esm/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
  15. package/esm/src/data/banks_tz.d.ts.map +1 -0
  16. package/esm/src/data/countries.d.ts +6 -0
  17. package/esm/src/data/countries.d.ts.map +1 -0
  18. package/esm/src/data/countries.js +974 -0
  19. package/esm/src/data/currencies.d.ts +1901 -0
  20. package/esm/src/data/currencies.d.ts.map +1 -0
  21. package/esm/src/data/currencies.js +1073 -0
  22. package/esm/src/data/phone_patterns.d.ts +3809 -0
  23. package/esm/src/data/phone_patterns.d.ts.map +1 -0
  24. package/esm/src/data/phone_patterns.js +2325 -0
  25. package/esm/src/models/amount/amount.d.ts +10 -12
  26. package/esm/src/models/amount/amount.d.ts.map +1 -1
  27. package/esm/src/models/amount/amount.js +58 -96
  28. package/esm/src/models/bank/bank.d.ts +58 -53
  29. package/esm/src/models/bank/bank.d.ts.map +1 -1
  30. package/esm/src/models/bank/bank.js +49 -84
  31. package/esm/src/models/bank/index.d.ts +1 -1
  32. package/esm/src/models/bank/index.d.ts.map +1 -1
  33. package/esm/src/models/bank/index.js +1 -1
  34. package/esm/src/models/bank/service.d.ts +106 -0
  35. package/esm/src/models/bank/service.d.ts.map +1 -0
  36. package/esm/src/models/bank/service.js +240 -0
  37. package/esm/src/models/country/country.d.ts +568 -0
  38. package/esm/src/models/country/country.d.ts.map +1 -0
  39. package/esm/src/models/country/country.js +165 -0
  40. package/esm/src/models/country/country.test.d.ts.map +1 -0
  41. package/esm/src/models/country/index.d.ts +3 -0
  42. package/esm/src/models/country/index.d.ts.map +1 -0
  43. package/esm/src/models/country/index.js +2 -0
  44. package/esm/src/models/country/service.d.ts +75 -0
  45. package/esm/src/models/country/service.d.ts.map +1 -0
  46. package/esm/src/models/country/service.js +267 -0
  47. package/esm/src/models/currency/currency.d.ts +341 -0
  48. package/esm/src/models/currency/currency.d.ts.map +1 -0
  49. package/esm/src/models/currency/currency.js +225 -0
  50. package/esm/src/models/currency/currency.test.d.ts.map +1 -0
  51. package/esm/src/models/currency/index.d.ts +3 -0
  52. package/esm/src/models/currency/index.d.ts.map +1 -0
  53. package/esm/src/models/currency/index.js +2 -0
  54. package/esm/src/models/currency/service.d.ts +96 -0
  55. package/esm/src/models/currency/service.d.ts.map +1 -0
  56. package/esm/src/models/currency/service.js +194 -0
  57. package/esm/src/models/index.d.ts +2 -0
  58. package/esm/src/models/index.d.ts.map +1 -1
  59. package/esm/src/models/index.js +2 -0
  60. package/esm/src/models/phone_number/format.d.ts +14 -0
  61. package/esm/src/models/phone_number/format.d.ts.map +1 -0
  62. package/esm/src/models/phone_number/format.js +14 -0
  63. package/esm/src/models/phone_number/global/phone_number.d.ts +160 -0
  64. package/esm/src/models/phone_number/global/phone_number.d.ts.map +1 -0
  65. package/esm/src/models/phone_number/global/phone_number.js +453 -0
  66. package/esm/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
  67. package/esm/src/models/phone_number/global/service.d.ts +260 -0
  68. package/esm/src/models/phone_number/global/service.d.ts.map +1 -0
  69. package/esm/src/models/phone_number/global/service.js +477 -0
  70. package/esm/src/models/phone_number/global/service.test.d.ts.map +1 -0
  71. package/esm/src/models/phone_number/index.d.ts +5 -3
  72. package/esm/src/models/phone_number/index.d.ts.map +1 -1
  73. package/esm/src/models/phone_number/index.js +5 -3
  74. package/esm/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
  75. package/esm/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
  76. package/esm/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +2 -2
  77. package/esm/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
  78. package/esm/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
  79. package/{script/src/models/phone_number → esm/src/models/phone_number/tz}/phone_number.d.ts +46 -29
  80. package/esm/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
  81. package/esm/src/models/phone_number/{phone_number.js → tz/phone_number.js} +87 -41
  82. package/esm/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
  83. package/esm/src/reports/index.d.ts +2 -0
  84. package/esm/src/reports/index.d.ts.map +1 -0
  85. package/esm/src/reports/index.js +1 -0
  86. package/esm/src/reports/report_manager.d.ts +144 -0
  87. package/esm/src/reports/report_manager.d.ts.map +1 -0
  88. package/esm/src/reports/report_manager.js +315 -0
  89. package/package.json +4 -3
  90. package/script/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
  91. package/script/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
  92. package/script/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
  93. package/script/mod.d.ts +2 -0
  94. package/script/mod.d.ts.map +1 -1
  95. package/script/mod.js +2 -0
  96. package/script/src/config/config_service.d.ts +11 -0
  97. package/script/src/config/config_service.d.ts.map +1 -0
  98. package/script/src/config/config_service.js +23 -0
  99. package/script/src/config/index.d.ts +2 -0
  100. package/script/src/config/index.d.ts.map +1 -0
  101. package/script/src/config/index.js +17 -0
  102. package/script/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
  103. package/script/src/data/banks_tz.d.ts.map +1 -0
  104. package/script/src/data/countries.d.ts +6 -0
  105. package/script/src/data/countries.d.ts.map +1 -0
  106. package/script/src/data/countries.js +976 -0
  107. package/script/src/data/currencies.d.ts +1901 -0
  108. package/script/src/data/currencies.d.ts.map +1 -0
  109. package/script/src/data/currencies.js +1075 -0
  110. package/script/src/data/phone_patterns.d.ts +3809 -0
  111. package/script/src/data/phone_patterns.d.ts.map +1 -0
  112. package/script/src/data/phone_patterns.js +2327 -0
  113. package/script/src/models/amount/amount.d.ts +10 -12
  114. package/script/src/models/amount/amount.d.ts.map +1 -1
  115. package/script/src/models/amount/amount.js +60 -98
  116. package/script/src/models/bank/bank.d.ts +58 -53
  117. package/script/src/models/bank/bank.d.ts.map +1 -1
  118. package/script/src/models/bank/bank.js +49 -87
  119. package/script/src/models/bank/index.d.ts +1 -1
  120. package/script/src/models/bank/index.d.ts.map +1 -1
  121. package/script/src/models/bank/index.js +1 -1
  122. package/script/src/models/bank/service.d.ts +106 -0
  123. package/script/src/models/bank/service.d.ts.map +1 -0
  124. package/script/src/models/bank/service.js +247 -0
  125. package/script/src/models/country/country.d.ts +568 -0
  126. package/script/src/models/country/country.d.ts.map +1 -0
  127. package/script/src/models/country/country.js +169 -0
  128. package/script/src/models/country/country.test.d.ts.map +1 -0
  129. package/script/src/models/country/index.d.ts +3 -0
  130. package/script/src/models/country/index.d.ts.map +1 -0
  131. package/script/src/models/country/index.js +18 -0
  132. package/script/src/models/country/service.d.ts +75 -0
  133. package/script/src/models/country/service.d.ts.map +1 -0
  134. package/script/src/models/country/service.js +274 -0
  135. package/script/src/models/currency/currency.d.ts +341 -0
  136. package/script/src/models/currency/currency.d.ts.map +1 -0
  137. package/script/src/models/currency/currency.js +229 -0
  138. package/script/src/models/currency/currency.test.d.ts.map +1 -0
  139. package/script/src/models/currency/index.d.ts +3 -0
  140. package/script/src/models/currency/index.d.ts.map +1 -0
  141. package/script/src/models/currency/index.js +18 -0
  142. package/script/src/models/currency/service.d.ts +96 -0
  143. package/script/src/models/currency/service.d.ts.map +1 -0
  144. package/script/src/models/currency/service.js +201 -0
  145. package/script/src/models/index.d.ts +2 -0
  146. package/script/src/models/index.d.ts.map +1 -1
  147. package/script/src/models/index.js +2 -0
  148. package/script/src/models/phone_number/format.d.ts +14 -0
  149. package/script/src/models/phone_number/format.d.ts.map +1 -0
  150. package/script/src/models/phone_number/format.js +17 -0
  151. package/script/src/models/phone_number/global/phone_number.d.ts +160 -0
  152. package/script/src/models/phone_number/global/phone_number.d.ts.map +1 -0
  153. package/script/src/models/phone_number/global/phone_number.js +457 -0
  154. package/script/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
  155. package/script/src/models/phone_number/global/service.d.ts +260 -0
  156. package/script/src/models/phone_number/global/service.d.ts.map +1 -0
  157. package/script/src/models/phone_number/global/service.js +485 -0
  158. package/script/src/models/phone_number/global/service.test.d.ts.map +1 -0
  159. package/script/src/models/phone_number/index.d.ts +5 -3
  160. package/script/src/models/phone_number/index.d.ts.map +1 -1
  161. package/script/src/models/phone_number/index.js +5 -3
  162. package/script/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
  163. package/script/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
  164. package/script/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +1 -1
  165. package/script/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
  166. package/script/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
  167. package/{esm/src/models/phone_number → script/src/models/phone_number/tz}/phone_number.d.ts +46 -29
  168. package/script/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
  169. package/script/src/models/phone_number/{phone_number.js → tz/phone_number.js} +89 -43
  170. package/script/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
  171. package/script/src/reports/index.d.ts +2 -0
  172. package/script/src/reports/index.d.ts.map +1 -0
  173. package/script/src/reports/index.js +17 -0
  174. package/script/src/reports/report_manager.d.ts +144 -0
  175. package/script/src/reports/report_manager.d.ts.map +1 -0
  176. package/script/src/reports/report_manager.js +325 -0
  177. package/esm/src/models/bank/banks.d.ts.map +0 -1
  178. package/esm/src/models/bank/utils.d.ts +0 -25
  179. package/esm/src/models/bank/utils.d.ts.map +0 -1
  180. package/esm/src/models/bank/utils.js +0 -35
  181. package/esm/src/models/phone_number/antd_validator.d.ts.map +0 -1
  182. package/esm/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
  183. package/esm/src/models/phone_number/network_operator.d.ts.map +0 -1
  184. package/esm/src/models/phone_number/phone_number.d.ts.map +0 -1
  185. package/esm/src/models/phone_number/phone_number.test.d.ts.map +0 -1
  186. package/script/src/models/bank/banks.d.ts.map +0 -1
  187. package/script/src/models/bank/utils.d.ts +0 -25
  188. package/script/src/models/bank/utils.d.ts.map +0 -1
  189. package/script/src/models/bank/utils.js +0 -41
  190. package/script/src/models/phone_number/antd_validator.d.ts.map +0 -1
  191. package/script/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
  192. package/script/src/models/phone_number/network_operator.d.ts.map +0 -1
  193. package/script/src/models/phone_number/phone_number.d.ts.map +0 -1
  194. package/script/src/models/phone_number/phone_number.test.d.ts.map +0 -1
  195. /package/esm/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
  196. /package/esm/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
  197. /package/esm/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
  198. /package/script/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
  199. /package/script/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
  200. /package/script/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
@@ -2,18 +2,24 @@ declare const AMOUNT_REGEX: RegExp;
2
2
  declare class Amount {
3
3
  private readonly value;
4
4
  private readonly text;
5
+ private readonly currency;
5
6
  private constructor();
6
7
  /**
7
8
  * Creates an Amount instance from a string or number input
8
9
  * Returns undefined if input is invalid or negative
9
10
  * @param input - The input value (string or number)
11
+ * @param currencyCode - The currency code (defaults to TZS)
10
12
  * @returns Amount instance or undefined if validation fails
11
13
  */
12
- static from(input: string | number): Amount | undefined;
14
+ static from(input: string | number, currencyCode?: string): Amount | undefined;
13
15
  /**
14
- * Returns the formatted string representation of the amount with TZS prefix
16
+ * Returns the formatted string representation of the amount with currency
15
17
  */
16
18
  get label(): string;
19
+ /**
20
+ * Returns the currency code
21
+ */
22
+ get currencyCode(): string;
17
23
  /**
18
24
  * Returns the numeric value of the amount
19
25
  */
@@ -25,24 +31,16 @@ declare class Amount {
25
31
  /**
26
32
  * Checks if the amount is valid
27
33
  * @param input amount to be checked for validity
34
+ * @param currencyCode currency code to validate against
28
35
  * @returns true if the amount is valid, false otherwise
29
36
  */
30
- static canConstruct(input?: string | number | null): boolean;
37
+ static canConstruct(input?: string | number | null, currencyCode?: string): boolean;
31
38
  /**
32
39
  * Checks if an unknown value is an Amount instance.
33
40
  * Validates the structural integrity of an amount object.
34
41
  *
35
42
  * @param {unknown} obj - The value to validate
36
43
  * @returns {obj is Amount} Type predicate indicating if the value is a valid Amount
37
- *
38
- * @example
39
- * const maybeAmount = JSON.parse(someData);
40
- * if (Amount.is(maybeAmount)) {
41
- * console.log(maybeAmount.label); // maybeAmount is typed as Amount
42
- * }
43
- *
44
- * @see {@link Amount.canConstruct} for validating raw amount values
45
- * @see {@link Amount.from} for constructing new instances
46
44
  */
47
45
  static is(obj: unknown): obj is Amount;
48
46
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../../../src/src/models/amount/amount.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,YAAY,QAA2C,CAAC;AAE9D,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B,OAAO;IAKP;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE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OAMG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM;IA4B7C;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B;AAgDD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC"}
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AMOUNT_REGEX = exports.Amount = void 0;
4
2
  // Regex explanation:
5
3
  // ^(?:\d{1,3}(?:,\d{3})*|\d+) - Either grouped digits with commas OR just digits
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.AMOUNT_REGEX = exports.Amount = void 0;
6
+ const service_js_1 = require("../currency/service.js");
6
7
  // (?:\.\d+)?$ - Optional decimal part with any number of digits
7
8
  const AMOUNT_REGEX = /^(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/;
8
9
  exports.AMOUNT_REGEX = AMOUNT_REGEX;
9
10
  class Amount {
10
- constructor(value, text) {
11
+ constructor(value, text, currencyCode = "TZS") {
11
12
  Object.defineProperty(this, "value", {
12
13
  enumerable: true,
13
14
  configurable: true,
@@ -20,22 +21,37 @@ class Amount {
20
21
  writable: true,
21
22
  value: void 0
22
23
  });
24
+ Object.defineProperty(this, "currency", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ const code = service_js_1.CurrencyService.getInstance().fromCode(currencyCode);
31
+ if (!code) {
32
+ throw new Error("Invalid code!");
33
+ }
23
34
  this.value = value;
24
35
  this.text = text;
36
+ this.currency = code;
25
37
  }
26
38
  /**
27
39
  * Creates an Amount instance from a string or number input
28
40
  * Returns undefined if input is invalid or negative
29
41
  * @param input - The input value (string or number)
42
+ * @param currencyCode - The currency code (defaults to TZS)
30
43
  * @returns Amount instance or undefined if validation fails
31
44
  */
32
- static from(input) {
45
+ static from(input, currencyCode = "TZS") {
46
+ const currency = service_js_1.CurrencyService.getInstance().fromCode(currencyCode);
47
+ if (!currency)
48
+ return undefined;
33
49
  let amountText = input.toString().trim();
50
+ amountText = removeCommasAndCurrency(amountText);
34
51
  if (hasComma(amountText)) {
35
52
  if (!hasValidCommaPlacement(amountText))
36
53
  return undefined;
37
54
  }
38
- amountText = removeCommasAndCurrency(amountText);
39
55
  // Handle string input
40
56
  if (!AMOUNT_REGEX.test(amountText))
41
57
  return undefined;
@@ -43,19 +59,28 @@ class Amount {
43
59
  const value = Number(amountText.replace(/,/g, ""));
44
60
  if (!Number.isFinite(value) || value < 0)
45
61
  return undefined;
46
- // Round to 2 decimal places and format the text representation
47
- const roundedValue = Number(value.toFixed(2));
48
- const text = roundedValue.toLocaleString("en-US", {
49
- minimumFractionDigits: 2,
50
- maximumFractionDigits: 2,
62
+ const dd = currency.decimalDigits;
63
+ const roundedValue = Number(value.toFixed(dd));
64
+ let text = roundedValue.toLocaleString("en-US", {
65
+ minimumFractionDigits: dd,
66
+ maximumFractionDigits: dd,
51
67
  });
52
- return new Amount(roundedValue, text);
68
+ if (dd === 0) {
69
+ text = text.replace(".00", "");
70
+ }
71
+ return new Amount(roundedValue, text, currency.code);
53
72
  }
54
73
  /**
55
- * Returns the formatted string representation of the amount with TZS prefix
74
+ * Returns the formatted string representation of the amount with currency
56
75
  */
57
76
  get label() {
58
- return `TZS ${this.text}`;
77
+ return `${this.currency.symbol} ${this.text}`;
78
+ }
79
+ /**
80
+ * Returns the currency code
81
+ */
82
+ get currencyCode() {
83
+ return this.currency.code;
59
84
  }
60
85
  /**
61
86
  * Returns the numeric value of the amount
@@ -75,13 +100,13 @@ class Amount {
75
100
  /**
76
101
  * Checks if the amount is valid
77
102
  * @param input amount to be checked for validity
103
+ * @param currencyCode currency code to validate against
78
104
  * @returns true if the amount is valid, false otherwise
79
105
  */
80
- static canConstruct(input) {
81
- /// (!input) alone does not work since input could 0 and (!input) return true for this case
106
+ static canConstruct(input, currencyCode = "TZS") {
82
107
  if (input === undefined || input === null)
83
108
  return false;
84
- const amount = Amount.from(input);
109
+ const amount = Amount.from(input, currencyCode);
85
110
  if (!amount)
86
111
  return false;
87
112
  return true;
@@ -92,15 +117,6 @@ class Amount {
92
117
  *
93
118
  * @param {unknown} obj - The value to validate
94
119
  * @returns {obj is Amount} Type predicate indicating if the value is a valid Amount
95
- *
96
- * @example
97
- * const maybeAmount = JSON.parse(someData);
98
- * if (Amount.is(maybeAmount)) {
99
- * console.log(maybeAmount.label); // maybeAmount is typed as Amount
100
- * }
101
- *
102
- * @see {@link Amount.canConstruct} for validating raw amount values
103
- * @see {@link Amount.from} for constructing new instances
104
120
  */
105
121
  static is(obj) {
106
122
  if (!obj || typeof obj !== "object")
@@ -111,17 +127,23 @@ class Amount {
111
127
  return false;
112
128
  if (typeof maybeAmount.text !== "string")
113
129
  return false;
130
+ if (!maybeAmount.currency || typeof maybeAmount.currency !== "object") {
131
+ return false;
132
+ }
114
133
  const value = maybeAmount.value;
115
134
  const text = maybeAmount.text;
135
+ const currency = maybeAmount.currency.code;
116
136
  // Validate numeric constraints
117
137
  if (!Number.isFinite(value) || value < 0)
118
138
  return false;
119
- const canConstruct = Amount.canConstruct(value);
139
+ const canConstruct = Amount.canConstruct(value, currency);
120
140
  if (!canConstruct)
121
141
  return false;
122
- const amount = Amount.from(value);
123
- return amount != undefined && amount.value === value &&
124
- amount.text === text;
142
+ const amount = Amount.from(value, currency);
143
+ return amount != undefined &&
144
+ amount.value === value &&
145
+ amount.text === text &&
146
+ amount.currencyCode === currency;
125
147
  }
126
148
  /**
127
149
  * Checks the validity of the amount data
@@ -129,7 +151,7 @@ class Amount {
129
151
  */
130
152
  validate() {
131
153
  try {
132
- return Amount.canConstruct(this.value);
154
+ return Amount.canConstruct(this.value, this.currencyCode);
133
155
  }
134
156
  catch (_) {
135
157
  return false;
@@ -138,95 +160,35 @@ class Amount {
138
160
  }
139
161
  exports.Amount = Amount;
140
162
  /**
141
- * Removes commas and "TZS" symbol (if present) from a string.
142
- * Handles both prefixed and suffixed "TZS" symbols, with or without spaces.
163
+ * Removes commas and currency symbols from a string.
164
+ * Handles both prefixed and suffixed currency symbols, with or without spaces.
143
165
  *
144
166
  * @param {string} text - The input string to clean
145
- * @returns {string} A string with commas and "TZS" symbol removed
146
- *
147
- * @example
148
- * removeCommasAndCurrency("1,234.56"); // Returns: "1234.56"
149
- * removeCommasAndCurrency("TZS 1,234.56"); // Returns: "1234.56"
150
- * removeCommasAndCurrency("1,234.56 TZS"); // Returns: "1234.56"
151
- * removeCommasAndCurrency("TZS1,234.56"); // Returns: "1234.56"
152
- * removeCommasAndCurrency("1234.56"); // Returns: "1234.56"
153
- * removeCommasAndCurrency(""); // Returns: ""
154
- *
155
- * @remarks
156
- * - Case insensitive for "TZS" symbol
157
- * - Removes all commas regardless of position
158
- * - Handles optional spaces around the currency symbol
159
- * - Returns empty string if input is empty
167
+ * @returns {string} A string with commas and currency symbols removed
160
168
  */
161
169
  function removeCommasAndCurrency(text) {
170
+ const currencyPatterns = service_js_1.CurrencyService.getInstance()
171
+ .getCurrencySymbolPattern();
172
+ const regex = new RegExp(`(?:${currencyPatterns})\\s*|\\s*(?:${currencyPatterns})`, "gi");
162
173
  return text
163
- .replace(/TZS\s*|\s*TZS/gi, "") // Remove TZS with optional spaces
174
+ .replace(regex, "") // Remove currency symbols with optional spaces
164
175
  .replace(/,/g, ""); // Remove all commas
165
176
  }
166
- /**
167
- * Checks if commas in a numeric string are correctly placed to separate groups of three digits.
168
- * Only validates the part before the decimal point if one exists.
169
- *
170
- * @param {string} text - The input string to validate
171
- * @returns {boolean} True if commas are correctly placed or if there are no commas, false otherwise
172
- *
173
- * @example
174
- * hasValidCommaPlacement("1,234,567.89"); // Returns: true
175
- * hasValidCommaPlacement("1234567.89"); // Returns: true (no commas)
176
- * hasValidCommaPlacement("1,234.56"); // Returns: true
177
- * hasValidCommaPlacement("1,23,456"); // Returns: false (incorrect grouping)
178
- * hasValidCommaPlacement("1,2345"); // Returns: false (incorrect grouping)
179
- * hasValidCommaPlacement(",123"); // Returns: false (leading comma)
180
- * hasValidCommaPlacement("1,234,"); // Returns: false (trailing comma)
181
- * hasValidCommaPlacement("1,,234"); // Returns: false (consecutive commas)
182
- *
183
- * @remarks
184
- * - Validates comma placement in the whole number part only
185
- * - Each group after the first must be exactly 3 digits
186
- * - First group can be 1-3 digits
187
- * - Returns true if the string contains no commas
188
- * - Does not validate the decimal part if present
189
- */
177
+ // Rest of the helper functions remain the same
190
178
  function hasValidCommaPlacement(text) {
191
- // Split at decimal point if it exists and take the whole number part
192
179
  const wholeNumberPart = text.split(".")[0];
193
- // If no commas, it's valid
194
180
  if (!wholeNumberPart.includes(",")) {
195
181
  return true;
196
182
  }
197
- // Split the whole number by commas
198
183
  const groups = wholeNumberPart.split(",");
199
- // Check for invalid cases:
200
- // - Empty string before/after comma (e.g. ",123" or "123,")
201
- // - More than one empty group (consecutive commas)
202
184
  if (groups.some((group) => group.length === 0)) {
203
185
  return false;
204
186
  }
205
- // First group can be 1-3 digits
206
187
  if (groups[0].length > 3 || groups[0].length < 1) {
207
188
  return false;
208
189
  }
209
- // All other groups must be exactly 3 digits
210
190
  return groups.slice(1).every((group) => group.length === 3);
211
191
  }
212
- /**
213
- * Checks if a string contains a comma character.
214
- *
215
- * @param {string} text - The input string to check
216
- * @returns {boolean} True if the string contains at least one comma, false otherwise
217
- *
218
- * @example
219
- * hasComma("1,234.56"); // Returns: true
220
- * hasComma("1234.56"); // Returns: false
221
- * hasComma("hello,world"); // Returns: true
222
- * hasComma(""); // Returns: false
223
- * hasComma(","); // Returns: true
224
- *
225
- * @remarks
226
- * - Returns false for empty strings
227
- * - Returns true if one or more commas are present
228
- * - Position of the comma doesn't matter
229
- */
230
192
  function hasComma(text) {
231
193
  return text.includes(",");
232
194
  }
@@ -6,8 +6,49 @@ export declare class Bank {
6
6
  private readonly _fullName;
7
7
  private readonly _shortName;
8
8
  private readonly _swiftCode;
9
+ static readonly CRDB: Bank;
10
+ static readonly PBZ: Bank;
11
+ static readonly SCB: Bank;
12
+ static readonly STANBIC: Bank;
13
+ static readonly CITI: Bank;
14
+ static readonly BOA: Bank;
15
+ static readonly DTB: Bank;
16
+ static readonly AKIBA: Bank;
17
+ static readonly EXIM: Bank;
18
+ static readonly KILIMANJARO: Bank;
19
+ static readonly NBC: Bank;
20
+ static readonly NMB: Bank;
21
+ static readonly KCB: Bank;
22
+ static readonly HABIB: Bank;
23
+ static readonly ICB: Bank;
24
+ static readonly ABSA: Bank;
25
+ static readonly IMBANK: Bank;
26
+ static readonly NCBA: Bank;
27
+ static readonly DCB: Bank;
28
+ static readonly BARODA: Bank;
29
+ static readonly AZANIA: Bank;
30
+ static readonly UCHUMI: Bank;
31
+ static readonly BANCABC: Bank;
32
+ static readonly ACCESS: Bank;
33
+ static readonly BOI: Bank;
34
+ static readonly UBA: Bank;
35
+ static readonly MKOMBOZI: Bank;
36
+ static readonly ECOBANK: Bank;
37
+ static readonly MWANGA: Bank;
38
+ static readonly FNB: Bank;
39
+ static readonly AMANA: Bank;
40
+ static readonly EQUITY: Bank;
41
+ static readonly TCB: Bank;
42
+ static readonly MAENDELEO: Bank;
43
+ static readonly CANARA: Bank;
44
+ static readonly MWALIMU: Bank;
45
+ static readonly GT_BANK: Bank;
46
+ static readonly YETU: Bank;
47
+ static readonly DASHENG: Bank;
9
48
  /**
10
- * Creates a new Bank instance.
49
+ * Creates a new Bank instance. Private constructor - only BankService can create instances.
50
+ * Clients should use static methods like Bank.from() or Bank.CRDB instead.
51
+ *
11
52
  * @param {string} _fullName - The full name of the bank
12
53
  * @param {string} _shortName - The short name or abbreviated name of the bank
13
54
  * @param {string} _swiftCode - The SWIFT code associated with the bank
@@ -45,35 +86,23 @@ export declare class Bank {
45
86
  * @returns {Bank | undefined} The bank corresponding to the full name or `undefined` if not found.
46
87
  */
47
88
  static fromBankName(bankName: string): Bank | undefined;
89
+ /**
90
+ * Returns all available banks.
91
+ * @returns {Bank[]} Array of all banks
92
+ */
93
+ static getAll(): Bank[];
48
94
  /**
49
95
  * Validates if a given SWIFT/BIC (Bank Identifier Code) is valid
50
- *
51
- * @param {string | null | undefined} swiftCode - The SWIFT/BIC code to validate.
52
- * Should be in the format of 8 or 11 characters (e.g., 'NMIBTZTZ' or 'CRDBTZTZXXX').
53
- *
54
- * @returns {boolean} Returns true if:
55
- * - The SWIFT code is not null/undefined
56
- * - The SWIFT code successfully creates a valid Bank instance
57
- * Returns false otherwise.
96
+ * @param swiftCode The SWIFT/BIC code to validate
97
+ * @returns True if the SWIFT code is valid
58
98
  */
59
99
  static isValidSwiftCode(swiftCode?: string | null): boolean;
60
100
  /**
61
101
  * Validates if a given bank name is valid
62
- *
63
- * @param {string | null | undefined} bankName - The bank name to validate.
64
- * Should be either 'CRDB' or 'NMB'.
65
- *
66
- * @returns {boolean} Returns true if:
67
- * - The bank name is not null/undefined
68
- * - The bank name successfully creates a valid Bank instance
69
- * Returns false otherwise.
102
+ * @param bankName The bank name to validate
103
+ * @returns True if the bank name is valid
70
104
  */
71
105
  static isValidBankName(bankName?: string | null): boolean;
72
- /**
73
- * Gets all banks from the JSON data.
74
- * @returns {Bank[]} Array of all banks
75
- */
76
- static getAll(): Bank[];
77
106
  /**
78
107
  * Checks the validity of the bank data
79
108
  * @returns true if the bank information is available and valid
@@ -81,44 +110,20 @@ export declare class Bank {
81
110
  validate(): boolean;
82
111
  /**
83
112
  * Attempts to create a Bank instance from a bank name or SWIFT code
84
- * First tries to create from bank name, then from SWIFT code if bank name fails
85
- *
86
- * @param {string} input - The bank name or SWIFT code
87
- * @returns {Bank | undefined} A Bank instance if valid input, undefined otherwise
88
- *
89
- * @example
90
- * const bank = Bank.from('CORUTZTZ'); // From SWIFT code
91
- * const sameBank = Bank.from('CRDB'); // From bank name
113
+ * @param input The bank name or SWIFT code
114
+ * @returns A Bank instance if valid input, undefined otherwise
92
115
  */
93
116
  static from(input: string): Bank | undefined;
94
117
  /**
95
118
  * Validates if the input can be used to construct a valid Bank instance
96
- * Checks if the input resolves to the same bank via both name and SWIFT code
97
- *
98
- * @param {string | null | undefined} input - The bank name or SWIFT code to validate
99
- * @returns {boolean} True if input can construct a valid bank, false otherwise
100
- *
101
- * @example
102
- * Bank.canConstruct('CORUTZTZ'); // true
103
- * Bank.canConstruct(''); // false
104
- * Bank.canConstruct(null); // false
119
+ * @param input The bank name or SWIFT code to validate
120
+ * @returns True if input can construct a valid bank, false otherwise
105
121
  */
106
122
  static canConstruct(input?: string | null): boolean;
107
123
  /**
108
- * Checks if an unknown value is a Bank instance.
109
- * Validates the structural integrity of a bank object.
110
- *
111
- * @param {unknown} obj - The value to validate
112
- * @returns {obj is Bank} Type predicate indicating if the value is a valid Bank
113
- *
114
- * @example
115
- * const maybeBank = JSON.parse(someData);
116
- * if (Bank.is(maybeBank)) {
117
- * console.log(maybeBank.fullName); // maybeBank is typed as Bank
118
- * }
119
- *
120
- * @see {@link Bank.fromSWIFTCode} for creating instances from SWIFT codes
121
- * @see {@link Bank.fromBankName} for creating instances from bank names
124
+ * Checks if an unknown value is a Bank instance
125
+ * @param obj The value to validate
126
+ * @returns Type predicate indicating if the value is a valid Bank
122
127
  */
123
128
  static is(obj: unknown): obj is Bank;
124
129
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bank.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/bank.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,IAAI;IAQb,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAT7B;;;;;OAKG;gBAEgB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM;IAGrC;;;OAGG;IACH,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;;OAGG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;;OAGG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;;OAGG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;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