Skip to content

Commit

Permalink
Fix currency for JPY
Browse files Browse the repository at this point in the history
  • Loading branch information
KirianCaumes committed Mar 2, 2022
1 parent 65729ad commit 1882b2e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/enum/ECurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ enum ECurrency {
JPY = 'JPY',
SEK = 'SEK',
BRL = 'BRL',
NZD = 'NZD',
MXN = 'MXN',
NZD = 'NZD',
DKK = 'DKK',
ZAR = 'ZAR',
}

Expand Down
3 changes: 3 additions & 0 deletions src/enum/iso/translate/EDiscogsCurrencyToIsoCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ enum EDiscogsCurrencyToIsoCode {
JPY = 'JPY',
CHF = 'CHF',
MX$ = 'MXN',
$MX = 'MXN',
MXN = 'MXN',
$NZ = 'NZD',
NZ$ = 'NZD',
NZD = 'NZD',
SEK = 'SEK',
ZAR = 'ZAR',
BRL = 'BRL',
DKK = 'DKK',
A$ = 'AUD',
R$ = 'BRL',
EUR = 'EUR',
Expand Down
6 changes: 4 additions & 2 deletions src/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,14 @@ export default class Marketplace {
if (!currency)
return value

const currencyClean = (EDiscogsCurrencyToIsoCode as any)[currency]

const amount = value
.replace(/[.](?=.*[.])/g, '') // Remove all dot but last
.replace(currencyClean !== ECurrency.JPY ? /[.](?=.*[.])/g : /\./g, '') // Remove all dot but last, except if JPY
.replace(currency, '') // Remove original currency
.replace(/\s/g, '') // Remove spaces

return `${amount} ${(EDiscogsCurrencyToIsoCode as any)[currency]}`
return `${amount} ${currencyClean}`
.replace(/\s\s+/g, ' ') // Remove useless spaces
}

Expand Down

0 comments on commit 1882b2e

Please sign in to comment.