Commit 51509bb2 by Hugo Häggmark Committed by GitHub

Units: adds scale symbol for currencies with suffixed symbol (#24678)

parent cfac5912
import { currency } from './symbolFormatters';
describe('currency', () => {
const symbol = '@';
describe('when called without asSuffix', () => {
const fmtFunc = currency(symbol);
it.each`
value | expectedSuffix | expectedText
${999} | ${''} | ${'999'}
${1000} | ${'K'} | ${'1'}
${1000000} | ${'M'} | ${'1'}
${1000000000} | ${'B'} | ${'1'}
${1000000000000} | ${'T'} | ${'1'}
${1000000000000000} | ${undefined} | ${'NA'}
${-1000000000000} | ${'T'} | ${'-1'}
${-1000000000} | ${'B'} | ${'-1'}
${-1000000} | ${'M'} | ${'-1'}
${-1000} | ${'K'} | ${'-1'}
${-999} | ${''} | ${'-999'}
`('when called with value:{$value}', ({ value, expectedSuffix, expectedText }) => {
const { prefix, suffix, text } = fmtFunc(value);
expect(prefix).toEqual(symbol);
expect(suffix).toEqual(expectedSuffix);
expect(text).toEqual(expectedText);
});
});
describe('when called with asSuffix', () => {
const fmtFunc = currency(symbol, true);
it.each`
value | expectedSuffix | expectedText
${999} | ${'@'} | ${'999'}
${1000} | ${'K@'} | ${'1'}
${1000000} | ${'M@'} | ${'1'}
${1000000000} | ${'B@'} | ${'1'}
${1000000000000} | ${'T@'} | ${'1'}
${1000000000000000} | ${undefined} | ${'NA'}
${-1000000000000} | ${'T@'} | ${'-1'}
${-1000000000} | ${'B@'} | ${'-1'}
${-1000000} | ${'M@'} | ${'-1'}
${-1000} | ${'K@'} | ${'-1'}
${-999} | ${'@'} | ${'-999'}
`('when called with value:{$value}', ({ value, expectedSuffix, expectedText }) => {
const { prefix, suffix, text } = fmtFunc(value);
expect(prefix).toEqual(undefined);
expect(suffix).toEqual(expectedSuffix);
expect(text).toEqual(expectedText);
});
});
});
...@@ -10,7 +10,7 @@ export function currency(symbol: string, asSuffix?: boolean): ValueFormatter { ...@@ -10,7 +10,7 @@ export function currency(symbol: string, asSuffix?: boolean): ValueFormatter {
} }
const scaled = scaler(size, decimals, scaledDecimals); const scaled = scaler(size, decimals, scaledDecimals);
if (asSuffix) { if (asSuffix) {
scaled.suffix = symbol; scaled.suffix = scaled.suffix !== undefined ? `${scaled.suffix}${symbol}` : undefined;
} else { } else {
scaled.prefix = symbol; scaled.prefix = symbol;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment