Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions languages/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const tenment = (n, g) => hundment(n, g) % 100;
const hundredIt = (n) => {
if (n < 100 || n >= 1000) return '';
const h = Math.floor(n / 100);
const remainder = n % 100;
// Elision: drop trailing 'o' before otto (8) and ottanta (80-89)
if (remainder >= 80 && remainder <= 89 || remainder === 8) {
return IT_HUNDREDS[h].slice(0, -1);
}
return IT_HUNDREDS[h];
};

Expand Down
12 changes: 11 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,22 @@ describe('italian', () => {
expect(italian(42)).toBe('quarantadue');
});

it('handles elision rules', () => {
it('handles tens elision rules', () => {
expect(italian(21)).toBe('ventuno');
expect(italian(28)).toBe('ventotto');
expect(italian(23)).toBe('ventitré');
});

it('handles cento elision before otto/ottanta', () => {
expect(italian(108)).toBe('centotto');
expect(italian(180)).toBe('centottanta');
expect(italian(188)).toBe('centottantotto');
expect(italian(208)).toBe('duecentotto');
expect(italian(280)).toBe('duecentottanta');
expect(italian(808)).toBe('ottocentotto');
expect(italian(880)).toBe('ottocentottanta');
});

it('converts thousands', () => {
expect(italian(1000)).toBe('mille');
expect(italian(2000)).toBe('duemila');
Expand Down