Skip to content

Commit

Permalink
fix(adjectives): issue with declining words ending in -er
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoBechtel committed Mar 27, 2021
1 parent 1ad0ac6 commit 1a25b79
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/adjective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,27 @@ export interface Adjective
gender: (gender: Gender) => this;
}

/**
* creates a declinable adjective
* @param template adjective in base form
* @example adjective('klein');
*/
export function adjective(template: string): Adjective {
/**
* removes e at the end
* removes 'e' at the end
* e.g. leise => leis
* teuer => teur
*/
let stem = template.replace(/e([rl]?)$/, '$1');
let stem = template.replace(/e(l?)$/, '$1');

/**
* removes 'e' in '-er' after diphthong (eu,ei,au)
* e.g. teuer => teur
*/
stem = stem.replace(/(eu|ei|au)er$/, '$1r');

/**
* hoch => hoh
* (any word that ends with 'hoch', so you do something like 'sehr hoch')
* (any word that ends with 'hoch', so you can write something like 'sehr hoch')
*/
stem = stem.replace(/hoch$/, 'hoh');

Expand Down
12 changes: 11 additions & 1 deletion test/adjective.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ test('handles edge cases', () => {
expect(quiet.plural().write()).toBe('leisen');

/**
* words ending with -er should not contain an 'e'
* words ending with -er after diphthong (ei,au,eu) should not contain an 'e'
*/
const pricey = adjective('teuer');
expect(pricey.write()).toBe('teure');
Expand All @@ -159,6 +159,16 @@ test('handles edge cases', () => {
expect(pricey.dative().write()).toBe('teuren');
expect(pricey.plural().write()).toBe('teuren');

/**
* others ending in -er should not be modified
*/
const tasty = adjective('lecker');
expect(tasty.write()).toBe('leckere');
expect(tasty.accusative().write()).toBe('leckere');
expect(tasty.genitive().write()).toBe('leckeren');
expect(tasty.dative().write()).toBe('leckeren');
expect(tasty.plural().write()).toBe('leckeren');

/**
* words ending with -el should switch 'e' with 'l'
* e.g. dunkel => dunkle instead of dunkel => dunkele
Expand Down

0 comments on commit 1a25b79

Please sign in to comment.