Skip to content

Commit 1c233cb

Browse files
committed
fix(inflekt): add compound *base word exceptions to singularize (codebases → codebase)
1 parent cfe4567 commit 1c233cb

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

packages/inflekt/__tests__/inflection.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ describe('singularize', () => {
4949
expect(singularize('SCHEMATA')).toBe('SCHEMA');
5050
});
5151

52+
it('should singularize compound *base words correctly', () => {
53+
expect(singularize('codebases')).toBe('codebase');
54+
expect(singularize('databases')).toBe('database');
55+
expect(singularize('firebases')).toBe('firebase');
56+
expect(singularize('knowledgebases')).toBe('knowledgebase');
57+
expect(singularize('Codebases')).toBe('Codebase');
58+
expect(singularize('Databases')).toBe('Database');
59+
});
60+
61+
it('should still singularize "bases" to "basis"', () => {
62+
expect(singularize('bases')).toBe('basis');
63+
});
64+
5265
it('should canonicalize malformed trailing triple-s words', () => {
5366
expect(singularize('classs')).toBe('class');
5467
expect(singularize('Classs')).toBe('Class');

packages/inflekt/src/pluralize.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const LATIN_SUFFIX_OVERRIDES: Array<[string, string]> = [
2525
['data', 'datum'],
2626
];
2727

28+
/**
29+
* Compound words ending in "base" that the inflection library incorrectly
30+
* singularizes via its (b)a branch in the ses$ rule (e.g. codebases -> codebasis).
31+
* We intercept these before delegating to inflection.singularize().
32+
*/
33+
const COMPOUND_BASE_REGEX = /(database|codebase|firebase|knowledgebase)s$/i;
34+
2835
const TRAILING_TRIPLE_S_REGEX = /[sS]{3,}$/;
2936
const TRAILING_TRIPLE_S_BEFORE_ES_REGEX = /[sS]{3,}(?=e[sS]$)/;
3037

@@ -96,6 +103,13 @@ export function singularize(word: string): string {
96103
}
97104
}
98105

106+
// Compound *base words: the inflection library's (b)a branch in the ses$
107+
// rule incorrectly produces "codebasis" instead of "codebase".
108+
const baseMatch = normalizedWord.match(COMPOUND_BASE_REGEX);
109+
if (baseMatch) {
110+
return normalizedWord.slice(0, -1);
111+
}
112+
99113
return normalizeMalformedDoubleS(inflection.singularize(normalizedWord));
100114
}
101115

0 commit comments

Comments
 (0)