@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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Currency } from "./currency.js";
|
|
2
|
+
/**
|
|
3
|
+
* Service for managing currency data.
|
|
4
|
+
* @class CurrencyService
|
|
5
|
+
*/
|
|
6
|
+
export declare class CurrencyService {
|
|
7
|
+
private static instance;
|
|
8
|
+
private currencyList;
|
|
9
|
+
private currencyRecord;
|
|
10
|
+
private nameRecord;
|
|
11
|
+
private staticReferences;
|
|
12
|
+
private constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Gets the singleton instance of CurrencyService.
|
|
15
|
+
* Creates the instance if it doesn't exist.
|
|
16
|
+
* @static
|
|
17
|
+
* @returns {CurrencyService} The singleton instance
|
|
18
|
+
*/
|
|
19
|
+
static getInstance(): CurrencyService;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes the service with currency data.
|
|
22
|
+
* Should be called once when your application starts.
|
|
23
|
+
*/
|
|
24
|
+
private initialize;
|
|
25
|
+
/**
|
|
26
|
+
* Gets all currencies.
|
|
27
|
+
* @returns {Currency[]} Array of all currencies
|
|
28
|
+
*/
|
|
29
|
+
getAll(): Currency[];
|
|
30
|
+
/**
|
|
31
|
+
* Gets all currencies as a record.
|
|
32
|
+
* @returns {Record<string, Currency>} Record of currency codes and currency objects
|
|
33
|
+
*/
|
|
34
|
+
getAllAsRecord(): Record<string, Currency>;
|
|
35
|
+
/**
|
|
36
|
+
* Gets static currency references to be used by the Currency class.
|
|
37
|
+
* @returns {Map<string, Currency>} Map of static references
|
|
38
|
+
*/
|
|
39
|
+
getStaticReferences(): Map<string, Currency>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves a currency by its ISO code.
|
|
42
|
+
* @param {string} code The ISO code of the currency.
|
|
43
|
+
* @returns {Currency | undefined} The currency corresponding to the ISO code or `undefined` if not found.
|
|
44
|
+
*/
|
|
45
|
+
fromCode(code: string): Currency | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves a currency by its name.
|
|
48
|
+
* @param {string} currencyName The name of the currency.
|
|
49
|
+
* @returns {Currency | undefined} The currency corresponding to the name or `undefined` if not found.
|
|
50
|
+
*/
|
|
51
|
+
fromName(currencyName: string): Currency | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Validates if a given ISO currency code is valid
|
|
54
|
+
*
|
|
55
|
+
* @param {string | null | undefined} code - The currency code to validate.
|
|
56
|
+
* Should be a three-letter ISO currency code (e.g., 'USD', 'EUR').
|
|
57
|
+
*
|
|
58
|
+
* @returns {boolean} Returns true if:
|
|
59
|
+
* - The currency code is not null/undefined
|
|
60
|
+
* - The currency code successfully resolves to a valid Currency instance
|
|
61
|
+
* Returns false otherwise.
|
|
62
|
+
*/
|
|
63
|
+
isValidCode(code?: string | null): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Validates if a given currency name is valid
|
|
66
|
+
*
|
|
67
|
+
* @param {string | null | undefined} currencyName - The currency name to validate.
|
|
68
|
+
*
|
|
69
|
+
* @returns {boolean} Returns true if:
|
|
70
|
+
* - The currency name is not null/undefined
|
|
71
|
+
* - The currency name successfully resolves to a valid Currency instance
|
|
72
|
+
* Returns false otherwise.
|
|
73
|
+
*/
|
|
74
|
+
isValidName(currencyName?: string | null): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Gets a regex-ready pattern matching all currency symbols
|
|
77
|
+
* Pattern is memoized for performance
|
|
78
|
+
* @returns {string} Pipe-separated pattern of escaped currency symbols
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* const pattern = currencyService.getCurrencySymbolPattern();
|
|
82
|
+
* // Returns something like: "\$|€|\£|¥"
|
|
83
|
+
*/
|
|
84
|
+
getCurrencySymbolPattern(): string;
|
|
85
|
+
/**
|
|
86
|
+
* Escapes special characters in a string for use in regular expressions
|
|
87
|
+
* @private
|
|
88
|
+
* @param {string} string - The string to escape
|
|
89
|
+
* @returns {string} The escaped string
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* private escapeRegExp("$") // Returns "\$"
|
|
93
|
+
*/
|
|
94
|
+
private escapeRegExp;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../src/src/models/currency/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAiBzC;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAkB;IACzC,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,cAAc,CAAgC;IACtD,OAAO,CAAC,UAAU,CAAgC;IAGlD,OAAO,CAAC,gBAAgB,CAAoC;IAE5D,OAAO;IAEP;;;;;OAKG;IACH,MAAM,CAAC,WAAW,IAAI,eAAe;IAQrC;;;OAGG;IACH,OAAO,CAAC,UAAU;IAmDlB;;;OAGG;IACH,MAAM,IAAI,QAAQ,EAAE;IAIpB;;;OAGG;IACH,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC;IAI1C;;;OAGG;IACH,mBAAmB,IAAI,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;IAI5C;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAI5C;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAmBpD;;;;;;;;;;OAUG;IACH,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAM1C;;;;;;;;;OASG;IACH,WAAW,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAMlD;;;;;;;;OAQG;IACH,wBAAwB,IAAI,MAAM;IAUlC;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;CAGrB"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Currency } from "./currency.js";
|
|
2
|
+
import file from "../../data/currencies.js";
|
|
3
|
+
/**
|
|
4
|
+
* Service for managing currency data.
|
|
5
|
+
* @class CurrencyService
|
|
6
|
+
*/
|
|
7
|
+
export class CurrencyService {
|
|
8
|
+
constructor() {
|
|
9
|
+
Object.defineProperty(this, "currencyList", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: []
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "currencyRecord", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: {}
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "nameRecord", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: {}
|
|
26
|
+
});
|
|
27
|
+
// Static references for direct access through Currency class
|
|
28
|
+
Object.defineProperty(this, "staticReferences", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: new Map()
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the singleton instance of CurrencyService.
|
|
37
|
+
* Creates the instance if it doesn't exist.
|
|
38
|
+
* @static
|
|
39
|
+
* @returns {CurrencyService} The singleton instance
|
|
40
|
+
*/
|
|
41
|
+
static getInstance() {
|
|
42
|
+
if (!CurrencyService.instance) {
|
|
43
|
+
CurrencyService.instance = new CurrencyService();
|
|
44
|
+
CurrencyService.instance.initialize();
|
|
45
|
+
}
|
|
46
|
+
return CurrencyService.instance;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Initializes the service with currency data.
|
|
50
|
+
* Should be called once when your application starts.
|
|
51
|
+
*/
|
|
52
|
+
initialize() {
|
|
53
|
+
try {
|
|
54
|
+
const data = JSON.parse(JSON.stringify(file));
|
|
55
|
+
const currencies = Object.values(data).map((c) => new Currency(c.symbol, c.name, c.symbol_native, c.decimal_digits, c.rounding, c.code, c.name_plural));
|
|
56
|
+
const codeRecord = {};
|
|
57
|
+
const nameRecord = {};
|
|
58
|
+
currencies.forEach((currency) => {
|
|
59
|
+
// Populate code record
|
|
60
|
+
codeRecord[currency.code] = currency;
|
|
61
|
+
// Add to record by name
|
|
62
|
+
nameRecord[currency.name.toUpperCase()] = currency;
|
|
63
|
+
const upperCode = currency.code.toUpperCase();
|
|
64
|
+
// Add to static references for uppercase code
|
|
65
|
+
this.staticReferences.set(upperCode, currency);
|
|
66
|
+
// Add formatted full name static reference based on name property
|
|
67
|
+
// Transform from "US Dollar" to "US_DOLLAR"
|
|
68
|
+
const nameKey = currency.name
|
|
69
|
+
.toUpperCase()
|
|
70
|
+
.replace(/\s+/g, "_")
|
|
71
|
+
.replace(/[-(),.']/g, "")
|
|
72
|
+
.replace(/&/g, "AND");
|
|
73
|
+
this.staticReferences.set(nameKey, currency);
|
|
74
|
+
});
|
|
75
|
+
this.currencyRecord = codeRecord;
|
|
76
|
+
this.nameRecord = nameRecord;
|
|
77
|
+
this.currencyList = currencies;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error("Failed to initialize CurrencyService:", error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Gets all currencies.
|
|
85
|
+
* @returns {Currency[]} Array of all currencies
|
|
86
|
+
*/
|
|
87
|
+
getAll() {
|
|
88
|
+
return this.currencyList;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Gets all currencies as a record.
|
|
92
|
+
* @returns {Record<string, Currency>} Record of currency codes and currency objects
|
|
93
|
+
*/
|
|
94
|
+
getAllAsRecord() {
|
|
95
|
+
return this.currencyRecord;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Gets static currency references to be used by the Currency class.
|
|
99
|
+
* @returns {Map<string, Currency>} Map of static references
|
|
100
|
+
*/
|
|
101
|
+
getStaticReferences() {
|
|
102
|
+
return this.staticReferences;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Retrieves a currency by its ISO code.
|
|
106
|
+
* @param {string} code The ISO code of the currency.
|
|
107
|
+
* @returns {Currency | undefined} The currency corresponding to the ISO code or `undefined` if not found.
|
|
108
|
+
*/
|
|
109
|
+
fromCode(code) {
|
|
110
|
+
return this.currencyRecord[code.trim().toUpperCase()];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves a currency by its name.
|
|
114
|
+
* @param {string} currencyName The name of the currency.
|
|
115
|
+
* @returns {Currency | undefined} The currency corresponding to the name or `undefined` if not found.
|
|
116
|
+
*/
|
|
117
|
+
fromName(currencyName) {
|
|
118
|
+
const input = currencyName.trim().toUpperCase();
|
|
119
|
+
// First try direct lookup in name record
|
|
120
|
+
const directMatch = this.nameRecord[input];
|
|
121
|
+
if (directMatch)
|
|
122
|
+
return directMatch;
|
|
123
|
+
// If not found, try more lenient matching
|
|
124
|
+
for (const [name, currObj] of Object.entries(this.nameRecord)) {
|
|
125
|
+
if (name.toUpperCase() === input) {
|
|
126
|
+
return currObj;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Finally, try case-insensitive exact match
|
|
130
|
+
return this.currencyList.find((currency) => currency.name.toUpperCase() === input);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Validates if a given ISO currency code is valid
|
|
134
|
+
*
|
|
135
|
+
* @param {string | null | undefined} code - The currency code to validate.
|
|
136
|
+
* Should be a three-letter ISO currency code (e.g., 'USD', 'EUR').
|
|
137
|
+
*
|
|
138
|
+
* @returns {boolean} Returns true if:
|
|
139
|
+
* - The currency code is not null/undefined
|
|
140
|
+
* - The currency code successfully resolves to a valid Currency instance
|
|
141
|
+
* Returns false otherwise.
|
|
142
|
+
*/
|
|
143
|
+
isValidCode(code) {
|
|
144
|
+
if (!code)
|
|
145
|
+
return false;
|
|
146
|
+
const currency = this.fromCode(code);
|
|
147
|
+
return !!currency;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Validates if a given currency name is valid
|
|
151
|
+
*
|
|
152
|
+
* @param {string | null | undefined} currencyName - The currency name to validate.
|
|
153
|
+
*
|
|
154
|
+
* @returns {boolean} Returns true if:
|
|
155
|
+
* - The currency name is not null/undefined
|
|
156
|
+
* - The currency name successfully resolves to a valid Currency instance
|
|
157
|
+
* Returns false otherwise.
|
|
158
|
+
*/
|
|
159
|
+
isValidName(currencyName) {
|
|
160
|
+
if (!currencyName)
|
|
161
|
+
return false;
|
|
162
|
+
const currency = this.fromName(currencyName);
|
|
163
|
+
return !!currency;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Gets a regex-ready pattern matching all currency symbols
|
|
167
|
+
* Pattern is memoized for performance
|
|
168
|
+
* @returns {string} Pipe-separated pattern of escaped currency symbols
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* const pattern = currencyService.getCurrencySymbolPattern();
|
|
172
|
+
* // Returns something like: "\$|€|\£|¥"
|
|
173
|
+
*/
|
|
174
|
+
getCurrencySymbolPattern() {
|
|
175
|
+
const symbols = new Set();
|
|
176
|
+
Object.values(this.currencyList).forEach((currency) => {
|
|
177
|
+
symbols.add(this.escapeRegExp(currency.symbol));
|
|
178
|
+
symbols.add(this.escapeRegExp(currency.symbolNative));
|
|
179
|
+
});
|
|
180
|
+
return Array.from(symbols).join("|");
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Escapes special characters in a string for use in regular expressions
|
|
184
|
+
* @private
|
|
185
|
+
* @param {string} string - The string to escape
|
|
186
|
+
* @returns {string} The escaped string
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* private escapeRegExp("$") // Returns "\$"
|
|
190
|
+
*/
|
|
191
|
+
escapeRegExp(string) {
|
|
192
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
|
package/esm/src/models/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration for various phone number formats
|
|
3
|
+
*/
|
|
4
|
+
export declare enum PhoneNumberFormat {
|
|
5
|
+
/** E.164 format with plus sign (e.g., +12025550123) */
|
|
6
|
+
INTERNATIONAL = "INTERNATIONAL",
|
|
7
|
+
/** National format with spaces (formatting varies by country) */
|
|
8
|
+
NATIONAL = "NATIONAL",
|
|
9
|
+
/** Compact format without country code (e.g., 2025550123) */
|
|
10
|
+
COMPACT = "COMPACT",
|
|
11
|
+
/** RFC3966 format (e.g., tel:+1-202-555-0123) */
|
|
12
|
+
RFC3966 = "RFC3966"
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/format.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,uDAAuD;IACvD,aAAa,kBAAkB;IAC/B,iEAAiE;IACjE,QAAQ,aAAa;IACrB,6DAA6D;IAC7D,OAAO,YAAY;IACnB,iDAAiD;IACjD,OAAO,YAAY;CACpB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration for various phone number formats
|
|
3
|
+
*/
|
|
4
|
+
export var PhoneNumberFormat;
|
|
5
|
+
(function (PhoneNumberFormat) {
|
|
6
|
+
/** E.164 format with plus sign (e.g., +12025550123) */
|
|
7
|
+
PhoneNumberFormat["INTERNATIONAL"] = "INTERNATIONAL";
|
|
8
|
+
/** National format with spaces (formatting varies by country) */
|
|
9
|
+
PhoneNumberFormat["NATIONAL"] = "NATIONAL";
|
|
10
|
+
/** Compact format without country code (e.g., 2025550123) */
|
|
11
|
+
PhoneNumberFormat["COMPACT"] = "COMPACT";
|
|
12
|
+
/** RFC3966 format (e.g., tel:+1-202-555-0123) */
|
|
13
|
+
PhoneNumberFormat["RFC3966"] = "RFC3966";
|
|
14
|
+
})(PhoneNumberFormat || (PhoneNumberFormat = {}));
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview
|
|
3
|
+
*
|
|
4
|
+
* # Global Phone Number Management System
|
|
5
|
+
*
|
|
6
|
+
* ## Features
|
|
7
|
+
* 1. Parsing and validation of international format phone numbers
|
|
8
|
+
* 2. Support for phone numbers across countries using standardized metadata
|
|
9
|
+
* 3. Standardized storage in E.164 format
|
|
10
|
+
* 4. Formatting options for display and API use:
|
|
11
|
+
* - INTERNATIONAL: "+{dial_code}{compactNumber}" - Returns the number with a plus and country code
|
|
12
|
+
* - COMPACT: Just the compactNumber without formatting
|
|
13
|
+
* - NATIONAL: Not fully implemented for global numbers, returns the compact number
|
|
14
|
+
* - RFC3966: "tel:+{dial_code}{compactNumber}" - Returns the number in URI format
|
|
15
|
+
* 5. Integration with Country class for country data
|
|
16
|
+
*/
|
|
17
|
+
import { Country } from "../../country/country.js";
|
|
18
|
+
import { PhoneNumberFormat } from "../format.js";
|
|
19
|
+
/**
|
|
20
|
+
* Options for parsing phone numbers
|
|
21
|
+
*/
|
|
22
|
+
export interface PhoneNumberParseOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Default country to use when a dial code is shared by multiple countries
|
|
25
|
+
* This can be either a Country object or an ISO country code string
|
|
26
|
+
*/
|
|
27
|
+
defaultCountry?: Country | string;
|
|
28
|
+
/**
|
|
29
|
+
* Whether to throw an error when encountering an ambiguous phone number
|
|
30
|
+
* with a shared dial code
|
|
31
|
+
*/
|
|
32
|
+
throwOnAmbiguous?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents a global phone number
|
|
36
|
+
*/
|
|
37
|
+
export declare class PhoneNumber {
|
|
38
|
+
/** The associated country object */
|
|
39
|
+
private _country;
|
|
40
|
+
/** The national number without country code or leading zeros */
|
|
41
|
+
private _compactNumber;
|
|
42
|
+
/**
|
|
43
|
+
* Private constructor to prevent direct instantiation.
|
|
44
|
+
* Use PhoneNumber.from() or PhoneNumber.fromWithCountry() instead.
|
|
45
|
+
*
|
|
46
|
+
* @param country - The Country object representing the phone number's country
|
|
47
|
+
* @param compactNumber - The phone number in compact format without country code
|
|
48
|
+
*/
|
|
49
|
+
private constructor();
|
|
50
|
+
/**
|
|
51
|
+
* Gets the Country object associated with this phone number
|
|
52
|
+
*/
|
|
53
|
+
get country(): Country;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the country code (ISO) of the phone number
|
|
56
|
+
*/
|
|
57
|
+
get countryCode(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the dial code (numeric) of the phone number
|
|
60
|
+
*/
|
|
61
|
+
get dialCode(): number;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the compact number (national number without formatting)
|
|
64
|
+
*/
|
|
65
|
+
get compactNumber(): string;
|
|
66
|
+
/**
|
|
67
|
+
* Gets the full E.164 formatted number (e.g., +12025550123)
|
|
68
|
+
*/
|
|
69
|
+
get formattedNumber(): string;
|
|
70
|
+
/**
|
|
71
|
+
* Gets a human-readable label for this phone number
|
|
72
|
+
* Uses international format with spaces for readability
|
|
73
|
+
*/
|
|
74
|
+
get label(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Formats the phone number according to the specified format
|
|
77
|
+
*
|
|
78
|
+
* @param format - The desired format
|
|
79
|
+
* @returns The formatted phone number string
|
|
80
|
+
*/
|
|
81
|
+
getWithFormat(format: PhoneNumberFormat): string;
|
|
82
|
+
/**
|
|
83
|
+
* Formats the phone number in international format
|
|
84
|
+
* Returns +{dial_code}{compactNumber} format
|
|
85
|
+
*/
|
|
86
|
+
private formatInternational;
|
|
87
|
+
/**
|
|
88
|
+
* Formats the phone number according to RFC3966
|
|
89
|
+
* Returns tel:+{dial_code}{compactNumber} format
|
|
90
|
+
*/
|
|
91
|
+
private formatRFC3966;
|
|
92
|
+
/**
|
|
93
|
+
* Validates that this phone number meets the requirements for its country
|
|
94
|
+
* Relies entirely on pattern validation
|
|
95
|
+
*
|
|
96
|
+
* @returns True if the phone number is valid, false otherwise
|
|
97
|
+
*/
|
|
98
|
+
validate(): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a PhoneNumber from an international format string.
|
|
101
|
+
* Only accepts the international format with a leading '+'.
|
|
102
|
+
* Thoroughly cleans the input by removing all non-digit characters except the leading '+'.
|
|
103
|
+
*
|
|
104
|
+
* @param input - The phone number string in international format (e.g., "+1 (202) 555-0123")
|
|
105
|
+
* @param options - Options for handling parsing, including defaultCountry and throwOnAmbiguous
|
|
106
|
+
* @returns A PhoneNumber instance if parsing succeeded, undefined otherwise
|
|
107
|
+
* @throws SharedDialCodeError when a shared dial code is encountered and throwOnAmbiguous is true
|
|
108
|
+
*/
|
|
109
|
+
static from(input: string, options?: PhoneNumberParseOptions): PhoneNumber | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Creates a PhoneNumber from various formats when a country is explicitly provided.
|
|
112
|
+
* Supports multiple input formats:
|
|
113
|
+
* - International format with plus and country code: "+{code}{number}" (e.g., "+12025550123")
|
|
114
|
+
* - Format with just country code: "{code}{number}" (e.g., "12025550123")
|
|
115
|
+
* - Local format with leading zero: "0{number}" (e.g., "02025550123")
|
|
116
|
+
* - Just the national number: "{number}" (e.g., "2025550123")
|
|
117
|
+
*
|
|
118
|
+
* Thoroughly cleans the input by removing all non-digit characters except the leading '+'.
|
|
119
|
+
*
|
|
120
|
+
* @param input - The phone number string in any format
|
|
121
|
+
* @param country - The Country object for this phone number
|
|
122
|
+
* @returns A PhoneNumber instance if parsing succeeded, undefined otherwise
|
|
123
|
+
*/
|
|
124
|
+
static fromWithCountry(input: string, country: Country): PhoneNumber | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Checks if a string can be constructed into a valid phone number.
|
|
127
|
+
*
|
|
128
|
+
* @param input - The string to validate
|
|
129
|
+
* @param options - Options for handling parsing
|
|
130
|
+
* @returns True if the input can be parsed into a valid phone number, false otherwise
|
|
131
|
+
*/
|
|
132
|
+
static canConstruct(input?: string | null, options?: PhoneNumberParseOptions): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Checks if a string can be constructed into a valid phone number with a given country.
|
|
135
|
+
*
|
|
136
|
+
* @param input - The string to validate
|
|
137
|
+
* @param country - The Country object to use
|
|
138
|
+
* @returns True if the input can be parsed into a valid phone number, false otherwise
|
|
139
|
+
*/
|
|
140
|
+
static canConstructWithCountry(input?: string | null, country?: Country | null): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Type guard to check if an unknown object is a valid PhoneNumber instance.
|
|
143
|
+
*
|
|
144
|
+
* @param obj - The object to check
|
|
145
|
+
* @returns Type predicate indicating if the object is a valid PhoneNumber
|
|
146
|
+
*/
|
|
147
|
+
static is(obj: unknown): obj is PhoneNumber;
|
|
148
|
+
/**
|
|
149
|
+
* Attempts to extract the country from a phone number string in international format.
|
|
150
|
+
*
|
|
151
|
+
* For shared dial codes, this will return undefined unless a default country is provided.
|
|
152
|
+
*
|
|
153
|
+
* @param input - The phone number string to parse (must be in international format)
|
|
154
|
+
* @param options - Options for handling shared dial codes
|
|
155
|
+
* @returns The Country object if found, undefined if ambiguous or not found
|
|
156
|
+
* @throws SharedDialCodeError when a shared dial code is encountered and throwOnAmbiguous is true
|
|
157
|
+
*/
|
|
158
|
+
static getCountry(input: string, options?: PhoneNumberParseOptions): Country | undefined;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=phone_number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone_number.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/phone_number/global/phone_number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAKnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAElC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAU;IAC1B,gEAAgE;IAChE,OAAO,CAAC,cAAc,CAAS;IAE/B;;;;;;OAMG;IACH,OAAO;IAKP;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAKrB;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM;IAoBhD;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;;OAKG;IACH,QAAQ,IAAI,OAAO;IAuCnB;;;;;;;;;OASG;WACW,IAAI,CAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,uBAAuB,GAChC,WAAW,GAAG,SAAS;IAsG1B;;;;;;;;;;;;;OAaG;WACW,eAAe,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACf,WAAW,GAAG,SAAS;IA0D1B;;;;;;OAMG;WACW,YAAY,CACxB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO;IAsBV;;;;;;OAMG;WACW,uBAAuB,CACnC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,GACvB,OAAO;IAaV;;;;;OAKG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW;IA2BlD;;;;;;;;;OASG;WACW,UAAU,CACtB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,GAAG,SAAS;CAwDvB"}
|