108 lines
4.0 KiB
Markdown
108 lines
4.0 KiB
Markdown
|
|
<a name="i18n"></a>
|
||
|
|
|
||
|
|
## i18n : <code>object</code>
|
||
|
|
Functions to help support multiple currencies and countries.
|
||
|
|
|
||
|
|
**Kind**: global namespace
|
||
|
|
|
||
|
|
* [i18n](#i18n) : <code>object</code>
|
||
|
|
* [.country()](#i18n.country) ⇒ <code>string</code>
|
||
|
|
* [.currency()](#i18n.currency) ⇒ <code>string</code>
|
||
|
|
* [.symbol()](#i18n.symbol) ⇒ <code>string</code>
|
||
|
|
* [.decimals()](#i18n.decimals) ⇒ <code>number</code>
|
||
|
|
* [.convertCurrency(amount, fromCurrency, [toCurrency])](#i18n.convertCurrency) ⇒ <code>Promise.<number></code>
|
||
|
|
* [.moneyToFixed(amount)](#i18n.moneyToFixed) ⇒ <code>string</code>
|
||
|
|
* [.moneyString(amount)](#i18n.moneyString) ⇒ <code>string</code>
|
||
|
|
* [.currencyMinorToMajor(amount)](#i18n.currencyMinorToMajor) ⇒ <code>number</code>
|
||
|
|
* [.currencyMajorToMinor(amount)](#i18n.currencyMajorToMinor) ⇒ <code>number</code>
|
||
|
|
|
||
|
|
<a name="i18n.country"></a>
|
||
|
|
|
||
|
|
### i18n.country() ⇒ <code>string</code>
|
||
|
|
Get the 2-character ISO country code that PostalPoint is running in.
|
||
|
|
|
||
|
|
**Kind**: static method of [<code>i18n</code>](#i18n)
|
||
|
|
**Returns**: <code>string</code> - "US", "CA", etc.
|
||
|
|
<a name="i18n.currency"></a>
|
||
|
|
|
||
|
|
### i18n.currency() ⇒ <code>string</code>
|
||
|
|
Get the 3-character currency code in use.
|
||
|
|
|
||
|
|
**Kind**: static method of [<code>i18n</code>](#i18n)
|
||
|
|
**Returns**: <code>string</code> - "usd", "cad", etc.
|
||
|
|
<a name="i18n.symbol"></a>
|
||
|
|
|
||
|
|
### i18n.symbol() ⇒ <code>string</code>
|
||
|
|
Get the currency symbol.
|
||
|
|
|
||
|
|
**Kind**: static method of [<code>i18n</code>](#i18n)
|
||
|
|
**Returns**: <code>string</code> - "$", "€", "₤", etc
|
||
|
|
<a name="i18n.decimals"></a>
|
||
|
|
|
||
|
|
### i18n.decimals() ⇒ <code>number</code>
|
||
|
|
Get the number of decimal places for the currency: for example, USD has 2 ($x.00), KRW has 0 (x), UYW has 4 (x.0000).
|
||
|
|
|
||
|
|
**Kind**: static method of [<code>i18n</code>](#i18n)
|
||
|
|
**Returns**: <code>number</code> - 0, 2, 3, or 4
|
||
|
|
<a name="i18n.convertCurrency"></a>
|
||
|
|
|
||
|
|
### i18n.convertCurrency(amount, fromCurrency, [toCurrency]) ⇒ <code>Promise.<number></code>
|
||
|
|
Convert an amount of money to a different currency. Conversion rate is retrieved from the internet and cached for 4 hours.
|
||
|
|
|
||
|
|
**Kind**: static method of [<code>i18n</code>](#i18n)
|
||
|
|
|
||
|
|
| Param | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| amount | <code>number</code> | | Amount of money in the "wrong" currency |
|
||
|
|
| fromCurrency | <code>string</code> | | The currency code for the "wrong" currency that needs conversion |
|
||
|
|
| [toCurrency] | <code>string</code> | <code>"getCurrencyCode()"</code> | The "correct" currency we want the amount to be in. |
|
||
|
|
|
||
|
|
<a name="i18n.moneyToFixed"></a>
|
||
|
|
|
||
|
|
### i18n.moneyToFixed(amount) ⇒ <code>string</code>
|
||
|
|
Returns the amount as a string formatted with the correct number of decimal places for the currency in use.
|
||
|
|
|
||
|
|
**Kind**: static method of [<code>i18n</code>](#i18n)
|
||
|
|
**Returns**: <code>string</code> - "1.23", "1.2345", etc
|
||
|
|
|
||
|
|
| Param | Type |
|
||
|
|
| --- | --- |
|
||
|
|
| amount | <code>number</code> |
|
||
|
|
|
||
|
|
<a name="i18n.moneyString"></a>
|
||
|
|
|
||
|
|
### i18n.moneyString(amount) ⇒ <code>string</code>
|
||
|
|
Returns the amount as a string, with the correct decimal places, and the local currency symbol.
|
||
|
|
|
||
|
|
**Kind**: static method of [<code>i18n</code>](#i18n)
|
||
|
|
**Returns**: <code>string</code> - "$1.23", etc
|
||
|
|
|
||
|
|
| Param | Type |
|
||
|
|
| --- | --- |
|
||
|
|
| amount | <code>number</code> |
|
||
|
|
|
||
|
|
<a name="i18n.currencyMinorToMajor"></a>
|
||
|
|
|
||
|
|
### i18n.currencyMinorToMajor(amount) ⇒ <code>number</code>
|
||
|
|
Convert an amount in cents to dollars (or the local equivalent currency units).
|
||
|
|
|
||
|
|
**Kind**: static method of [<code>i18n</code>](#i18n)
|
||
|
|
**Returns**: <code>number</code> - Dollars, etc
|
||
|
|
|
||
|
|
| Param | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| amount | <code>number</code> | Cents, etc |
|
||
|
|
|
||
|
|
<a name="i18n.currencyMajorToMinor"></a>
|
||
|
|
|
||
|
|
### i18n.currencyMajorToMinor(amount) ⇒ <code>number</code>
|
||
|
|
Convert an amount in dollars to cents (or the local equivalent currency units).
|
||
|
|
|
||
|
|
**Kind**: static method of [<code>i18n</code>](#i18n)
|
||
|
|
**Returns**: <code>number</code> - Cents, etc
|
||
|
|
|
||
|
|
| Param | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| amount | <code>number</code> | Dollars, etc |
|
||
|
|
|