File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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' ) ;
Original file line number Diff line number Diff 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 = / ( d a t a b a s e | c o d e b a s e | f i r e b a s e | k n o w l e d g e b a s e ) s $ / i;
34+
2835const TRAILING_TRIPLE_S_REGEX = / [ s S ] { 3 , } $ / ;
2936const TRAILING_TRIPLE_S_BEFORE_ES_REGEX = / [ s S ] { 3 , } (? = e [ s S ] $ ) / ;
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
You can’t perform that action at this time.
0 commit comments