mirror of
				https://github.com/gristlabs/grist-core.git
				synced 2025-06-13 20:53:59 +00:00 
			
		
		
		
	(core) Adding fallback for currency symbol
Summary: Adding fallback for currency formatting on older browsers. Test Plan: Existing tests Reviewers: alexmojaki Reviewed By: alexmojaki Subscribers: alexmojaki Differential Revision: https://phab.getgrist.com/D3108
This commit is contained in:
		
							parent
							
								
									db34e1a6d9
								
							
						
					
					
						commit
						4ddc29fb40
					
				@ -66,9 +66,21 @@ export function buildNumberFormat(options: NumberFormatOptions, docSettings: Doc
 | 
			
		||||
  return new Intl.NumberFormat(docSettings.locale, nfOptions);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Safari 13 and some other browsers don't support narrowSymbol option:
 | 
			
		||||
// https://github.com/mdn/browser-compat-data/issues/8985
 | 
			
		||||
// https://caniuse.com/?search=currencyDisplay
 | 
			
		||||
const currencyDisplay = (function(){
 | 
			
		||||
  try {
 | 
			
		||||
    new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD', currencyDisplay: 'narrowSymbol'});
 | 
			
		||||
    return 'narrowSymbol';
 | 
			
		||||
  } catch(err) {
 | 
			
		||||
    return 'symbol';
 | 
			
		||||
  }
 | 
			
		||||
})();
 | 
			
		||||
 | 
			
		||||
export function parseNumMode(numMode?: NumMode, currency?: string): Intl.NumberFormatOptions {
 | 
			
		||||
  switch (numMode) {
 | 
			
		||||
    case 'currency': return {style: 'currency', currency, currencyDisplay: 'narrowSymbol' };
 | 
			
		||||
    case 'currency': return {style: 'currency', currency, currencyDisplay};
 | 
			
		||||
    case 'decimal': return {useGrouping: true};
 | 
			
		||||
    case 'percent': return {style: 'percent'};
 | 
			
		||||
    // TODO 'notation' option (and therefore numMode 'scientific') works on recent Firefox and
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user