-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@formatjs/intl-unified-numberformat): add currencyDisplay… (#332)
add support for `currencyDisplay`: `narrowSymbol` polyfill for tc39/ecma402#200
- Loading branch information
1 parent
62b8af6
commit ad4f8bc
Showing
9 changed files
with
1,156 additions
and
237 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
packages/formatjs/packages/formatjs-extract-cldr-data/src/extract-currencies.ts
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,59 @@ | ||
import * as Currencies from 'cldr-numbers-full/main/en/currencies.json'; | ||
import {Locale} from './types'; | ||
import generateFieldExtractorFn from './utils'; | ||
import {sync as globSync} from 'glob'; | ||
import {resolve, dirname} from 'path'; | ||
import {CurrencyData} from '@formatjs/intl-utils'; | ||
import {mapValues} from 'lodash'; | ||
|
||
export type Currencies = typeof Currencies['main']['en']['numbers']['currencies']; | ||
|
||
export function getAllLocales() { | ||
return globSync('*/currencies.json', { | ||
cwd: resolve( | ||
dirname(require.resolve('cldr-numbers-full/package.json')), | ||
'./main' | ||
), | ||
}).map(dirname); | ||
} | ||
|
||
const currenciesLocales = getAllLocales(); | ||
|
||
function loadCurrencies(locale: Locale): Record<string, CurrencyData> { | ||
const jsonData = require(`cldr-numbers-full/main/${locale}/currencies.json`) as typeof Currencies; | ||
return mapValues< | ||
Record< | ||
string, | ||
{ | ||
displayName: string; | ||
'displayName-count-one'?: string; | ||
'displayName-count-other': string; | ||
symbol: string; | ||
'symbol-alt-narrow'?: string; | ||
'symbol-alt-variant'?: string; | ||
} | ||
>, | ||
CurrencyData | ||
>(jsonData.main[locale as 'en'].numbers.currencies, currencyData => { | ||
return { | ||
displayName: { | ||
one: currencyData['displayName-count-one'], | ||
other: | ||
currencyData['displayName-count-other'] || currencyData.displayName, | ||
}, | ||
symbol: currencyData.symbol, | ||
narrowSymbol: currencyData['symbol-alt-narrow'], | ||
variantSymbol: currencyData['symbol-alt-variant'], | ||
}; | ||
}); | ||
} | ||
|
||
function hasCurrencies(locale: Locale): boolean { | ||
return currenciesLocales.includes(locale); | ||
} | ||
|
||
export default generateFieldExtractorFn<Record<string, CurrencyData>>( | ||
loadCurrencies, | ||
hasCurrencies, | ||
getAllLocales() | ||
); |
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
174 changes: 0 additions & 174 deletions
174
packages/formatjs/packages/intl-unified-numberformat/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.