Skip to content

Commit

Permalink
prettier fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RgnDunes committed Nov 7, 2023
1 parent 80bfbdc commit 68f658a
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 236 deletions.
4 changes: 2 additions & 2 deletions src/modules/currency/__tests__/getCurrencyList.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import getCurrencyList from "../getCurrencyList";
import { CURRENCIES } from "../data/currencies";
import getCurrencyList from '../getCurrencyList';
import { CURRENCIES } from '../data/currencies';
describe('getCurrencyList', () => {
it('should return the correct currency list', () => {
const currencyList = getCurrencyList();
Expand Down
26 changes: 15 additions & 11 deletions src/modules/currency/__tests__/getCurrencySymbol.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import getCurrencySymbol from "../getCurrencySymbol";
import getCurrencySymbol from '../getCurrencySymbol';

describe("getCurrencySymbol", () => {
it("should return the correct symbol for a valid currency code", () => {
const currencyCode = "USD";
const expectedSymbol = "$";
describe('getCurrencySymbol', () => {
it('should return the correct symbol for a valid currency code', () => {
const currencyCode = 'USD';
const expectedSymbol = '$';
const symbol = getCurrencySymbol(currencyCode);
expect(symbol).toBe(expectedSymbol);
});

it("should throw Error for an invalid currency code", () => {
const currencyCode = "XYZ"; // An invalid code
expect(() => getCurrencySymbol(currencyCode)).toThrow("Invalid currencyCode!");
it('should throw Error for an invalid currency code', () => {
const currencyCode = 'XYZ'; // An invalid code
expect(() => getCurrencySymbol(currencyCode)).toThrow(
'Invalid currencyCode!',
);
});

it("should throw Error for an empty string", () => {
const currencyCode = "";
expect(() => getCurrencySymbol(currencyCode)).toThrow("Invalid currencyCode!");
it('should throw Error for an empty string', () => {
const currencyCode = '';
expect(() => getCurrencySymbol(currencyCode)).toThrow(
'Invalid currencyCode!',
);
});
});
192 changes: 96 additions & 96 deletions src/modules/currency/data/currencies.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
export const CURRENCIES: { [key: string]: {symbol:string, name: string} } = {
AED: { symbol: "د.إ", name: "United Arab Emirates Dirham" },
ALL: { symbol: "Lek", name: "Albanian Lek" },
AMD: { symbol: "֏", name: "Armenian Dram" },
ARS: { symbol: "ARS", name: "Argentine Peso" },
AUD: { symbol: "A$", name: "Australian Dollar" },
AWG: { symbol: "Afl.", name: "Aruban Florin" },
BBD: { symbol: "$", name: "Barbadian Dollar" },
BDT: { symbol: "৳", name: "Bangladeshi Taka" },
BMD: { symbol: "$", name: "Bermudian Dollar" },
BND: { symbol: "BND", name: "Brunei Dollar" },
BOB: { symbol: "Bs", name: "Bolivian Boliviano" },
BSD: { symbol: "B$", name: "Bahamian Dollar" },
BWP: { symbol: "P", name: "Botswanan Pula" },
BZD: { symbol: "BZ$", name: "Belize Dollar" },
CAD: { symbol: "C$", name: "Canadian Dollar" },
CHF: { symbol: "CHf", name: "Swiss Franc" },
CNY: { symbol: "¥", name: "Chinese Yuan" },
COP: { symbol: "COL$", name: "Colombian Peso" },
CRC: { symbol: "₡", name: "Costa Rican Colón" },
CUP: { symbol: "$MN", name: "Cuban Peso" },
CZK: { symbol: "Kč", name: "Czech Koruna" },
DKK: { symbol: "DKK", name: "Danish Krone" },
DOP: { symbol: "RD$", name: "Dominican Peso" },
DZD: { symbol: "د.ج", name: "Algerian Dinar" },
EGP: { symbol: "E£", name: "Egyptian Pound" },
ETB: { symbol: "ብር", name: "Ethiopian Birr" },
EUR: { symbol: "€", name: "Euro" },
FJD: { symbol: "FJ$", name: "Fijian Dollar" },
GBP: { symbol: "£", name: "British Pound" },
GHS: { symbol: "GH₵", name: "Ghanaian Cedi" },
GIP: { symbol: "GIP", name: "Gibraltar Pound" },
GMD: { symbol: "D", name: "Gambian Dalasi" },
GTQ: { symbol: "Q", name: "Guatemalan Quetzal" },
GYD: { symbol: "G$", name: "Guyanese Dollar" },
HKD: { symbol: "HK$", name: "Hong Kong Dollar" },
HNL: { symbol: "HNL", name: "Honduran Lempira" },
HRK: { symbol: "kn", name: "Croatian Kuna" },
HTG: { symbol: "G", name: "Haitian Gourde" },
HUF: { symbol: "Ft", name: "Hungarian Forint" },
IDR: { symbol: "Rp", name: "Indonesian Rupiah" },
ILS: { symbol: "₪", name: "Israeli New Shekel" },
INR: { symbol: "₹", name: "Indian Rupee" },
JMD: { symbol: "J$", name: "Jamaican Dollar" },
KES: { symbol: "Ksh", name: "Kenyan Shilling" },
KGS: { symbol: "Лв", name: "Kyrgystani Som" },
KHR: { symbol: "៛", name: "Cambodian Riel" },
KYD: { symbol: "CI$", name: "Cayman Islands Dollar" },
KZT: { symbol: "₸", name: "Kazakhstani Tenge" },
LAK: { symbol: "₭", name: "Laotian Kip" },
LKR: { symbol: "රු", name: "Sri Lankan Rupee" },
LRD: { symbol: "L$", name: "Liberian Dollar" },
LSL: { symbol: "LSL", name: "Lesotho Loti" },
MAD: { symbol: "د.م.", name: "Moroccan Dirham" },
MDL: { symbol: "MDL", name: "Moldovan Leu" },
MKD: { symbol: "ден", name: "Macedonian Denar" },
MMK: { symbol: "MMK", name: "Myanmar Kyat" },
MNT: { symbol: "₮", name: "Mongolian Tugrik" },
MOP: { symbol: "MOP$", name: "Macanese Pataca" },
MUR: { symbol: "₨", name: "Mauritian Rupee" },
MVR: { symbol: "Rf", name: "Maldivian Rufiyaa" },
MWK: { symbol: "MK", name: "Malawian Kwacha" },
MXN: { symbol: "Mex$", name: "Mexican Peso" },
MYR: { symbol: "RM", name: "Malaysian Ringgit" },
NAD: { symbol: "N$", name: "Namibian Dollar" },
NGN: { symbol: "₦", name: "Nigerian Naira" },
NIO: { symbol: "NIO", name: "Nicaraguan Córdoba" },
NOK: { symbol: "NOK", name: "Norwegian Krone" },
NPR: { symbol: "रू", name: "Nepalese Rupee" },
NZD: { symbol: "NZ$", name: "New Zealand Dollar" },
PEN: { symbol: "S/", name: "Peruvian Nuevo Sol" },
PGK: { symbol: "PGK", name: "Papua New Guinean Kina" },
PHP: { symbol: "₱", name: "Philippine Peso" },
PKR: { symbol: "₨", name: "Pakistani Rupee" },
QAR: { symbol: "QR", name: "Qatari Riyal" },
RUB: { symbol: "₽", name: "Russian Ruble" },
SAR: { symbol: "SR", name: "Saudi Riyal" },
SCR: { symbol: "SRe", name: "Seychellois Rupee" },
SEK: { symbol: "SEK", name: "Swedish Krona" },
SGD: { symbol: "S$", name: "Singapore Dollar" },
SLL: { symbol: "Le", name: "Sierra Leonean Leone" },
SOS: { symbol: "Sh.so.", name: "Somali Shilling" },
SSP: { symbol: "SS£", name: "South Sudanese Pound" },
SVC: { symbol: "₡", name: "Salvadoran Colón" },
SZL: { symbol: "E", name: "Swazi Lilangeni" },
THB: { symbol: "฿", name: "Thai Baht" },
TTD: { symbol: "TT$", name: "Trinidad and Tobago Dollar" },
TZS: { symbol: "Sh", name: "Tanzanian Shilling" },
USD: { symbol: "$", name: "United States Dollar" },
UYU: { symbol: "$U", name: "Uruguayan Peso" },
UZS: { symbol: "so'm", name: "Uzbekistani Som" },
YER: { symbol: "﷼", name: "Yemeni Rial" },
ZAR: { symbol: "R", name: "South African Rand" },
KWD: { symbol: "د.ك", name: "Kuwaiti Dinar" },
BHD: { symbol: "د.ب.", name: "Bahraini Dinar" },
OMR: { symbol: "ر.ع.", name: "Omani Rial" },
export const CURRENCIES: { [key: string]: { symbol: string; name: string } } = {
AED: { symbol: 'د.إ', name: 'United Arab Emirates Dirham' },
ALL: { symbol: 'Lek', name: 'Albanian Lek' },
AMD: { symbol: '֏', name: 'Armenian Dram' },
ARS: { symbol: 'ARS', name: 'Argentine Peso' },
AUD: { symbol: 'A$', name: 'Australian Dollar' },
AWG: { symbol: 'Afl.', name: 'Aruban Florin' },
BBD: { symbol: '$', name: 'Barbadian Dollar' },
BDT: { symbol: '৳', name: 'Bangladeshi Taka' },
BMD: { symbol: '$', name: 'Bermudian Dollar' },
BND: { symbol: 'BND', name: 'Brunei Dollar' },
BOB: { symbol: 'Bs', name: 'Bolivian Boliviano' },
BSD: { symbol: 'B$', name: 'Bahamian Dollar' },
BWP: { symbol: 'P', name: 'Botswanan Pula' },
BZD: { symbol: 'BZ$', name: 'Belize Dollar' },
CAD: { symbol: 'C$', name: 'Canadian Dollar' },
CHF: { symbol: 'CHf', name: 'Swiss Franc' },
CNY: { symbol: '¥', name: 'Chinese Yuan' },
COP: { symbol: 'COL$', name: 'Colombian Peso' },
CRC: { symbol: '₡', name: 'Costa Rican Colón' },
CUP: { symbol: '$MN', name: 'Cuban Peso' },
CZK: { symbol: 'Kč', name: 'Czech Koruna' },
DKK: { symbol: 'DKK', name: 'Danish Krone' },
DOP: { symbol: 'RD$', name: 'Dominican Peso' },
DZD: { symbol: 'د.ج', name: 'Algerian Dinar' },
EGP: { symbol: 'E£', name: 'Egyptian Pound' },
ETB: { symbol: 'ብር', name: 'Ethiopian Birr' },
EUR: { symbol: '€', name: 'Euro' },
FJD: { symbol: 'FJ$', name: 'Fijian Dollar' },
GBP: { symbol: '£', name: 'British Pound' },
GHS: { symbol: 'GH₵', name: 'Ghanaian Cedi' },
GIP: { symbol: 'GIP', name: 'Gibraltar Pound' },
GMD: { symbol: 'D', name: 'Gambian Dalasi' },
GTQ: { symbol: 'Q', name: 'Guatemalan Quetzal' },
GYD: { symbol: 'G$', name: 'Guyanese Dollar' },
HKD: { symbol: 'HK$', name: 'Hong Kong Dollar' },
HNL: { symbol: 'HNL', name: 'Honduran Lempira' },
HRK: { symbol: 'kn', name: 'Croatian Kuna' },
HTG: { symbol: 'G', name: 'Haitian Gourde' },
HUF: { symbol: 'Ft', name: 'Hungarian Forint' },
IDR: { symbol: 'Rp', name: 'Indonesian Rupiah' },
ILS: { symbol: '₪', name: 'Israeli New Shekel' },
INR: { symbol: '₹', name: 'Indian Rupee' },
JMD: { symbol: 'J$', name: 'Jamaican Dollar' },
KES: { symbol: 'Ksh', name: 'Kenyan Shilling' },
KGS: { symbol: 'Лв', name: 'Kyrgystani Som' },
KHR: { symbol: '៛', name: 'Cambodian Riel' },
KYD: { symbol: 'CI$', name: 'Cayman Islands Dollar' },
KZT: { symbol: '₸', name: 'Kazakhstani Tenge' },
LAK: { symbol: '₭', name: 'Laotian Kip' },
LKR: { symbol: 'රු', name: 'Sri Lankan Rupee' },
LRD: { symbol: 'L$', name: 'Liberian Dollar' },
LSL: { symbol: 'LSL', name: 'Lesotho Loti' },
MAD: { symbol: 'د.م.', name: 'Moroccan Dirham' },
MDL: { symbol: 'MDL', name: 'Moldovan Leu' },
MKD: { symbol: 'ден', name: 'Macedonian Denar' },
MMK: { symbol: 'MMK', name: 'Myanmar Kyat' },
MNT: { symbol: '₮', name: 'Mongolian Tugrik' },
MOP: { symbol: 'MOP$', name: 'Macanese Pataca' },
MUR: { symbol: '₨', name: 'Mauritian Rupee' },
MVR: { symbol: 'Rf', name: 'Maldivian Rufiyaa' },
MWK: { symbol: 'MK', name: 'Malawian Kwacha' },
MXN: { symbol: 'Mex$', name: 'Mexican Peso' },
MYR: { symbol: 'RM', name: 'Malaysian Ringgit' },
NAD: { symbol: 'N$', name: 'Namibian Dollar' },
NGN: { symbol: '₦', name: 'Nigerian Naira' },
NIO: { symbol: 'NIO', name: 'Nicaraguan Córdoba' },
NOK: { symbol: 'NOK', name: 'Norwegian Krone' },
NPR: { symbol: 'रू', name: 'Nepalese Rupee' },
NZD: { symbol: 'NZ$', name: 'New Zealand Dollar' },
PEN: { symbol: 'S/', name: 'Peruvian Nuevo Sol' },
PGK: { symbol: 'PGK', name: 'Papua New Guinean Kina' },
PHP: { symbol: '₱', name: 'Philippine Peso' },
PKR: { symbol: '₨', name: 'Pakistani Rupee' },
QAR: { symbol: 'QR', name: 'Qatari Riyal' },
RUB: { symbol: '₽', name: 'Russian Ruble' },
SAR: { symbol: 'SR', name: 'Saudi Riyal' },
SCR: { symbol: 'SRe', name: 'Seychellois Rupee' },
SEK: { symbol: 'SEK', name: 'Swedish Krona' },
SGD: { symbol: 'S$', name: 'Singapore Dollar' },
SLL: { symbol: 'Le', name: 'Sierra Leonean Leone' },
SOS: { symbol: 'Sh.so.', name: 'Somali Shilling' },
SSP: { symbol: 'SS£', name: 'South Sudanese Pound' },
SVC: { symbol: '₡', name: 'Salvadoran Colón' },
SZL: { symbol: 'E', name: 'Swazi Lilangeni' },
THB: { symbol: '฿', name: 'Thai Baht' },
TTD: { symbol: 'TT$', name: 'Trinidad and Tobago Dollar' },
TZS: { symbol: 'Sh', name: 'Tanzanian Shilling' },
USD: { symbol: '$', name: 'United States Dollar' },
UYU: { symbol: '$U', name: 'Uruguayan Peso' },
UZS: { symbol: "so'm", name: 'Uzbekistani Som' },
YER: { symbol: '﷼', name: 'Yemeni Rial' },
ZAR: { symbol: 'R', name: 'South African Rand' },
KWD: { symbol: 'د.ك', name: 'Kuwaiti Dinar' },
BHD: { symbol: 'د.ب.', name: 'Bahraini Dinar' },
OMR: { symbol: 'ر.ع.', name: 'Omani Rial' },
};
28 changes: 14 additions & 14 deletions src/modules/currency/formatAmountByParts.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { CURRENCIES } from "./data/currencies";
import { ByParts } from "./types";
import { withErrorBoundary } from "../../common/errorBoundary";
import { CURRENCIES } from './data/currencies';
import { ByParts } from './types';
import { withErrorBoundary } from '../../common/errorBoundary';

const formatAmountByParts = (
currencyCode: keyof typeof CURRENCIES,
amount: string | number,
locale?: string
locale?: string,
): ByParts => {
if (!Number(amount)) throw new Error("Parameter `amount` is not a number!");
if (!Number(amount)) throw new Error('Parameter `amount` is not a number!');

// If a specific locale is provided, use it; otherwise, use the browser's locale
if (!locale) {
Expand All @@ -16,21 +16,21 @@ const formatAmountByParts = (

try {
const formattedAmount = new Intl.NumberFormat(locale || undefined, {
style: "currency",
style: 'currency',
currency: currencyCode as string,
}).formatToParts(Number(amount));

const parts = formattedAmount;
let integerValue = "";
let decimalValue = "";
let currencySymbol = "";
let separator = "";
let integerValue = '';
let decimalValue = '';
let currencySymbol = '';
let separator = '';
let symbolAtFirst = true;
const partValues = parts.map((p: any) => {

Check failure on line 29 in src/modules/currency/formatAmountByParts.ts

View workflow job for this annotation

GitHub Actions / Validate Source code

Unexpected any. Specify a different type
if (p.type === "integer" || p.type === "group") integerValue += p.value;
else if (p.type === "fraction") decimalValue += p.value;
else if (p.type === "currency") currencySymbol += p.value;
else if (p.type === "decimal") separator += p.value;
if (p.type === 'integer' || p.type === 'group') integerValue += p.value;
else if (p.type === 'fraction') decimalValue += p.value;
else if (p.type === 'currency') currencySymbol += p.value;
else if (p.type === 'decimal') separator += p.value;
return p.value;
});

Expand Down
6 changes: 3 additions & 3 deletions src/modules/currency/getCurrencyList.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CURRENCIES } from "./data/currencies";
import { GetCurrencyListOutput } from "./types";
import { withErrorBoundary } from "../../common/errorBoundary";
import { CURRENCIES } from './data/currencies';
import { GetCurrencyListOutput } from './types';
import { withErrorBoundary } from '../../common/errorBoundary';

const getCurrencyList = (): GetCurrencyListOutput => {
return CURRENCIES;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/currency/getCurrencySymbol.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CURRENCIES } from "./data/currencies";
import { withErrorBoundary } from "../../common/errorBoundary";
import { CURRENCIES } from './data/currencies';
import { withErrorBoundary } from '../../common/errorBoundary';

const getCurrencySymbol = (currencyCode: keyof typeof CURRENCIES): string => {
if (currencyCode in CURRENCIES) return CURRENCIES[currencyCode]?.symbol;
else throw new Error("Invalid currencyCode!");
else throw new Error('Invalid currencyCode!');
};

export default withErrorBoundary(getCurrencySymbol);
8 changes: 4 additions & 4 deletions src/modules/currency/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as formatNumber } from "./formatNumber";
export { default as getCurrencyList } from "./getCurrencyList";
export { default as getCurrencySymbol } from "./getCurrencySymbol";
export { default as formatAmountByParts } from "./formatAmountByParts";
export { default as formatNumber } from './formatNumber';
export { default as getCurrencyList } from './getCurrencyList';
export { default as getCurrencySymbol } from './getCurrencySymbol';
export { default as formatAmountByParts } from './formatAmountByParts';
2 changes: 1 addition & 1 deletion src/modules/currency/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CURRENCIES } from "./data/currencies";
import { CURRENCIES } from './data/currencies';

export interface Currency {
symbol: string;
Expand Down
Loading

0 comments on commit 68f658a

Please sign in to comment.