feat: Update currency parsing methods and enhance showcase styling
This commit is contained in:
@@ -49,13 +49,13 @@ describe('CurrencyService', () => {
|
||||
CurrencyService.setGlobalDecimalSeparator('.');
|
||||
const c = new CurrencyService();
|
||||
expect(c.format(1234.56)).toBe('Rp 1,234.56');
|
||||
expect(c.parse('Rp 1,234.56')).toBe('1234.56');
|
||||
expect(c.parseToRaw('Rp 1,234.56')).toBe('1234.56');
|
||||
});
|
||||
|
||||
it('should override instance decimal separator', () => {
|
||||
const c = new CurrencyService({ decimalSeparator: '.' });
|
||||
expect(c.format(1234.56)).toBe('Rp 1,234.56');
|
||||
expect(c.parse('Rp 1,234.56')).toBe('1234.56');
|
||||
expect(c.parseToRaw('Rp 1,234.56')).toBe('1234.56');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -91,13 +91,13 @@ describe('CurrencyService', () => {
|
||||
|
||||
describe('Parsing', () => {
|
||||
it('should parse formatted string to raw numeric string', () => {
|
||||
expect(currency.parse('Rp 1.234.567')).toBe('1234567');
|
||||
expect(currency.parse('Rp 1.234,5678')).toBe('1234.5678');
|
||||
expect(currency.parseToRaw('Rp 1.234.567')).toBe('1234567');
|
||||
expect(currency.parseToRaw('Rp 1.234,5678')).toBe('1234.5678');
|
||||
});
|
||||
|
||||
it('should return empty string for null or undefined input', () => {
|
||||
expect(currency.parse(null)).toBe('');
|
||||
expect(currency.parse(undefined)).toBe('');
|
||||
expect(currency.parseToRaw(null)).toBe('');
|
||||
expect(currency.parseToRaw(undefined)).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ export class CurrencyService {
|
||||
* @param displayValue Formatted currency string
|
||||
* @returns Raw numeric string
|
||||
*/
|
||||
parse(displayValue: string | undefined | null): string {
|
||||
parseToRaw(displayValue: string | undefined | null): string {
|
||||
if (!displayValue) return '';
|
||||
|
||||
// Remove currency prefix
|
||||
|
||||
Reference in New Issue
Block a user