-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new feature, options: currencySign, currencyDisplay
- Loading branch information
1 parent
22e85bd
commit c86b2ff
Showing
14 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
import { findIso4217Currency } from "./findIso4217Currency"; | ||
import { getSeparator } from "./internal/getSeparator"; | ||
import { CurrencySymbolOptions } from "./types/currencySymbolOptions"; | ||
import { IntlCurrencyDisplay } from "./types/intlCurrencyDisplay"; | ||
import { Iso4217Alpha3Code, Iso4217NumericCode } from "./types/iso4217"; | ||
import { Locale } from "./types/locale"; | ||
|
||
export function getCurrencySymbol(currencyCode: Iso4217Alpha3Code | Iso4217NumericCode, locale?: Locale): string { | ||
const code = typeof currencyCode === "string" | ||
? currencyCode | ||
: findIso4217Currency(currencyCode)?.alpha3Code; | ||
export function getCurrencySymbol(currencyCode: Iso4217Alpha3Code | Iso4217NumericCode, locale?: Locale): string | ||
export function getCurrencySymbol(currencyCode: CurrencySymbolOptions, locale?: Locale): string | ||
export function getCurrencySymbol(options: Iso4217Alpha3Code | Iso4217NumericCode | CurrencySymbolOptions, locale?: Locale): string { | ||
if (typeof options === "string") { | ||
return getCurrencySymbolString(options, undefined, locale); | ||
} | ||
|
||
if (typeof options === "number") { | ||
return getCurrencySymbolString(findIso4217Currency(options)?.alpha3Code, undefined, locale); | ||
} | ||
|
||
if (!code) { | ||
const code = typeof options.currency === "string" | ||
? options.currency | ||
: findIso4217Currency(options.currency)?.alpha3Code | ||
|
||
return getCurrencySymbolString(code, options.currencyDisplay, locale); | ||
} | ||
|
||
function getCurrencySymbolString(currency?: Iso4217Alpha3Code, currencyDisplay?: IntlCurrencyDisplay, locale?: Locale): string { | ||
if (!currency) { | ||
return ""; | ||
} | ||
|
||
return getSeparator(1, "currency", { style: "currency", currency: code, currencyDisplay: "symbol" }, locale); | ||
const intlOptions = { style: "currency", currency: currency, currencyDisplay: currencyDisplay ?? "symbol" }; | ||
|
||
return getSeparator(1, "currency", intlOptions, locale); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IntlCurrencyDisplay } from "./intlCurrencyDisplay"; | ||
import { Iso4217Alpha3Code, Iso4217NumericCode } from "./iso4217"; | ||
|
||
export interface CurrencySymbolOptions { | ||
currency: Iso4217Alpha3Code | Iso4217NumericCode; | ||
currencyDisplay?: IntlCurrencyDisplay; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type IntlCurrencySign = "standard" | "accounting"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { IntlCurrencyDisplay } from "./intlCurrencyDisplay"; | ||
import { Iso4217Alpha3Code } from "./iso4217"; | ||
import { IntlCurrencySign } from "./intlCurrencySign"; | ||
import { Iso4217Alpha3Code, Iso4217NumericCode } from "./iso4217"; | ||
|
||
export interface NumberFormatBase { | ||
thousandsSeparator: boolean; | ||
useBankersRounding: boolean; | ||
negativeZero: boolean; | ||
currency: Iso4217Alpha3Code; | ||
currency: Iso4217Alpha3Code | Iso4217NumericCode; | ||
currencyDisplay: IntlCurrencyDisplay; | ||
currencySign: IntlCurrencySign; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { IntlCurrencyDisplay } from "./intlCurrencyDisplay"; | ||
import { Iso4217Alpha3Code } from "./iso4217"; | ||
import { IntlCurrencySign } from "./intlCurrencySign"; | ||
import { Iso4217Alpha3Code, Iso4217NumericCode } from "./iso4217"; | ||
|
||
export interface NumberFormatMoney { | ||
precision: number; | ||
currency: Iso4217Alpha3Code; | ||
currency: Iso4217Alpha3Code | Iso4217NumericCode; | ||
currencyDisplay: IntlCurrencyDisplay; | ||
currencySign: IntlCurrencySign; | ||
} |