react-native-format-currency 0.0.4 → 1.0.0

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.
@@ -0,0 +1,104 @@
1
+ import type { FormatResult, FormatResultObject, SupportedCurrency } from "./types";
2
+ import { type CurrencyCode } from "./currencies";
3
+ /**
4
+ * Clears the internal memoization cache.
5
+ *
6
+ * Use this to free memory or reset state during testing.
7
+ * The cache automatically evicts old entries when full (LRU with 100 entries max).
8
+ *
9
+ * @example
10
+ * clearFormatCache();
11
+ */
12
+ export declare const clearFormatCache: () => void;
13
+ /**
14
+ * Returns the current number of entries in the memoization cache.
15
+ *
16
+ * Useful for debugging or monitoring cache usage.
17
+ * Maximum cache size is 100 entries.
18
+ *
19
+ * @returns The number of cached format results
20
+ *
21
+ * @example
22
+ * console.log(getFormatCacheSize()); // 42
23
+ */
24
+ export declare const getFormatCacheSize: () => number;
25
+ /**
26
+ * Formats a numeric amount as a localized currency string.
27
+ *
28
+ * Supports 165+ ISO 4217 currency codes with proper symbol placement,
29
+ * thousands separators, and decimal formatting. Results are memoized
30
+ * for performance (LRU cache with 100 entries).
31
+ *
32
+ * @param options - Formatting options
33
+ * @param options.amount - The numeric amount to format (supports negative values)
34
+ * @param options.code - ISO 4217 currency code (e.g., 'USD', 'EUR', 'JPY')
35
+ * @param options.returnType - Optional: 'array' (default) or 'object'
36
+ * @returns Tuple of [formattedWithSymbol, formattedWithoutSymbol, symbol] or object with formatted, value, symbol
37
+ *
38
+ * @example
39
+ * // Basic usage (returns array)
40
+ * formatCurrency({ amount: 1234.56, code: 'USD' });
41
+ * // Returns: ['$1,234.56', '1,234.56', '$']
42
+ *
43
+ * @example
44
+ * // Object return type
45
+ * formatCurrency({ amount: 1234.56, code: 'USD', returnType: 'object' });
46
+ * // Returns: { formatted: '$1,234.56', value: '1,234.56', symbol: '$' }
47
+ *
48
+ * @example
49
+ * // European format (period for thousands, comma for decimals)
50
+ * formatCurrency({ amount: 1234.56, code: 'EUR' });
51
+ * // Returns: ['€1.234,56', '1.234,56', '€']
52
+ *
53
+ * @example
54
+ * // Zero-decimal currency
55
+ * formatCurrency({ amount: 1234.56, code: 'JPY' });
56
+ * // Returns: ['¥ 1,235', '1,235', '¥']
57
+ *
58
+ * @example
59
+ * // Negative amount
60
+ * formatCurrency({ amount: -99.99, code: 'GBP' });
61
+ * // Returns: ['-£99.99', '-99.99', '£']
62
+ *
63
+ * @example
64
+ * // Unknown currency code (returns plain number)
65
+ * formatCurrency({ amount: 100, code: 'XXX' });
66
+ * // Returns: ['100', '100', '']
67
+ */
68
+ export declare function formatCurrency(options: {
69
+ amount: number;
70
+ code: CurrencyCode | string;
71
+ }): FormatResult;
72
+ export declare function formatCurrency(options: {
73
+ amount: number;
74
+ code: CurrencyCode | string;
75
+ returnType: "array";
76
+ }): FormatResult;
77
+ export declare function formatCurrency(options: {
78
+ amount: number;
79
+ code: CurrencyCode | string;
80
+ returnType: "object";
81
+ }): FormatResultObject;
82
+ /**
83
+ * Returns a list of all supported currencies.
84
+ *
85
+ * Useful for building currency selector dropdowns or validating user input.
86
+ * Returns 165+ currencies sorted alphabetically by code.
87
+ *
88
+ * @returns Array of objects with `code` and `name` properties
89
+ *
90
+ * @example
91
+ * const currencies = getSupportedCurrencies();
92
+ * // [
93
+ * // { code: 'AED', name: 'United Arab Emirates Dirham' },
94
+ * // { code: 'AFN', name: 'Afghanistan Afghani' },
95
+ * // ...
96
+ * // ]
97
+ *
98
+ * @example
99
+ * // Building a dropdown
100
+ * getSupportedCurrencies().map(c => (
101
+ * <option key={c.code} value={c.code}>{c.name}</option>
102
+ * ));
103
+ */
104
+ export declare const getSupportedCurrencies: () => SupportedCurrency[];
package/dist/format.js ADDED
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSupportedCurrencies = exports.getFormatCacheSize = exports.clearFormatCache = void 0;
4
+ exports.formatCurrency = formatCurrency;
5
+ var currencies_1 = require("./currencies");
6
+ // Memoization cache for formatCurrency results
7
+ var cache = new Map();
8
+ var MAX_CACHE_SIZE = 100;
9
+ var getCacheKey = function (amount, code) {
10
+ return "".concat(amount, ":").concat(code);
11
+ };
12
+ /**
13
+ * Clears the internal memoization cache.
14
+ *
15
+ * Use this to free memory or reset state during testing.
16
+ * The cache automatically evicts old entries when full (LRU with 100 entries max).
17
+ *
18
+ * @example
19
+ * clearFormatCache();
20
+ */
21
+ var clearFormatCache = function () {
22
+ cache.clear();
23
+ };
24
+ exports.clearFormatCache = clearFormatCache;
25
+ /**
26
+ * Returns the current number of entries in the memoization cache.
27
+ *
28
+ * Useful for debugging or monitoring cache usage.
29
+ * Maximum cache size is 100 entries.
30
+ *
31
+ * @returns The number of cached format results
32
+ *
33
+ * @example
34
+ * console.log(getFormatCacheSize()); // 42
35
+ */
36
+ var getFormatCacheSize = function () { return cache.size; };
37
+ exports.getFormatCacheSize = getFormatCacheSize;
38
+ // Pre-compiled regex for thousands separator insertion (avoids regex creation per call)
39
+ var THOUSANDS_REGEX = /\B(?=(\d{3})+(?!\d))/g;
40
+ var formatNumber = function (num, format, decimals) {
41
+ if (!Number.isFinite(num)) {
42
+ return String(num);
43
+ }
44
+ var str = String(num);
45
+ var _a = str.split("."), intStr = _a[0], _b = _a[1], decStr = _b === void 0 ? "" : _b;
46
+ var thousandsSep = format === "comma" ? "," : ".";
47
+ var decimalSep = format === "comma" ? "." : ",";
48
+ var formattedInt = intStr.replace(THOUSANDS_REGEX, thousandsSep);
49
+ if (decimals === 0) {
50
+ return formattedInt;
51
+ }
52
+ var decPart = decStr.length < decimals ? decStr.padEnd(decimals, "0") : decStr;
53
+ return "".concat(formattedInt).concat(decimalSep).concat(decPart);
54
+ };
55
+ function formatCurrency(_a) {
56
+ var _b;
57
+ var amount = _a.amount, code = _a.code, returnType = _a.returnType;
58
+ // Helper to convert array result to object if requested
59
+ var toResult = function (arr) {
60
+ if (returnType === "object") {
61
+ return { formatted: arr[0], value: arr[1], symbol: arr[2] };
62
+ }
63
+ return arr;
64
+ };
65
+ // Check cache first
66
+ var cacheKey = getCacheKey(amount, code);
67
+ var cached = cache.get(cacheKey);
68
+ if (cached) {
69
+ return toResult(cached);
70
+ }
71
+ var config = currencies_1.CURRENCIES[code];
72
+ if (!config) {
73
+ var str = amount.toString();
74
+ var result_1 = [str, str, ""];
75
+ // Cache unknown currency results too
76
+ if (cache.size >= MAX_CACHE_SIZE) {
77
+ var firstKey = cache.keys().next().value;
78
+ if (firstKey !== undefined) {
79
+ cache.delete(firstKey);
80
+ }
81
+ }
82
+ cache.set(cacheKey, result_1);
83
+ return toResult(result_1);
84
+ }
85
+ var symbol = config.symbol, format = config.format, position = config.position, space = config.space;
86
+ var decimals = "decimals" in config ? ((_b = config.decimals) !== null && _b !== void 0 ? _b : 2) : 2;
87
+ var isNegative = amount < 0;
88
+ var absAmount = Math.abs(amount);
89
+ var formatted = formatNumber(absAmount, format, decimals);
90
+ var separator = space ? " " : "";
91
+ var withSymbol = position === "before"
92
+ ? "".concat(symbol).concat(separator).concat(formatted)
93
+ : "".concat(formatted).concat(separator).concat(symbol);
94
+ var formattedWithSign = isNegative ? "-".concat(withSymbol) : withSymbol;
95
+ var formattedValueWithSign = isNegative ? "-".concat(formatted) : formatted;
96
+ var result = [
97
+ formattedWithSign,
98
+ formattedValueWithSign,
99
+ symbol,
100
+ ];
101
+ // LRU eviction: remove oldest entry if cache is full
102
+ if (cache.size >= MAX_CACHE_SIZE) {
103
+ var firstKey = cache.keys().next().value;
104
+ if (firstKey !== undefined) {
105
+ cache.delete(firstKey);
106
+ }
107
+ }
108
+ cache.set(cacheKey, result);
109
+ return toResult(result);
110
+ }
111
+ /**
112
+ * Returns a list of all supported currencies.
113
+ *
114
+ * Useful for building currency selector dropdowns or validating user input.
115
+ * Returns 165+ currencies sorted alphabetically by code.
116
+ *
117
+ * @returns Array of objects with `code` and `name` properties
118
+ *
119
+ * @example
120
+ * const currencies = getSupportedCurrencies();
121
+ * // [
122
+ * // { code: 'AED', name: 'United Arab Emirates Dirham' },
123
+ * // { code: 'AFN', name: 'Afghanistan Afghani' },
124
+ * // ...
125
+ * // ]
126
+ *
127
+ * @example
128
+ * // Building a dropdown
129
+ * getSupportedCurrencies().map(c => (
130
+ * <option key={c.code} value={c.code}>{c.name}</option>
131
+ * ));
132
+ */
133
+ var getSupportedCurrencies = function () {
134
+ return Object.entries(currencies_1.CURRENCIES).map(function (_a) {
135
+ var code = _a[0], config = _a[1];
136
+ return ({
137
+ code: code,
138
+ name: config.name,
139
+ });
140
+ });
141
+ };
142
+ exports.getSupportedCurrencies = getSupportedCurrencies;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,3 @@
1
- declare type FormatCurrencyFunction = ({ amount, code, }: {
2
- amount: number;
3
- code: string;
4
- }) => [string, number, string];
5
- export declare const formatCurrency: FormatCurrencyFunction;
6
- declare type CurrencyCode = {
7
- code: string;
8
- name: string;
9
- };
10
- export declare const getSupportedCurrencies: () => CurrencyCode[];
11
- export {};
1
+ export type { CurrencyConfig, FormatResult, FormatResultObject, SupportedCurrency, } from "./types";
2
+ export { CURRENCIES, type CurrencyCode } from "./currencies";
3
+ export { formatCurrency, getSupportedCurrencies, clearFormatCache, getFormatCacheSize, } from "./format";
package/dist/index.js CHANGED
@@ -1,266 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSupportedCurrencies = exports.formatCurrency = void 0;
4
- var formatCurrency = function (_a) {
5
- var amount = _a.amount, code = _a.code;
6
- var commaFormatted = String(amount).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
7
- var periodFormatted = String(amount)
8
- .replace(".", ",")
9
- .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1.");
10
- var switchOptions = {
11
- // argentine peso (ex: $ 1.234,56)
12
- ARS: ["$ ".concat(periodFormatted), "".concat(periodFormatted), "$"],
13
- // australian dollar (ex: $ 1,234.56)
14
- AUD: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
15
- // bulgarian lev (ex: лв1,234.56)
16
- BGN: ["\u043B\u0432".concat(commaFormatted), "".concat(commaFormatted), "лв"],
17
- // brazilian real (ex: R$ 1.234,56)
18
- BRL: ["R$ ".concat(periodFormatted), "".concat(periodFormatted), "R$"],
19
- // canadian dollar (ex: $ 1,234.56)
20
- CAD: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
21
- // swiss franc (ex: fr. 1.234,56)
22
- CHF: ["fr. ".concat(periodFormatted), "".concat(periodFormatted), "fr."],
23
- // chilean peso (ex: $ 1,234.56)
24
- CLP: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
25
- // yuan renminbi (ex: ¥ 1,234.56)
26
- CNY: ["\u00A5 ".concat(commaFormatted), "".concat(commaFormatted), "¥"],
27
- // colombian peso (ex: $ 1,234.56)
28
- COP: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
29
- // czech koruna (ex: 1.234,56 Kč)
30
- CZK: ["".concat(periodFormatted, " K\u010D"), "".concat(periodFormatted), "Kč"],
31
- // danish krone (ex: kr. 1.234,56)
32
- DKK: ["kr. ".concat(periodFormatted), "".concat(periodFormatted), "kr."],
33
- // european union (ex: €1.234,56)
34
- EUR: ["\u20AC".concat(periodFormatted), "".concat(periodFormatted), "€"],
35
- // uk/great britain pound sterling (ex: £1,234.56)
36
- GBP: ["\u00A3".concat(commaFormatted), "".concat(commaFormatted), "£"],
37
- // hong kong dollar (ex: HK$ 1,234.56)
38
- HKD: ["HK$ ".concat(commaFormatted), "".concat(commaFormatted), "HK$"],
39
- // croatian kuna (ex: 1,234.56 kn)
40
- HRK: ["".concat(commaFormatted, " kn"), "".concat(commaFormatted), "kn"],
41
- // hungarian forint (ex: 1.234,56 Ft)
42
- HUF: ["".concat(periodFormatted, " Ft"), "".concat(periodFormatted), "Ft"],
43
- // indonesian rupiah (ex: Rp 1,234.56)
44
- IDR: ["Rp ".concat(commaFormatted), "".concat(commaFormatted), "Rp"],
45
- // new israeli shekel (ex: ₪ 1.234,56)
46
- ILS: ["\u20AA ".concat(periodFormatted), "".concat(periodFormatted), "₪"],
47
- // indian rupee (ex: ₹ 1,234.56)
48
- INR: ["\u20B9 ".concat(commaFormatted), "".concat(commaFormatted), "₹"],
49
- // icelandic krona (ex: kr. 1.234,56)
50
- ISK: ["kr. ".concat(periodFormatted), "".concat(periodFormatted), "kr."],
51
- // yen (ex: ¥ 1,234.56)
52
- JPY: ["\u00A5 ".concat(commaFormatted), "".concat(commaFormatted), "¥"],
53
- // won (ex: ₩ 1,234.56)
54
- KRW: ["\u20A9 ".concat(commaFormatted), "".concat(commaFormatted), "₩"],
55
- // moroccan dirham (ex: 1,234.56 .د.م.)
56
- MAD: ["".concat(commaFormatted, " .\u062F.\u0645."), "".concat(commaFormatted), ".د.م."],
57
- // mexican peso (ex: $ 1,234.56)
58
- MXN: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
59
- // malaysian ringgit (ex: RM 1,234.56)
60
- MYR: ["RM ".concat(commaFormatted), "".concat(commaFormatted), "RM"],
61
- // norwegian krone (ex: kr 1,234.56)
62
- NOK: ["kr ".concat(commaFormatted), "".concat(commaFormatted), "kr"],
63
- // new zealand dollar (ex: $ 1,234.56)
64
- NZD: ["$ ".concat(commaFormatted), "".concat(commaFormatted), "$"],
65
- // philippine peso (ex: ₱ 1,234.56)
66
- PHP: ["\u20B1 ".concat(commaFormatted), "".concat(commaFormatted), "₱"],
67
- // polish zloty (ex: 1.234,56 zł)
68
- PLN: ["".concat(periodFormatted, " z\u0142"), "".concat(periodFormatted), "zł"],
69
- // romanian new leu (ex: 1,234.56L)
70
- RON: ["".concat(commaFormatted, "L"), "".concat(commaFormatted), "L"],
71
- // russian ruble (ex: 1.234,56 p.)
72
- RUB: ["".concat(periodFormatted, " p."), "".concat(periodFormatted), "p."],
73
- // saudi riyal (ex: 1,234.56 ﷼)
74
- SAR: ["".concat(commaFormatted, " \uFDFC"), "".concat(commaFormatted), "﷼"],
75
- // swedish krona (ex: 1.234,56 kr)
76
- SEK: ["".concat(periodFormatted, " kr"), "".concat(periodFormatted), "kr"],
77
- // singapore dollar (ex: $1,234.56)
78
- SGD: ["$".concat(commaFormatted), "".concat(commaFormatted), "$"],
79
- // thai baht (ex: 1,234.56 ฿)
80
- THB: ["".concat(commaFormatted, " \u0E3F"), "".concat(commaFormatted), "฿"],
81
- // turkish lira (ex: 1,234.56 ₺)
82
- TRY: ["".concat(commaFormatted, " \u20BA"), "".concat(commaFormatted), "₺"],
83
- // new taiwan dollar (ex: 元 1,234.56)
84
- TWD: ["\u5143 ".concat(commaFormatted), "".concat(commaFormatted), "元"],
85
- // us dollar (ex: $1,234.56)
86
- USD: ["$".concat(commaFormatted), "".concat(commaFormatted), "$"],
87
- // vietnamese dong (ex: 1.234,56 ₫)
88
- VND: ["".concat(periodFormatted, " \u20AB"), "".concat(periodFormatted), "₫"],
89
- // south african rand (ex: R 1,234.56)
90
- ZAR: ["R ".concat(commaFormatted), "".concat(commaFormatted), "R"],
91
- // default
92
- DEFAULT: [amount.toString(), amount.toString(), ""],
93
- };
94
- // TODO: fix typescript error!
95
- // @ts-ignore
96
- return switchOptions[code] || switchOptions.DEFAULT;
97
- };
98
- exports.formatCurrency = formatCurrency;
99
- var getSupportedCurrencies = function () {
100
- var currencyCodes = [
101
- // { code: "AED", name: "United Arab Emirates Dirham"},
102
- // { code: "AFN", name: "Afghanistan Afghani"},
103
- // { code: "ALL", name: "Albania Lek"},
104
- // { code: "AMD", name: "Armenia Dram"},
105
- // { code: "ANG", name: "Netherlands Antilles Guilder"},
106
- // { code: "AOA", name: "Angola Kwanza"},
107
- { code: "ARS", name: "Argentina Peso" },
108
- { code: "AUD", name: "Australia Dollar" },
109
- // { code: "AWG", name: "Aruba Guilder"},
110
- // { code: "AZN", name: "Azerbaijan Manat"},
111
- // { code: "BAM", name: "Bosnia and Herzegovina Convertible Mark"},
112
- // { code: "BBD", name: "Barbados Dollar"},
113
- // { code: "BDT", name: "Bangladesh Taka"},
114
- { code: "BGN", name: "Bulgaria Lev" },
115
- // { code: "BHD", name: "Bahrain Dinar" },
116
- // { code: "BIF", name: "Burundi Franc" },
117
- // { code: "BMD", name: "Bermuda Dollar" },
118
- // { code: "BND", name: "Brunei Darussalam Dollar" },
119
- // { code: "BOB", name: "Bolivia Bolíviano" },
120
- { code: "BRL", name: "Brazil Real" },
121
- // { code: "BSD", name: "Bahamas Dollar" },
122
- // { code: "BTN", name: "Bhutan Ngultrum" },
123
- // { code: "BWP", name: "Botswana Pula" },
124
- // { code: "BYN", name: "Belarus Ruble" },
125
- // { code: "BZD", name: "Belize Dollar" },
126
- { code: "CAD", name: "Canada Dollar" },
127
- // { code: "CDF", name: "Congo/Kinshasa Franc" },
128
- { code: "CHF", name: "Switzerland Franc" },
129
- { code: "CLP", name: "Chile Peso" },
130
- { code: "CNY", name: "China Yuan Renminbi" },
131
- { code: "COP", name: "Colombia Peso" },
132
- // { code: "CRC", name: "Costa Rica Colon" },
133
- // { code: "CUC", name: "Cuba Convertible Peso" },
134
- // { code: "CUP", name: "Cuba Peso" },
135
- // { code: "CVE", name: "Cape Verde Escudo" },
136
- { code: "CZK", name: "Czech Republic Koruna" },
137
- // { code: "DJF", name: "Djibouti Franc" },
138
- { code: "DKK", name: "Denmark Krone" },
139
- // { code: "DOP", name: "Dominican Republic Peso" },
140
- // { code: "DZD", name: "Algeria Dinar" },
141
- // { code: "EGP", name: "Egypt Pound" },
142
- // { code: "ERN", name: "Eritrea Nakfa" },
143
- // { code: "ETB", name: "Ethiopia Birr" },
144
- { code: "EUR", name: "Euro Member Countries" },
145
- // { code: "FJD", name: "Fiji Dollar" },
146
- // { code: "FKP", name: "Falkland Islands (Malvinas) Pound" },
147
- { code: "GBP", name: "United Kingdom Pound" },
148
- // { code: "GEL", name: "Georgia Lari" },
149
- // { code: "GGP", name: "Guernsey Pound" },
150
- // { code: "GHS", name: "Ghana Cedi" },
151
- // { code: "GIP", name: "Gibraltar Pound" },
152
- // { code: "GMD", name: "Gambia Dalasi" },
153
- // { code: "GNF", name: "Guinea Franc" },
154
- // { code: "GTQ", name: "Guatemala Quetzal" },
155
- // { code: "GTQ", name: "Guyana Dollar" },
156
- { code: "HKD", name: "Hong Kong Dollar" },
157
- // { code: "HNL", name: "Honduras Lempira" },
158
- { code: "HRK", name: "Croatia Kuna" },
159
- // { code: "HTG", name: "Haiti Gourde" },
160
- { code: "HUF", name: "Hungary Forint" },
161
- { code: "IDR", name: "Indonesia Rupiah" },
162
- { code: "ILS", name: "Israel Shekel" },
163
- // { code: "IMP", name: "Isle of Man Pound" },
164
- { code: "INR", name: "India Rupee" },
165
- // { code: "IQD", name: "Iraq Dinar" },
166
- // { code: "IRR", name: "Iran Rial" },
167
- { code: "ISK", name: "Iceland Krona" },
168
- // { code: "JEP", name: "Jersey Pound" },
169
- // { code: "JMD", name: "Jamaica Dollar" },
170
- // { code: "JOD", name: "Jordan Dinar" },
171
- { code: "JPY", name: "Japan Yen" },
172
- // { code: "KES", name: "Kenya Shilling" },
173
- // { code: "KGS", name: "Kyrgyzstan Som" },
174
- // { code: "KHR", name: "Cambodia Riel" },
175
- // { code: "KMF", name: "Comorian Franc" },
176
- // { code: "KPW", name: "Korea (North) Won" },
177
- { code: "KRW", name: "Korea (South) Won" },
178
- // { code: "KWD", name: "Kuwait Dinar" },
179
- // { code: "KYD", name: "Cayman Islands Dollar" },
180
- // { code: "KZT", name: "Kazakhstan Tenge" },
181
- // { code: "LAK", name: "Laos Kip" },
182
- // { code: "LPB", name: "Lebanon Pound" },
183
- // { code: "LKR", name: "Sri Lanka Rupee" },
184
- // { code: "LRD", name: "Liberia Dollar" },
185
- // { code: "LSL", name: "Lesotho Loti" },
186
- // { code: "LYD", name: "Libya Dinar" },
187
- { code: "MAD", name: "Morocco Dirham" },
188
- // { code: "MDL", name: "Moldova Leu" },
189
- // { code: "MGA", name: "Madagascar Ariary" },
190
- // { code: "MKD", name: "Macedonia Denar" },
191
- // { code: "MMK", name: "Myanmar (Burma) Kyat" },
192
- // { code: "MNT", name: "Mongolia Tughrik" },
193
- // { code: "MOP", name: "Macau Pataca" },
194
- // { code: "MRU", name: "Mauritania Ouguiya" },
195
- // { code: "MUR", name: "Mauritius Rupee" },
196
- // { code: "MVR", name: "Maldives (Maldive Islands) Rufiyaa" },
197
- // { code: "MWK", name: "Malawi Kwacha" },
198
- { code: "MXN", name: "Mexico Peso" },
199
- { code: "MYR", name: "Malaysia Ringgit" },
200
- // { code: "MZN", name: "Mozambique Metical" },
201
- // { code: "NAD", name: "Namibia Dollar" },
202
- // { code: "NGN", name: "Nigeria Naira" },
203
- // { code: "NIO", name: "Nicaragua Cordoba" },
204
- { code: "NOK", name: "Norway Krone" },
205
- // { code: "NPR", name: "Nepal Rupee" },
206
- { code: "NZD", name: "New Zealand Dollar" },
207
- // { code: "OMR", name: "Oman Rial" },
208
- // { code: "PAB", name: "Panama Balboa" },
209
- // { code: "PEN", name: "Peru Sol" },
210
- // { code: "PGK", name: "Papua New Guinea Kina" },
211
- { code: "PHP", name: "Philippines Peso" },
212
- // { code: "PKR", name: "Pakistan Rupee" },
213
- { code: "PLN", name: "Poland Zloty" },
214
- // { code: "PYG", name: "Paraguay Guarani" },
215
- // { code: "QAR", name: "Qatar Riyal" },
216
- { code: "RON", name: "Romania Leu" },
217
- // { code: "RSD", name: "Serbia Dinar" },
218
- { code: "RUB", name: "Russia Ruble" },
219
- // { code: "RWF", name: "Rwanda Franc" },
220
- { code: "SAR", name: "Saudi Arabia Riyal" },
221
- // { code: "SBD", name: "Solomon Islands Dollar" },
222
- // { code: "SCR", name: "Seychelles Rupee" },
223
- // { code: "SDG", name: "Sudan Pound" },
224
- { code: "SEK", name: "Sweden Krona" },
225
- { code: "SGD", name: "Singapore Dollar" },
226
- // { code: "SHP", name: "Saint Helena Pound" },
227
- // { code: "SLL", name: "Sierra Leone Leone" },
228
- // { code: "SOS", name: "Somalia Shilling" },
229
- // { code: "SPL", name: "Seborga Luigino" },
230
- // { code: "SRD", name: "Suriname Dollar" },
231
- // { code: "STN", name: "São Tomé and Príncipe Dobra" },
232
- // { code: "SVC", name: "El Salvador Colon" },
233
- // { code: "SYP", name: "Syria Pound" },
234
- // { code: "SZL", name: "eSwatini Lilangeni" },
235
- { code: "THB", name: "Thailand Baht" },
236
- // { code: "TJS", name: "Tajikistan Somoni" },
237
- // { code: "TMT", name: "Turkmenistan Manat" },
238
- // { code: "TND", name: "Tunisia Dinar" },
239
- // { code: "TOP", name: "Tonga Pa'anga" },
240
- { code: "TRY", name: "Turkey Lira" },
241
- // { code: "TTD", name: "Trinidad and Tobago Dollar" },
242
- // { code: "TVD", name: "Tuvalu Dollar" },
243
- { code: "TWD", name: "Taiwan New Dollar" },
244
- // { code: "TZS", name: "Tanzania Shilling" },
245
- // { code: "UAH", name: "Ukraine Hryvnia" },
246
- // { code: "UGX", name: "Uganda Shilling" },
247
- { code: "USD", name: "United States Dollar" },
248
- // { code: "UYU", name: "Uruguay Peso" },
249
- // { code: "UZS", name: "Uzbekistan Som" },
250
- // { code: "VEF", name: "Venezuela Bolívar" },
251
- { code: "VND", name: "Viet Nam Dong" },
252
- // { code: "VUV", name: "Vanuatu Vatu" },
253
- // { code: "WST", name: "Samoa Tala" },
254
- // { code: "XAF", name: "Communauté Financière Africaine (BEAC) CFA Franc BEAC" },
255
- // { code: "XCD", name: "East Caribbean Dollar" },
256
- // { code: "XDR", name: "International Monetary Fund (IMF) Special Drawing Rights" },
257
- // { code: "XOF", name: "Communauté Financière Africaine (BCEAO) Franc" },
258
- // { code: "XPF", name: "Comptoirs Français du Pacifique (CFP) Franc" },
259
- // { code: "YER", name: "Yemen Rial" },
260
- { code: "ZAR", name: "South Africa Rand" },
261
- // { code: "ZMW", name: "Zambia Kwacha" },
262
- // { code: "ZWD", name: "Zimbabwe Dollar" },
263
- ];
264
- return currencyCodes;
265
- };
266
- exports.getSupportedCurrencies = getSupportedCurrencies;
3
+ exports.getFormatCacheSize = exports.clearFormatCache = exports.getSupportedCurrencies = exports.formatCurrency = exports.CURRENCIES = void 0;
4
+ // Currency data and codes
5
+ var currencies_1 = require("./currencies");
6
+ Object.defineProperty(exports, "CURRENCIES", { enumerable: true, get: function () { return currencies_1.CURRENCIES; } });
7
+ // Formatting functions
8
+ var format_1 = require("./format");
9
+ Object.defineProperty(exports, "formatCurrency", { enumerable: true, get: function () { return format_1.formatCurrency; } });
10
+ Object.defineProperty(exports, "getSupportedCurrencies", { enumerable: true, get: function () { return format_1.getSupportedCurrencies; } });
11
+ Object.defineProperty(exports, "clearFormatCache", { enumerable: true, get: function () { return format_1.clearFormatCache; } });
12
+ Object.defineProperty(exports, "getFormatCacheSize", { enumerable: true, get: function () { return format_1.getFormatCacheSize; } });
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Configuration for a currency's formatting rules.
3
+ *
4
+ * @property name - Full name of the currency (e.g., "United States Dollar")
5
+ * @property symbol - Currency symbol or code (e.g., "$", "€", "USD")
6
+ * @property format - Thousands/decimal separator style: "comma" (1,234.56) or "period" (1.234,56)
7
+ * @property position - Symbol placement: "before" ($100) or "after" (100€)
8
+ * @property space - Whether to include a space between symbol and amount
9
+ * @property decimals - Number of decimal places (defaults to 2 if not specified)
10
+ */
11
+ export type CurrencyConfig = {
12
+ name: string;
13
+ symbol: string;
14
+ format: "comma" | "period";
15
+ position: "before" | "after";
16
+ space: boolean;
17
+ decimals?: number;
18
+ };
19
+ /**
20
+ * Return type for formatCurrency function (array format).
21
+ *
22
+ * A tuple containing three strings:
23
+ * - [0] Formatted amount with currency symbol (e.g., "$1,234.56")
24
+ * - [1] Formatted amount without symbol (e.g., "1,234.56")
25
+ * - [2] Currency symbol only (e.g., "$")
26
+ *
27
+ * @example
28
+ * const [withSymbol, withoutSymbol, symbol] = formatCurrency({ amount: 1234.56, code: 'USD' });
29
+ * // withSymbol: "$1,234.56"
30
+ * // withoutSymbol: "1,234.56"
31
+ * // symbol: "$"
32
+ */
33
+ export type FormatResult = [string, string, string];
34
+ /**
35
+ * Return type for formatCurrency function (object format).
36
+ *
37
+ * An object containing the formatted currency values:
38
+ * - formatted: Formatted amount with currency symbol (e.g., "$1,234.56")
39
+ * - value: Formatted amount without symbol (e.g., "1,234.56")
40
+ * - symbol: Currency symbol only (e.g., "$")
41
+ *
42
+ * @example
43
+ * const result = formatCurrency({ amount: 1234.56, code: 'USD', returnType: 'object' });
44
+ * // result.formatted: "$1,234.56"
45
+ * // result.value: "1,234.56"
46
+ * // result.symbol: "$"
47
+ */
48
+ export type FormatResultObject = {
49
+ formatted: string;
50
+ value: string;
51
+ symbol: string;
52
+ };
53
+ /**
54
+ * Represents a supported currency with its code and display name.
55
+ */
56
+ export type SupportedCurrency = {
57
+ /** ISO 4217 currency code (e.g., "USD", "EUR") */
58
+ code: string;
59
+ /** Full currency name (e.g., "United States Dollar") */
60
+ name: string;
61
+ };
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });