Skip to content

Commit

Permalink
[chore]: resolve review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RgnDunes committed Jun 11, 2024
1 parent 2b66031 commit 3cd696e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { INTL_MAPPING } from '../constants';
import { ByParts } from '../types';
import { configureIntlFromI18nifyData } from '../utils';
import { getMockParts } from './mocks/configureIntlFromI18nifyData';
import { transformPartsFromIntl } from '../utils';
import { getMockParts } from './mocks/transformPartsFromIntl';

describe('configureIntlFromI18nifyData', () => {
describe('transformPartsFromIntl', () => {
Object.keys(INTL_MAPPING).forEach((currencyCode) => {
const mapping = INTL_MAPPING[currencyCode as keyof typeof INTL_MAPPING];
const symbolKey = Object.keys(mapping)[0] as keyof typeof mapping;
Expand All @@ -16,15 +16,15 @@ describe('configureIntlFromI18nifyData', () => {
];

it(`should replace the currency symbol with the value from INTL_MAPPING for ${currencyCode}`, () => {
const result = configureIntlFromI18nifyData(mockParts, currencyCode);
const result = transformPartsFromIntl(mockParts, currencyCode);
expect(result).toEqual(expectedParts);
});
});

it('should not modify parts if currency code is not in INTL_MAPPING', () => {
const currencyCode = 'XYZ';
const mockParts = getMockParts('$');
const result = configureIntlFromI18nifyData(mockParts, currencyCode);
const result = transformPartsFromIntl(mockParts, currencyCode);
expect(result).toEqual(mockParts);
});

Expand All @@ -37,7 +37,7 @@ describe('configureIntlFromI18nifyData', () => {
];

const currencyCode = 'SGD';
const result = configureIntlFromI18nifyData(
const result = transformPartsFromIntl(
mockPartsWithDifferentCurrencySymbol,
currencyCode,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/i18nify-js/src/modules/currency/formatNumber.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { withErrorBoundary } from '../../common/errorBoundary';
import { getIntlInstanceWithOptions } from '../.internal/utils';
import { ByParts, CurrencyCodeType, I18nifyNumberFormatOptions } from './types';
import { configureIntlFromI18nifyData } from './utils';
import { transformPartsFromIntl } from './utils';

// this function formats number based on different arguments passed
const formatNumber = (
Expand All @@ -28,7 +28,7 @@ const formatNumber = (
const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {};
const currencyCode = (options?.currency || intlOptions.currency) as string;

parts = configureIntlFromI18nifyData(parts, currencyCode);
parts = transformPartsFromIntl(parts, currencyCode);

// Join the parts back together to form the final formatted string
return parts.map((p) => p.value).join('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { withErrorBoundary } from '../../common/errorBoundary';
import { getIntlInstanceWithOptions } from '../.internal/utils';
import { ALLOWED_FORMAT_PARTS_KEYS } from './constants';
import { configureIntlFromI18nifyData } from './utils';
import { transformPartsFromIntl } from './utils';

const formatNumberByParts = (
amount: string | number,
Expand All @@ -34,7 +34,7 @@ const formatNumberByParts = (
const intlOptions = options?.intlOptions ? { ...options.intlOptions } : {};
const currencyCode = (options?.currency || intlOptions.currency) as string;

parts = configureIntlFromI18nifyData(parts, currencyCode);
parts = transformPartsFromIntl(parts, currencyCode);

parts.forEach((p) => {
// If the part is a group separator, add it to the integer part
Expand Down
2 changes: 1 addition & 1 deletion packages/i18nify-js/src/modules/currency/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ByParts } from './types';
* @returns {ByParts['rawParts']} - The modified array of parts with replaced values based on the
* local i18nify configuration.
*/
export const configureIntlFromI18nifyData = (
export const transformPartsFromIntl = (
parts: ByParts['rawParts'],
currencyCode: string,
): ByParts['rawParts'] => {
Expand Down

0 comments on commit 3cd696e

Please sign in to comment.