File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,11 @@ export function territoryCurrencyCode(territory) {
7676 if ( ! currencyData ) {
7777 throw new Error ( "Cannot determine currency. Please load the supplemental currencyData." ) ;
7878 }
79+
7980 const regionCurrencies = currencyData . region [ territory ] ;
81+ if ( ! regionCurrencies ) {
82+ throw new Error ( "No currency data for region " + territory ) ;
83+ }
8084 const currencyCode = Object . keys ( regionCurrencies [ regionCurrencies . length - 1 ] ) [ 0 ] ;
8185
8286 return currencyCode ;
@@ -89,4 +93,4 @@ export function localeCurrency(locale) {
8993 numbers . localeCurrency = territoryCurrencyCode ( localeTerritory ( info ) ) ;
9094 }
9195 return numbers . localeCurrency ;
92- }
96+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ const likelySubtags = require("cldr-data/supplemental/likelySubtags.json");
55const numbers = require ( "cldr-data/main/bg/numbers.json" ) ;
66const currencies = require ( "cldr-data/main/bg/currencies.json" ) ;
77const currencyData = require ( "cldr-data/supplemental/currencyData.json" ) ;
8+
9+ // CUSTOM region is used in tests below
10+ currencyData . supplemental . currencyData . region . CUSTOM = [ { } ] ;
11+
812load ( likelySubtags , currencyData , numbers , currencies ) ;
913
1014function loadCustom ( options ) {
@@ -239,6 +243,14 @@ describe('standard currency formatting', () => {
239243 expect ( formatNumber ( 123 , "c" ) ) . toEqual ( "$123.00" ) ;
240244 } ) ;
241245
246+ it ( "should apply format when passing language" , ( ) => {
247+ expect ( formatNumber ( 10 , "c" , "bg" ) ) . toEqual ( "10,00 лв." ) ;
248+ } ) ;
249+
250+ it ( "should apply format when passing language and territory" , ( ) => {
251+ expect ( formatNumber ( 10 , "c" , "bg-BG" ) ) . toEqual ( "10,00 лв." ) ;
252+ } ) ;
253+
242254 it ( "should apply format when passing object" , ( ) => {
243255 expect ( formatNumber ( 10 , { style : "currency" } ) ) . toEqual ( "$10.00" ) ;
244256 } ) ;
You can’t perform that action at this time.
0 commit comments