Skip to content

Commit

Permalink
v3.4.0: allow to pass options toString that will be forwarded to Intl…
Browse files Browse the repository at this point in the history
….NumberFormat
  • Loading branch information
10xSebastian committed Jun 27, 2022
1 parent d5eae16 commit 31f2eb1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ currency.toString()
// €22.32
```

`options`: accepts options object that will be forwarded to `Intl.NumberFormat`

```javascript
new LocalCurrency.Currency({ amount: 20 }).toString({ maximumFractionDigits: 0 })
// $20
```

### fromUSD

Converts USD into local currency:
Expand Down
4 changes: 2 additions & 2 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ class Currency {
return Intl.DateTimeFormat().resolvedOptions().timeZone
}

toString() {
return new Intl.NumberFormat(navigator.language, {
toString(options = {}) {
return new Intl.NumberFormat(navigator.language, {...options,
style: 'currency',
currency: this.code,
}).format(this.amount)
Expand Down
4 changes: 2 additions & 2 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@
return Intl.DateTimeFormat().resolvedOptions().timeZone
}

toString() {
return new Intl.NumberFormat(navigator.language, {
toString(options = {}) {
return new Intl.NumberFormat(navigator.language, {...options,
style: 'currency',
currency: this.code,
}).format(this.amount)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/local-currency",
"moduleName": "LocalCurrency",
"version": "3.3.0",
"version": "3.4.0",
"description": "JavaScript library that detects user's local currency and provides functionalities to convert between multiple currencies.",
"main": "dist/umd/index.js",
"module": "dist/esm/index.js",
Expand Down
4 changes: 2 additions & 2 deletions src/Currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Currency {
return Intl.DateTimeFormat().resolvedOptions().timeZone
}

toString() {
return new Intl.NumberFormat(navigator.language, {
toString(options = {}) {
return new Intl.NumberFormat(navigator.language, {...options,
style: 'currency',
currency: this.code,
}).format(this.amount)
Expand Down

0 comments on commit 31f2eb1

Please sign in to comment.