@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.
- package/README.md +126 -25
- package/esm/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
- package/esm/mod.d.ts +2 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -0
- package/esm/src/config/config_service.d.ts +11 -0
- package/esm/src/config/config_service.d.ts.map +1 -0
- package/esm/src/config/config_service.js +19 -0
- package/esm/src/config/index.d.ts +2 -0
- package/esm/src/config/index.d.ts.map +1 -0
- package/esm/src/config/index.js +1 -0
- package/esm/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
- package/esm/src/data/banks_tz.d.ts.map +1 -0
- package/esm/src/data/countries.d.ts +6 -0
- package/esm/src/data/countries.d.ts.map +1 -0
- package/esm/src/data/countries.js +974 -0
- package/esm/src/data/currencies.d.ts +1901 -0
- package/esm/src/data/currencies.d.ts.map +1 -0
- package/esm/src/data/currencies.js +1073 -0
- package/esm/src/data/phone_patterns.d.ts +3809 -0
- package/esm/src/data/phone_patterns.d.ts.map +1 -0
- package/esm/src/data/phone_patterns.js +2325 -0
- package/esm/src/models/amount/amount.d.ts +10 -12
- package/esm/src/models/amount/amount.d.ts.map +1 -1
- package/esm/src/models/amount/amount.js +58 -96
- package/esm/src/models/bank/bank.d.ts +58 -53
- package/esm/src/models/bank/bank.d.ts.map +1 -1
- package/esm/src/models/bank/bank.js +49 -84
- package/esm/src/models/bank/index.d.ts +1 -1
- package/esm/src/models/bank/index.d.ts.map +1 -1
- package/esm/src/models/bank/index.js +1 -1
- package/esm/src/models/bank/service.d.ts +106 -0
- package/esm/src/models/bank/service.d.ts.map +1 -0
- package/esm/src/models/bank/service.js +240 -0
- package/esm/src/models/country/country.d.ts +568 -0
- package/esm/src/models/country/country.d.ts.map +1 -0
- package/esm/src/models/country/country.js +165 -0
- package/esm/src/models/country/country.test.d.ts.map +1 -0
- package/esm/src/models/country/index.d.ts +3 -0
- package/esm/src/models/country/index.d.ts.map +1 -0
- package/esm/src/models/country/index.js +2 -0
- package/esm/src/models/country/service.d.ts +75 -0
- package/esm/src/models/country/service.d.ts.map +1 -0
- package/esm/src/models/country/service.js +267 -0
- package/esm/src/models/currency/currency.d.ts +341 -0
- package/esm/src/models/currency/currency.d.ts.map +1 -0
- package/esm/src/models/currency/currency.js +225 -0
- package/esm/src/models/currency/currency.test.d.ts.map +1 -0
- package/esm/src/models/currency/index.d.ts +3 -0
- package/esm/src/models/currency/index.d.ts.map +1 -0
- package/esm/src/models/currency/index.js +2 -0
- package/esm/src/models/currency/service.d.ts +96 -0
- package/esm/src/models/currency/service.d.ts.map +1 -0
- package/esm/src/models/currency/service.js +194 -0
- package/esm/src/models/index.d.ts +2 -0
- package/esm/src/models/index.d.ts.map +1 -1
- package/esm/src/models/index.js +2 -0
- package/esm/src/models/phone_number/format.d.ts +14 -0
- package/esm/src/models/phone_number/format.d.ts.map +1 -0
- package/esm/src/models/phone_number/format.js +14 -0
- package/esm/src/models/phone_number/global/phone_number.d.ts +160 -0
- package/esm/src/models/phone_number/global/phone_number.d.ts.map +1 -0
- package/esm/src/models/phone_number/global/phone_number.js +453 -0
- package/esm/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
- package/esm/src/models/phone_number/global/service.d.ts +260 -0
- package/esm/src/models/phone_number/global/service.d.ts.map +1 -0
- package/esm/src/models/phone_number/global/service.js +477 -0
- package/esm/src/models/phone_number/global/service.test.d.ts.map +1 -0
- package/esm/src/models/phone_number/index.d.ts +5 -3
- package/esm/src/models/phone_number/index.d.ts.map +1 -1
- package/esm/src/models/phone_number/index.js +5 -3
- package/esm/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
- package/esm/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
- package/esm/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +2 -2
- package/esm/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
- package/esm/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
- package/{script/src/models/phone_number → esm/src/models/phone_number/tz}/phone_number.d.ts +46 -29
- package/esm/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
- package/esm/src/models/phone_number/{phone_number.js → tz/phone_number.js} +87 -41
- package/esm/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
- package/esm/src/reports/index.d.ts +2 -0
- package/esm/src/reports/index.d.ts.map +1 -0
- package/esm/src/reports/index.js +1 -0
- package/esm/src/reports/report_manager.d.ts +144 -0
- package/esm/src/reports/report_manager.d.ts.map +1 -0
- package/esm/src/reports/report_manager.js +315 -0
- package/package.json +4 -3
- package/script/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
- package/script/mod.d.ts +2 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +2 -0
- package/script/src/config/config_service.d.ts +11 -0
- package/script/src/config/config_service.d.ts.map +1 -0
- package/script/src/config/config_service.js +23 -0
- package/script/src/config/index.d.ts +2 -0
- package/script/src/config/index.d.ts.map +1 -0
- package/script/src/config/index.js +17 -0
- package/script/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
- package/script/src/data/banks_tz.d.ts.map +1 -0
- package/script/src/data/countries.d.ts +6 -0
- package/script/src/data/countries.d.ts.map +1 -0
- package/script/src/data/countries.js +976 -0
- package/script/src/data/currencies.d.ts +1901 -0
- package/script/src/data/currencies.d.ts.map +1 -0
- package/script/src/data/currencies.js +1075 -0
- package/script/src/data/phone_patterns.d.ts +3809 -0
- package/script/src/data/phone_patterns.d.ts.map +1 -0
- package/script/src/data/phone_patterns.js +2327 -0
- package/script/src/models/amount/amount.d.ts +10 -12
- package/script/src/models/amount/amount.d.ts.map +1 -1
- package/script/src/models/amount/amount.js +60 -98
- package/script/src/models/bank/bank.d.ts +58 -53
- package/script/src/models/bank/bank.d.ts.map +1 -1
- package/script/src/models/bank/bank.js +49 -87
- package/script/src/models/bank/index.d.ts +1 -1
- package/script/src/models/bank/index.d.ts.map +1 -1
- package/script/src/models/bank/index.js +1 -1
- package/script/src/models/bank/service.d.ts +106 -0
- package/script/src/models/bank/service.d.ts.map +1 -0
- package/script/src/models/bank/service.js +247 -0
- package/script/src/models/country/country.d.ts +568 -0
- package/script/src/models/country/country.d.ts.map +1 -0
- package/script/src/models/country/country.js +169 -0
- package/script/src/models/country/country.test.d.ts.map +1 -0
- package/script/src/models/country/index.d.ts +3 -0
- package/script/src/models/country/index.d.ts.map +1 -0
- package/script/src/models/country/index.js +18 -0
- package/script/src/models/country/service.d.ts +75 -0
- package/script/src/models/country/service.d.ts.map +1 -0
- package/script/src/models/country/service.js +274 -0
- package/script/src/models/currency/currency.d.ts +341 -0
- package/script/src/models/currency/currency.d.ts.map +1 -0
- package/script/src/models/currency/currency.js +229 -0
- package/script/src/models/currency/currency.test.d.ts.map +1 -0
- package/script/src/models/currency/index.d.ts +3 -0
- package/script/src/models/currency/index.d.ts.map +1 -0
- package/script/src/models/currency/index.js +18 -0
- package/script/src/models/currency/service.d.ts +96 -0
- package/script/src/models/currency/service.d.ts.map +1 -0
- package/script/src/models/currency/service.js +201 -0
- package/script/src/models/index.d.ts +2 -0
- package/script/src/models/index.d.ts.map +1 -1
- package/script/src/models/index.js +2 -0
- package/script/src/models/phone_number/format.d.ts +14 -0
- package/script/src/models/phone_number/format.d.ts.map +1 -0
- package/script/src/models/phone_number/format.js +17 -0
- package/script/src/models/phone_number/global/phone_number.d.ts +160 -0
- package/script/src/models/phone_number/global/phone_number.d.ts.map +1 -0
- package/script/src/models/phone_number/global/phone_number.js +457 -0
- package/script/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
- package/script/src/models/phone_number/global/service.d.ts +260 -0
- package/script/src/models/phone_number/global/service.d.ts.map +1 -0
- package/script/src/models/phone_number/global/service.js +485 -0
- package/script/src/models/phone_number/global/service.test.d.ts.map +1 -0
- package/script/src/models/phone_number/index.d.ts +5 -3
- package/script/src/models/phone_number/index.d.ts.map +1 -1
- package/script/src/models/phone_number/index.js +5 -3
- package/script/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
- package/script/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
- package/script/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +1 -1
- package/script/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
- package/script/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
- package/{esm/src/models/phone_number → script/src/models/phone_number/tz}/phone_number.d.ts +46 -29
- package/script/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
- package/script/src/models/phone_number/{phone_number.js → tz/phone_number.js} +89 -43
- package/script/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
- package/script/src/reports/index.d.ts +2 -0
- package/script/src/reports/index.d.ts.map +1 -0
- package/script/src/reports/index.js +17 -0
- package/script/src/reports/report_manager.d.ts +144 -0
- package/script/src/reports/report_manager.d.ts.map +1 -0
- package/script/src/reports/report_manager.js +325 -0
- package/esm/src/models/bank/banks.d.ts.map +0 -1
- package/esm/src/models/bank/utils.d.ts +0 -25
- package/esm/src/models/bank/utils.d.ts.map +0 -1
- package/esm/src/models/bank/utils.js +0 -35
- package/esm/src/models/phone_number/antd_validator.d.ts.map +0 -1
- package/esm/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
- package/esm/src/models/phone_number/network_operator.d.ts.map +0 -1
- package/esm/src/models/phone_number/phone_number.d.ts.map +0 -1
- package/esm/src/models/phone_number/phone_number.test.d.ts.map +0 -1
- package/script/src/models/bank/banks.d.ts.map +0 -1
- package/script/src/models/bank/utils.d.ts +0 -25
- package/script/src/models/bank/utils.d.ts.map +0 -1
- package/script/src/models/bank/utils.js +0 -41
- package/script/src/models/phone_number/antd_validator.d.ts.map +0 -1
- package/script/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
- package/script/src/models/phone_number/network_operator.d.ts.map +0 -1
- package/script/src/models/phone_number/phone_number.d.ts.map +0 -1
- package/script/src/models/phone_number/phone_number.test.d.ts.map +0 -1
- /package/esm/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
- /package/esm/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
- /package/esm/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
- /package/script/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
- /package/script/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
- /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
|
|
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":"
|
|
1
|
+
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../../../src/src/models/amount/amount.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,YAAY,QAA2C,CAAC;AAE9D,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IAEpC,OAAO;IAcP;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CACT,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,YAAY,GAAE,MAAc,GAC3B,MAAM,GAAG,SAAS;IAkCrB;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,qBAAqB,IAAI,MAAM,CAKlC;IAED;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CACjB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC9B,YAAY,GAAE,MAAc,GAC3B,OAAO;IAQV;;;;;;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,9 +1,10 @@
|
|
|
1
1
|
// Regex explanation:
|
|
2
2
|
// ^(?:\d{1,3}(?:,\d{3})*|\d+) - Either grouped digits with commas OR just digits
|
|
3
|
+
import { CurrencyService } from "../currency/service.js";
|
|
3
4
|
// (?:\.\d+)?$ - Optional decimal part with any number of digits
|
|
4
5
|
const AMOUNT_REGEX = /^(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/;
|
|
5
6
|
class Amount {
|
|
6
|
-
constructor(value, text) {
|
|
7
|
+
constructor(value, text, currencyCode = "TZS") {
|
|
7
8
|
Object.defineProperty(this, "value", {
|
|
8
9
|
enumerable: true,
|
|
9
10
|
configurable: true,
|
|
@@ -16,22 +17,37 @@ class Amount {
|
|
|
16
17
|
writable: true,
|
|
17
18
|
value: void 0
|
|
18
19
|
});
|
|
20
|
+
Object.defineProperty(this, "currency", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
const code = CurrencyService.getInstance().fromCode(currencyCode);
|
|
27
|
+
if (!code) {
|
|
28
|
+
throw new Error("Invalid code!");
|
|
29
|
+
}
|
|
19
30
|
this.value = value;
|
|
20
31
|
this.text = text;
|
|
32
|
+
this.currency = code;
|
|
21
33
|
}
|
|
22
34
|
/**
|
|
23
35
|
* Creates an Amount instance from a string or number input
|
|
24
36
|
* Returns undefined if input is invalid or negative
|
|
25
37
|
* @param input - The input value (string or number)
|
|
38
|
+
* @param currencyCode - The currency code (defaults to TZS)
|
|
26
39
|
* @returns Amount instance or undefined if validation fails
|
|
27
40
|
*/
|
|
28
|
-
static from(input) {
|
|
41
|
+
static from(input, currencyCode = "TZS") {
|
|
42
|
+
const currency = CurrencyService.getInstance().fromCode(currencyCode);
|
|
43
|
+
if (!currency)
|
|
44
|
+
return undefined;
|
|
29
45
|
let amountText = input.toString().trim();
|
|
46
|
+
amountText = removeCommasAndCurrency(amountText);
|
|
30
47
|
if (hasComma(amountText)) {
|
|
31
48
|
if (!hasValidCommaPlacement(amountText))
|
|
32
49
|
return undefined;
|
|
33
50
|
}
|
|
34
|
-
amountText = removeCommasAndCurrency(amountText);
|
|
35
51
|
// Handle string input
|
|
36
52
|
if (!AMOUNT_REGEX.test(amountText))
|
|
37
53
|
return undefined;
|
|
@@ -39,19 +55,28 @@ class Amount {
|
|
|
39
55
|
const value = Number(amountText.replace(/,/g, ""));
|
|
40
56
|
if (!Number.isFinite(value) || value < 0)
|
|
41
57
|
return undefined;
|
|
42
|
-
|
|
43
|
-
const roundedValue = Number(value.toFixed(
|
|
44
|
-
|
|
45
|
-
minimumFractionDigits:
|
|
46
|
-
maximumFractionDigits:
|
|
58
|
+
const dd = currency.decimalDigits;
|
|
59
|
+
const roundedValue = Number(value.toFixed(dd));
|
|
60
|
+
let text = roundedValue.toLocaleString("en-US", {
|
|
61
|
+
minimumFractionDigits: dd,
|
|
62
|
+
maximumFractionDigits: dd,
|
|
47
63
|
});
|
|
48
|
-
|
|
64
|
+
if (dd === 0) {
|
|
65
|
+
text = text.replace(".00", "");
|
|
66
|
+
}
|
|
67
|
+
return new Amount(roundedValue, text, currency.code);
|
|
49
68
|
}
|
|
50
69
|
/**
|
|
51
|
-
* Returns the formatted string representation of the amount with
|
|
70
|
+
* Returns the formatted string representation of the amount with currency
|
|
52
71
|
*/
|
|
53
72
|
get label() {
|
|
54
|
-
return
|
|
73
|
+
return `${this.currency.symbol} ${this.text}`;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns the currency code
|
|
77
|
+
*/
|
|
78
|
+
get currencyCode() {
|
|
79
|
+
return this.currency.code;
|
|
55
80
|
}
|
|
56
81
|
/**
|
|
57
82
|
* Returns the numeric value of the amount
|
|
@@ -71,13 +96,13 @@ class Amount {
|
|
|
71
96
|
/**
|
|
72
97
|
* Checks if the amount is valid
|
|
73
98
|
* @param input amount to be checked for validity
|
|
99
|
+
* @param currencyCode currency code to validate against
|
|
74
100
|
* @returns true if the amount is valid, false otherwise
|
|
75
101
|
*/
|
|
76
|
-
static canConstruct(input) {
|
|
77
|
-
/// (!input) alone does not work since input could 0 and (!input) return true for this case
|
|
102
|
+
static canConstruct(input, currencyCode = "TZS") {
|
|
78
103
|
if (input === undefined || input === null)
|
|
79
104
|
return false;
|
|
80
|
-
const amount = Amount.from(input);
|
|
105
|
+
const amount = Amount.from(input, currencyCode);
|
|
81
106
|
if (!amount)
|
|
82
107
|
return false;
|
|
83
108
|
return true;
|
|
@@ -88,15 +113,6 @@ class Amount {
|
|
|
88
113
|
*
|
|
89
114
|
* @param {unknown} obj - The value to validate
|
|
90
115
|
* @returns {obj is Amount} Type predicate indicating if the value is a valid Amount
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* const maybeAmount = JSON.parse(someData);
|
|
94
|
-
* if (Amount.is(maybeAmount)) {
|
|
95
|
-
* console.log(maybeAmount.label); // maybeAmount is typed as Amount
|
|
96
|
-
* }
|
|
97
|
-
*
|
|
98
|
-
* @see {@link Amount.canConstruct} for validating raw amount values
|
|
99
|
-
* @see {@link Amount.from} for constructing new instances
|
|
100
116
|
*/
|
|
101
117
|
static is(obj) {
|
|
102
118
|
if (!obj || typeof obj !== "object")
|
|
@@ -107,17 +123,23 @@ class Amount {
|
|
|
107
123
|
return false;
|
|
108
124
|
if (typeof maybeAmount.text !== "string")
|
|
109
125
|
return false;
|
|
126
|
+
if (!maybeAmount.currency || typeof maybeAmount.currency !== "object") {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
110
129
|
const value = maybeAmount.value;
|
|
111
130
|
const text = maybeAmount.text;
|
|
131
|
+
const currency = maybeAmount.currency.code;
|
|
112
132
|
// Validate numeric constraints
|
|
113
133
|
if (!Number.isFinite(value) || value < 0)
|
|
114
134
|
return false;
|
|
115
|
-
const canConstruct = Amount.canConstruct(value);
|
|
135
|
+
const canConstruct = Amount.canConstruct(value, currency);
|
|
116
136
|
if (!canConstruct)
|
|
117
137
|
return false;
|
|
118
|
-
const amount = Amount.from(value);
|
|
119
|
-
return amount != undefined &&
|
|
120
|
-
amount.
|
|
138
|
+
const amount = Amount.from(value, currency);
|
|
139
|
+
return amount != undefined &&
|
|
140
|
+
amount.value === value &&
|
|
141
|
+
amount.text === text &&
|
|
142
|
+
amount.currencyCode === currency;
|
|
121
143
|
}
|
|
122
144
|
/**
|
|
123
145
|
* Checks the validity of the amount data
|
|
@@ -125,7 +147,7 @@ class Amount {
|
|
|
125
147
|
*/
|
|
126
148
|
validate() {
|
|
127
149
|
try {
|
|
128
|
-
return Amount.canConstruct(this.value);
|
|
150
|
+
return Amount.canConstruct(this.value, this.currencyCode);
|
|
129
151
|
}
|
|
130
152
|
catch (_) {
|
|
131
153
|
return false;
|
|
@@ -133,95 +155,35 @@ class Amount {
|
|
|
133
155
|
}
|
|
134
156
|
}
|
|
135
157
|
/**
|
|
136
|
-
* Removes commas and
|
|
137
|
-
* Handles both prefixed and suffixed
|
|
158
|
+
* Removes commas and currency symbols from a string.
|
|
159
|
+
* Handles both prefixed and suffixed currency symbols, with or without spaces.
|
|
138
160
|
*
|
|
139
161
|
* @param {string} text - The input string to clean
|
|
140
|
-
* @returns {string} A string with commas and
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* removeCommasAndCurrency("1,234.56"); // Returns: "1234.56"
|
|
144
|
-
* removeCommasAndCurrency("TZS 1,234.56"); // Returns: "1234.56"
|
|
145
|
-
* removeCommasAndCurrency("1,234.56 TZS"); // Returns: "1234.56"
|
|
146
|
-
* removeCommasAndCurrency("TZS1,234.56"); // Returns: "1234.56"
|
|
147
|
-
* removeCommasAndCurrency("1234.56"); // Returns: "1234.56"
|
|
148
|
-
* removeCommasAndCurrency(""); // Returns: ""
|
|
149
|
-
*
|
|
150
|
-
* @remarks
|
|
151
|
-
* - Case insensitive for "TZS" symbol
|
|
152
|
-
* - Removes all commas regardless of position
|
|
153
|
-
* - Handles optional spaces around the currency symbol
|
|
154
|
-
* - Returns empty string if input is empty
|
|
162
|
+
* @returns {string} A string with commas and currency symbols removed
|
|
155
163
|
*/
|
|
156
164
|
function removeCommasAndCurrency(text) {
|
|
165
|
+
const currencyPatterns = CurrencyService.getInstance()
|
|
166
|
+
.getCurrencySymbolPattern();
|
|
167
|
+
const regex = new RegExp(`(?:${currencyPatterns})\\s*|\\s*(?:${currencyPatterns})`, "gi");
|
|
157
168
|
return text
|
|
158
|
-
.replace(
|
|
169
|
+
.replace(regex, "") // Remove currency symbols with optional spaces
|
|
159
170
|
.replace(/,/g, ""); // Remove all commas
|
|
160
171
|
}
|
|
161
|
-
|
|
162
|
-
* Checks if commas in a numeric string are correctly placed to separate groups of three digits.
|
|
163
|
-
* Only validates the part before the decimal point if one exists.
|
|
164
|
-
*
|
|
165
|
-
* @param {string} text - The input string to validate
|
|
166
|
-
* @returns {boolean} True if commas are correctly placed or if there are no commas, false otherwise
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* hasValidCommaPlacement("1,234,567.89"); // Returns: true
|
|
170
|
-
* hasValidCommaPlacement("1234567.89"); // Returns: true (no commas)
|
|
171
|
-
* hasValidCommaPlacement("1,234.56"); // Returns: true
|
|
172
|
-
* hasValidCommaPlacement("1,23,456"); // Returns: false (incorrect grouping)
|
|
173
|
-
* hasValidCommaPlacement("1,2345"); // Returns: false (incorrect grouping)
|
|
174
|
-
* hasValidCommaPlacement(",123"); // Returns: false (leading comma)
|
|
175
|
-
* hasValidCommaPlacement("1,234,"); // Returns: false (trailing comma)
|
|
176
|
-
* hasValidCommaPlacement("1,,234"); // Returns: false (consecutive commas)
|
|
177
|
-
*
|
|
178
|
-
* @remarks
|
|
179
|
-
* - Validates comma placement in the whole number part only
|
|
180
|
-
* - Each group after the first must be exactly 3 digits
|
|
181
|
-
* - First group can be 1-3 digits
|
|
182
|
-
* - Returns true if the string contains no commas
|
|
183
|
-
* - Does not validate the decimal part if present
|
|
184
|
-
*/
|
|
172
|
+
// Rest of the helper functions remain the same
|
|
185
173
|
function hasValidCommaPlacement(text) {
|
|
186
|
-
// Split at decimal point if it exists and take the whole number part
|
|
187
174
|
const wholeNumberPart = text.split(".")[0];
|
|
188
|
-
// If no commas, it's valid
|
|
189
175
|
if (!wholeNumberPart.includes(",")) {
|
|
190
176
|
return true;
|
|
191
177
|
}
|
|
192
|
-
// Split the whole number by commas
|
|
193
178
|
const groups = wholeNumberPart.split(",");
|
|
194
|
-
// Check for invalid cases:
|
|
195
|
-
// - Empty string before/after comma (e.g. ",123" or "123,")
|
|
196
|
-
// - More than one empty group (consecutive commas)
|
|
197
179
|
if (groups.some((group) => group.length === 0)) {
|
|
198
180
|
return false;
|
|
199
181
|
}
|
|
200
|
-
// First group can be 1-3 digits
|
|
201
182
|
if (groups[0].length > 3 || groups[0].length < 1) {
|
|
202
183
|
return false;
|
|
203
184
|
}
|
|
204
|
-
// All other groups must be exactly 3 digits
|
|
205
185
|
return groups.slice(1).every((group) => group.length === 3);
|
|
206
186
|
}
|
|
207
|
-
/**
|
|
208
|
-
* Checks if a string contains a comma character.
|
|
209
|
-
*
|
|
210
|
-
* @param {string} text - The input string to check
|
|
211
|
-
* @returns {boolean} True if the string contains at least one comma, false otherwise
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* hasComma("1,234.56"); // Returns: true
|
|
215
|
-
* hasComma("1234.56"); // Returns: false
|
|
216
|
-
* hasComma("hello,world"); // Returns: true
|
|
217
|
-
* hasComma(""); // Returns: false
|
|
218
|
-
* hasComma(","); // Returns: true
|
|
219
|
-
*
|
|
220
|
-
* @remarks
|
|
221
|
-
* - Returns false for empty strings
|
|
222
|
-
* - Returns true if one or more commas are present
|
|
223
|
-
* - Position of the comma doesn't matter
|
|
224
|
-
*/
|
|
225
187
|
function hasComma(text) {
|
|
226
188
|
return text.includes(",");
|
|
227
189
|
}
|
|
@@ -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
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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,qB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