indo-format
Version:
Utility functions for Indonesian-specific formatting: Rupiah, NIK, tanggal, dan terbilang.
38 lines (37 loc) • 1.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const currency_1 = require("./currency");
(0, vitest_1.describe)('formatRupiah', () => {
(0, vitest_1.it)('formats correctly without space by default', () => {
(0, vitest_1.expect)((0, currency_1.formatRupiah)(5000)).toBe('Rp5.000');
(0, vitest_1.expect)((0, currency_1.formatRupiah)(1500000)).toBe('Rp1.500.000');
});
(0, vitest_1.it)('formats with space when withSpace is true', () => {
(0, vitest_1.expect)((0, currency_1.formatRupiah)(5000, { withSpace: true })).toBe('Rp 5.000');
(0, vitest_1.expect)((0, currency_1.formatRupiah)(1500000, { withSpace: true })).toBe('Rp 1.500.000');
});
(0, vitest_1.it)('handles zero value', () => {
(0, vitest_1.expect)((0, currency_1.formatRupiah)(0)).toBe('Rp0');
});
(0, vitest_1.it)('handles decimal values', () => {
(0, vitest_1.expect)((0, currency_1.formatRupiah)(5000.75)).toBe('Rp5.000,75');
});
});
(0, vitest_1.describe)('parseRupiah', () => {
(0, vitest_1.it)('parses plain string correctly', () => {
(0, vitest_1.expect)((0, currency_1.parseRupiah)('Rp5.000')).toBe(5000);
});
(0, vitest_1.it)('parses with space correctly', () => {
(0, vitest_1.expect)((0, currency_1.parseRupiah)('Rp 5.000')).toBe(5000);
});
(0, vitest_1.it)('parses with decimals using comma', () => {
(0, vitest_1.expect)((0, currency_1.parseRupiah)('Rp5.000,75')).toBe(5000.75);
});
(0, vitest_1.it)('parses large number correctly', () => {
(0, vitest_1.expect)((0, currency_1.parseRupiah)('Rp1.500.000')).toBe(1500000);
});
(0, vitest_1.it)('parses malformed input gracefully', () => {
(0, vitest_1.expect)((0, currency_1.parseRupiah)('Rpabc123.456xyz')).toBe(123456);
});
});