Open samhh opened 2 years ago
Perhaps we could create instances (e.g. for Intl.NumberFormat
) once in the module scope and then re-use them, e.g.:
const numberFormat = new Intl.NumberFormat('en-US')
export const a = (params) => `${numberFormat.format(params.number)}k`
export const b = (params) => `Age: ${numberFormat.format(params.number)}`
Although, I think we may need different instances because we need to pass through the options from the variables in the ICU message—e.g. a single message may have both a plain number and a number to be formatted as currency.
FormatJS has createIntlCache
which is intended to solve a similar problem:
e.g. if the same number is used twice we'll compile two instantiations of
Intl.NumberFormat
. The compiler knows enough to potentially open a function body and declare a variable.