Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-expose Intl.NumberFormat.formatToParts
`Intl.NumberFormat.formatToParts` was first propsed in #30. The spec for it was created in #79 and merged in #100 (with follow-ups). Due to browser implementations not being ready at the time, it was moved back to Stage 3 in #101. The internal refactoring were kept in master and the user-facing method `formatToParts` was removed from the spec in #102. As of August 1st, 2017, `Intl.NumberFormat.prototype.formatToParts` has shipped in two engines (behind a flag): SpiderMonkey and V8. This PR brings `Intl.NumberFormat.formatToParts` back as Stage 4 proposal. > const usd = Intl.NumberFormat('en', { style: 'currency', currency: 'USD' }); > usd.format(123456.789) '$123,456.79' > usd.formatToParts(123456.789) [ { type: 'currency', value: '$' }, { type: 'integer', value: '123' }, { type: 'group', value: ',' }, { type: 'integer', value: '456' }, { type: 'decimal', value: '.' }, { type: 'fraction', value: '79' } ] > const pc = Intl.NumberFormat('en', { style: 'percent', minimumFractionDigits: 2 }) > pc.format(-0.123456) '-12.35%' > pc.formatToParts(-0.123456) [ { type: 'minusSign', value: '-' }, { type: 'integer', value: '12' }, { type: 'decimal', value: '.' }, { type: 'fraction', value: '35' }, { type: 'literal', value: '%' } ]
- Loading branch information