Skip to content

Commit

Permalink
feat(intl-messageformat): format scale stem in number skeleton correc…
Browse files Browse the repository at this point in the history
…tly, fix #2414
  • Loading branch information
longlho committed Dec 17, 2020
1 parent 3419140 commit e48b60c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/intl-messageformat/src/formatters.ts
Expand Up @@ -11,6 +11,7 @@ import {
isTimeElement,
MessageFormatElement,
isTagElement,
ExtendedNumberFormatOptions,
} from 'intl-messageformat-parser';
import {
MissingValueError,
Expand Down Expand Up @@ -194,10 +195,16 @@ export function formatToParts<T>(
: isNumberSkeleton(el.style)
? el.style.parsedOptions
: undefined;

if (style && (style as ExtendedNumberFormatOptions).scale) {
value =
(value as number) *
((style as ExtendedNumberFormatOptions).scale || 1);
}
result.push({
type: PART_TYPE.literal,
value: formatters
.getNumberFormat(locales, style)
.getNumberFormat(locales, style as Intl.NumberFormatOptions)
.format(value as number),
});
continue;
Expand Down
9 changes: 9 additions & 0 deletions packages/intl-messageformat/tests/index.test.ts
Expand Up @@ -847,6 +847,15 @@ describe('IntlMessageFormat', function () {
).toBe('£123,456.79');
});

it('number skeleton with scale', function () {
expect(
new IntlMessageFormat(
'{amount, number, ::percent scale/0.01}',
'en-US'
).format({amount: 12.3})
).toBe('12%');
});

it('date skeleton', function () {
expect(
new IntlMessageFormat('{d, date, ::yyyyMMMdd}', 'en-US').format({
Expand Down

0 comments on commit e48b60c

Please sign in to comment.