inflekt 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -5,8 +5,8 @@
5
5
  * It uses the 'inflection' package with custom overrides for Latin plural suffixes
6
6
  * that PostGraphile handles differently than standard English pluralization.
7
7
  */
8
- export * from './pluralize';
9
8
  export * from './case';
10
- export * from './naming';
11
9
  export * from './matching';
10
+ export * from './naming';
11
+ export * from './pluralize';
12
12
  export * from './transform-keys';
package/index.js CHANGED
@@ -21,8 +21,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  * It uses the 'inflection' package with custom overrides for Latin plural suffixes
22
22
  * that PostGraphile handles differently than standard English pluralization.
23
23
  */
24
- __exportStar(require("./pluralize"), exports);
25
24
  __exportStar(require("./case"), exports);
26
- __exportStar(require("./naming"), exports);
27
25
  __exportStar(require("./matching"), exports);
26
+ __exportStar(require("./naming"), exports);
27
+ __exportStar(require("./pluralize"), exports);
28
28
  __exportStar(require("./transform-keys"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inflekt",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Inflection utilities for pluralization and singularization with PostGraphile-compatible Latin suffix handling",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "homepage": "https://github.com/constructive-io/dev-utils",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "inflection": "^3.0.0",
45
- "komoji": "0.9.0"
45
+ "komoji": "0.9.1"
46
46
  },
47
- "gitHead": "cfe4567674d1906fca82b404ed77c3a0fceeb5a3"
47
+ "gitHead": "2985d68020ec7d1eeae9a839bdb7ebb68727dd55"
48
48
  }
package/pluralize.js CHANGED
@@ -43,91 +43,73 @@ exports.distinctPluralizeLast = distinctPluralizeLast;
43
43
  * Pluralization utilities with PostGraphile-compatible Latin suffix handling
44
44
  *
45
45
  * Uses the 'inflection' package with custom overrides for Latin plural suffixes
46
- * that PostGraphile handles differently than standard English pluralization.
46
+ * that PostGraphile handles differently than standard English pluralization,
47
+ * plus a dictionary-proven exception table for the words where no suffix rule
48
+ * is right (see exceptions.ts).
47
49
  */
48
50
  const inflection = __importStar(require("inflection"));
51
+ const exceptions_1 = require("./exceptions");
52
+ const rules_1 = require("./rules");
53
+ const LAST_SEGMENT_REGEX = /([A-Z]|_[a-z0-9])[a-z0-9]*_*$/;
49
54
  /**
50
- * Latin plural suffixes that inflection handles differently than PostGraphile.
51
- *
52
- * The inflection library correctly singularizes Latin words (schemata -> schematum),
53
- * but PostGraphile uses English-style naming (schemata -> schema).
54
- *
55
- * Format: [pluralSuffix, singularSuffix]
55
+ * Locate the final word segment of a compound name ("user_cookies" -> "cookies",
56
+ * "UserCookies" -> "Cookies") so the exception table applies to compounds too.
56
57
  */
57
- const LATIN_SUFFIX_OVERRIDES = [
58
- ['schemata', 'schema'],
59
- ['criteria', 'criterion'],
60
- ['phenomena', 'phenomenon'],
61
- ['media', 'medium'],
62
- ['memoranda', 'memorandum'],
63
- ['strata', 'stratum'],
64
- ['curricula', 'curriculum'],
65
- ['data', 'datum'],
66
- ];
67
- const TRAILING_TRIPLE_S_REGEX = /[sS]{3,}$/;
68
- const TRAILING_TRIPLE_S_BEFORE_ES_REGEX = /[sS]{3,}(?=e[sS]$)/;
69
- function normalizeTrailingSRun(suffix) {
70
- return suffix === suffix.toUpperCase() ? 'SS' : 'ss';
71
- }
72
- function normalizeTripleSBeforeEs(word) {
73
- return word.replace(TRAILING_TRIPLE_S_BEFORE_ES_REGEX, normalizeTrailingSRun);
74
- }
75
- function normalizeTrailingTripleS(word) {
76
- const match = word.match(TRAILING_TRIPLE_S_REGEX);
77
- if (!match) {
78
- return word;
58
+ function splitLastSegment(str) {
59
+ const matches = str.match(LAST_SEGMENT_REGEX);
60
+ if (!matches) {
61
+ return null;
79
62
  }
80
- const suffix = match[0];
81
- const prefix = word.slice(0, -suffix.length);
82
- const normalizedSuffix = normalizeTrailingSRun(suffix);
83
- return `${prefix}${normalizedSuffix}`;
84
- }
85
- function normalizeMalformedDoubleS(word) {
86
- return normalizeTrailingTripleS(normalizeTripleSBeforeEs(word));
87
- }
88
- function enforceDoubleSPlural(singularWord, pluralWord) {
89
- if (!singularWord.toLowerCase().endsWith('ss')) {
90
- return pluralWord;
63
+ const index = (matches.index ?? 0) + matches[1].length - 1;
64
+ if (index <= 0) {
65
+ return null;
91
66
  }
92
- // Defensive normalization for malformed outputs like "hazardClasss".
93
- if (pluralWord === `${singularWord}s`) {
94
- return `${singularWord}es`;
67
+ return { prefix: str.slice(0, index), word: str.slice(index) };
68
+ }
69
+ function lookupException(word) {
70
+ const key = word.toLowerCase();
71
+ if (!Object.prototype.hasOwnProperty.call(exceptions_1.SINGULAR_EXCEPTIONS, key)) {
72
+ return null;
95
73
  }
96
- return pluralWord;
74
+ return (0, rules_1.restoreWordCase)(word, exceptions_1.SINGULAR_EXCEPTIONS[key]);
97
75
  }
98
76
  /**
99
77
  * Convert a word to its singular form with PostGraphile-compatible Latin handling
100
78
  * @example "Users" -> "User", "People" -> "Person", "Schemata" -> "Schema", "ApiSchemata" -> "ApiSchema"
101
79
  */
102
80
  function singularize(word) {
103
- const normalizedWord = normalizeMalformedDoubleS(word);
104
- const lowerWord = normalizedWord.toLowerCase();
105
- for (const [pluralSuffix, singularSuffix] of LATIN_SUFFIX_OVERRIDES) {
106
- if (lowerWord.endsWith(pluralSuffix)) {
107
- const suffixStart = normalizedWord.length - pluralSuffix.length;
108
- const prefix = normalizedWord.slice(0, suffixStart);
109
- const originalSuffix = normalizedWord.slice(suffixStart);
110
- const isAllCaps = originalSuffix === originalSuffix.toUpperCase();
111
- const isUpperSuffix = originalSuffix[0] === originalSuffix[0].toUpperCase();
112
- let newSuffix;
113
- if (isAllCaps) {
114
- newSuffix = singularSuffix.toUpperCase();
115
- }
116
- else if (isUpperSuffix) {
117
- newSuffix = singularSuffix.charAt(0).toUpperCase() + singularSuffix.slice(1);
118
- }
119
- else {
120
- newSuffix = singularSuffix;
121
- }
122
- return prefix + newSuffix;
81
+ const normalizedWord = (0, rules_1.normalizeMalformedDoubleS)(word);
82
+ const exception = lookupException(normalizedWord);
83
+ if (exception) {
84
+ return exception;
85
+ }
86
+ const segment = splitLastSegment(normalizedWord);
87
+ if (segment) {
88
+ const segmentException = lookupException(segment.word);
89
+ if (segmentException) {
90
+ return segment.prefix + segmentException;
123
91
  }
124
92
  }
125
- return normalizeMalformedDoubleS(inflection.singularize(normalizedWord));
93
+ return (0, rules_1.singularizeByRules)(normalizedWord);
126
94
  }
95
+ const F_OR_FE_REGEX = /(?:f|fe)$/i;
127
96
  function pluralizeCanonical(word) {
128
- const normalizedWord = normalizeMalformedDoubleS(word);
129
- const pluralWord = normalizeMalformedDoubleS(inflection.pluralize(normalizedWord));
130
- return enforceDoubleSPlural(singularize(normalizedWord), pluralWord);
97
+ const normalizedWord = (0, rules_1.normalizeMalformedDoubleS)(word);
98
+ // -f/-fe words: only the f-stem nouns take -ves; the rest take a plain "s".
99
+ const fStem = (0, rules_1.pluralizeFStem)(normalizedWord);
100
+ if (fStem) {
101
+ return fStem;
102
+ }
103
+ if (F_OR_FE_REGEX.test(normalizedWord)) {
104
+ return `${normalizedWord}s`;
105
+ }
106
+ const pluralWord = (0, rules_1.normalizeMalformedDoubleS)(inflection.pluralize(normalizedWord));
107
+ // -is nouns the inflection library leaves untouched (iris, chassis) rather
108
+ // than treating as Greek/Latin (analysis -> analyses).
109
+ if (pluralWord === normalizedWord && /is$/i.test(normalizedWord)) {
110
+ return `${normalizedWord}es`;
111
+ }
112
+ return (0, rules_1.enforceDoubleSPlural)(singularize(normalizedWord), pluralWord);
131
113
  }
132
114
  /**
133
115
  * Convert a word to its plural form
@@ -145,7 +127,7 @@ function pluralize(word) {
145
127
  * @returns The transformed string with only the final segment changed
146
128
  */
147
129
  function changeLastWord(fn, str) {
148
- const matches = str.match(/([A-Z]|_[a-z0-9])[a-z0-9]*_*$/);
130
+ const matches = str.match(LAST_SEGMENT_REGEX);
149
131
  const index = matches ? (matches.index ?? 0) + matches[1].length - 1 : 0;
150
132
  const suffixMatches = str.match(/_*$/);
151
133
  const suffixIndex = suffixMatches && suffixMatches.index !== undefined
package/rules.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Generic suffix rules applied before delegating to the inflection library,
3
+ * replacing inflection rules that are wrong for most English words.
4
+ *
5
+ * The biggest offender is `-ves`: inflection rewrites it to `-fe`/`-f` (knives
6
+ * -> knife, wolves -> wolf), but the overwhelming majority of `-ves` words
7
+ * simply drop the trailing "s" (derives -> derive, solves -> solve, olives ->
8
+ * olive). The genuine f-stem nouns are carried by SINGULAR_EXCEPTIONS, so the
9
+ * generic case here is "drop the s".
10
+ *
11
+ * Format: [pluralPattern, singularReplacement]
12
+ */
13
+ /**
14
+ * The complete set of English nouns whose plural rewrites -f/-fe to -ves.
15
+ *
16
+ * Both directions are wrong in the inflection library, which applies the -ves
17
+ * pattern by suffix shape: it invents "caves" for cafe, "saves" for safe and
18
+ * "barves" for barf, while spelling the real cases "leafs", "thiefs" and
19
+ * "loafs". Matched as a suffix so compounds work (bookshelf -> bookshelves,
20
+ * jackknife -> jackknives).
21
+ *
22
+ * Format: [singular, plural]
23
+ */
24
+ export declare const F_STEM_PLURALS: Array<[string, string]>;
25
+ export declare function normalizeMalformedDoubleS(word: string): string;
26
+ export declare function enforceDoubleSPlural(singularWord: string, pluralWord: string): string;
27
+ /**
28
+ * Pluralize the f-stem nouns (and their compounds), or null when `word` is not
29
+ * one — in which case an -f/-fe word takes a plain "s" (cafes, roofs, barfs).
30
+ */
31
+ export declare function pluralizeFStem(word: string): string | null;
32
+ /**
33
+ * Restore the capitalization of `source` onto `replacement`.
34
+ */
35
+ export declare function restoreWordCase(source: string, replacement: string): string;
36
+ /**
37
+ * Singularize using suffix rules only — the fallback for words absent from the
38
+ * exception table (including coined identifiers that no dictionary knows).
39
+ */
40
+ export declare function singularizeByRules(word: string): string;
package/rules.js ADDED
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.F_STEM_PLURALS = void 0;
37
+ exports.normalizeMalformedDoubleS = normalizeMalformedDoubleS;
38
+ exports.enforceDoubleSPlural = enforceDoubleSPlural;
39
+ exports.pluralizeFStem = pluralizeFStem;
40
+ exports.restoreWordCase = restoreWordCase;
41
+ exports.singularizeByRules = singularizeByRules;
42
+ /**
43
+ * Rule-based singularization: the suffix rules alone, with no exception table.
44
+ *
45
+ * Kept separate from pluralize.ts so that scripts/generate-exceptions.ts can
46
+ * diff the rules against a dictionary without the exception table masking the
47
+ * very defects it is meant to record. Not part of the public API.
48
+ */
49
+ const inflection = __importStar(require("inflection"));
50
+ /**
51
+ * Latin plural suffixes that inflection handles differently than PostGraphile.
52
+ *
53
+ * The inflection library correctly singularizes Latin words (schemata -> schematum),
54
+ * but PostGraphile uses English-style naming (schemata -> schema).
55
+ *
56
+ * Format: [pluralSuffix, singularSuffix]
57
+ */
58
+ const LATIN_SUFFIX_OVERRIDES = [
59
+ ['schemata', 'schema'],
60
+ ['criteria', 'criterion'],
61
+ ['phenomena', 'phenomenon'],
62
+ ['media', 'medium'],
63
+ ['memoranda', 'memorandum'],
64
+ ['strata', 'stratum'],
65
+ ['curricula', 'curriculum'],
66
+ ['data', 'datum'],
67
+ ];
68
+ /**
69
+ * Compound words ending in "base" that the inflection library incorrectly
70
+ * singularizes via its (b)a branch in the ses$ rule (e.g. codebases -> codebasis).
71
+ * We intercept these before delegating to inflection.singularize().
72
+ */
73
+ const COMPOUND_BASE_REGEX = /(database|codebase|firebase|knowledgebase)s$/i;
74
+ /**
75
+ * Generic suffix rules applied before delegating to the inflection library,
76
+ * replacing inflection rules that are wrong for most English words.
77
+ *
78
+ * The biggest offender is `-ves`: inflection rewrites it to `-fe`/`-f` (knives
79
+ * -> knife, wolves -> wolf), but the overwhelming majority of `-ves` words
80
+ * simply drop the trailing "s" (derives -> derive, solves -> solve, olives ->
81
+ * olive). The genuine f-stem nouns are carried by SINGULAR_EXCEPTIONS, so the
82
+ * generic case here is "drop the s".
83
+ *
84
+ * Format: [pluralPattern, singularReplacement]
85
+ */
86
+ /**
87
+ * The complete set of English nouns whose plural rewrites -f/-fe to -ves.
88
+ *
89
+ * Both directions are wrong in the inflection library, which applies the -ves
90
+ * pattern by suffix shape: it invents "caves" for cafe, "saves" for safe and
91
+ * "barves" for barf, while spelling the real cases "leafs", "thiefs" and
92
+ * "loafs". Matched as a suffix so compounds work (bookshelf -> bookshelves,
93
+ * jackknife -> jackknives).
94
+ *
95
+ * Format: [singular, plural]
96
+ */
97
+ exports.F_STEM_PLURALS = [
98
+ ['calf', 'calves'],
99
+ ['dwarf', 'dwarves'],
100
+ ['elf', 'elves'],
101
+ ['half', 'halves'],
102
+ ['hoof', 'hooves'],
103
+ ['knife', 'knives'],
104
+ ['leaf', 'leaves'],
105
+ ['life', 'lives'],
106
+ ['loaf', 'loaves'],
107
+ ['scarf', 'scarves'],
108
+ ['self', 'selves'],
109
+ ['sheaf', 'sheaves'],
110
+ ['shelf', 'shelves'],
111
+ ['thief', 'thieves'],
112
+ ['wharf', 'wharves'],
113
+ ['wife', 'wives'],
114
+ ['wolf', 'wolves'],
115
+ ];
116
+ /**
117
+ * Words that are already singular but look plural to the s$ rule: no English
118
+ * plural ends in "is" (iris, analysis, chassis) or "us" (bus, status, virus,
119
+ * anxious).
120
+ */
121
+ const ALREADY_SINGULAR_REGEX = /(?:is|us)$/i;
122
+ /**
123
+ * The only -ice plurals. The inflection library's rule is written `([m|l])ice`,
124
+ * whose character class also matches "|", and it fires on any word ending in
125
+ * "ice": police -> polouse, chalice -> chalouse, service -> servouse.
126
+ */
127
+ const MOUSE_PLURALS = {
128
+ dormice: 'dormouse',
129
+ fieldmice: 'fieldmouse',
130
+ lice: 'louse',
131
+ mice: 'mouse',
132
+ titmice: 'titmouse',
133
+ woodlice: 'woodlouse',
134
+ };
135
+ const ICE_REGEX = /ice$/i;
136
+ /** @see the GENERIC_SINGULAR_RULES documentation above. */
137
+ const GENERIC_SINGULAR_RULES = [
138
+ [/zzes$/i, 'zz'], // buzzes -> buzz
139
+ [/tzes$/i, 'tz'], // waltzes -> waltz
140
+ [/yses$/i, 'ysis'], // analyses -> analysis, dialyses -> dialysis
141
+ [/([^aeiou])uses$/i, '$1us'], // cactuses -> cactus, focuses -> focus
142
+ [/ves$/i, 've'], // derives -> derive, solves -> solve, olives -> olive
143
+ ];
144
+ const TRAILING_TRIPLE_S_REGEX = /[sS]{3,}$/;
145
+ const TRAILING_TRIPLE_S_BEFORE_ES_REGEX = /[sS]{3,}(?=e[sS]$)/;
146
+ function normalizeTrailingSRun(suffix) {
147
+ return suffix === suffix.toUpperCase() ? 'SS' : 'ss';
148
+ }
149
+ function normalizeTripleSBeforeEs(word) {
150
+ return word.replace(TRAILING_TRIPLE_S_BEFORE_ES_REGEX, normalizeTrailingSRun);
151
+ }
152
+ function normalizeTrailingTripleS(word) {
153
+ const match = word.match(TRAILING_TRIPLE_S_REGEX);
154
+ if (!match) {
155
+ return word;
156
+ }
157
+ const suffix = match[0];
158
+ const prefix = word.slice(0, -suffix.length);
159
+ const normalizedSuffix = normalizeTrailingSRun(suffix);
160
+ return `${prefix}${normalizedSuffix}`;
161
+ }
162
+ function normalizeMalformedDoubleS(word) {
163
+ return normalizeTrailingTripleS(normalizeTripleSBeforeEs(word));
164
+ }
165
+ function enforceDoubleSPlural(singularWord, pluralWord) {
166
+ if (!singularWord.toLowerCase().endsWith('ss')) {
167
+ return pluralWord;
168
+ }
169
+ // Defensive normalization for malformed outputs like "hazardClasss".
170
+ if (pluralWord === `${singularWord}s`) {
171
+ return `${singularWord}es`;
172
+ }
173
+ return pluralWord;
174
+ }
175
+ /**
176
+ * Pluralize the f-stem nouns (and their compounds), or null when `word` is not
177
+ * one — in which case an -f/-fe word takes a plain "s" (cafes, roofs, barfs).
178
+ */
179
+ function pluralizeFStem(word) {
180
+ const lowerWord = word.toLowerCase();
181
+ for (const [singular, plural] of exports.F_STEM_PLURALS) {
182
+ if (!lowerWord.endsWith(singular)) {
183
+ continue;
184
+ }
185
+ const stem = word.slice(0, word.length - singular.length);
186
+ const matched = word.slice(word.length - singular.length);
187
+ return stem + matchCase(matched, plural);
188
+ }
189
+ return null;
190
+ }
191
+ /**
192
+ * Restore the capitalization of `source` onto `replacement`.
193
+ */
194
+ function restoreWordCase(source, replacement) {
195
+ if (source === source.toUpperCase()) {
196
+ return replacement.toUpperCase();
197
+ }
198
+ if (source[0] === source[0].toUpperCase()) {
199
+ return replacement.charAt(0).toUpperCase() + replacement.slice(1);
200
+ }
201
+ return replacement;
202
+ }
203
+ function matchCase(source, replacement) {
204
+ if (source && source === source.toUpperCase()) {
205
+ return replacement.toUpperCase();
206
+ }
207
+ return replacement;
208
+ }
209
+ function applyGenericSingularRules(word) {
210
+ for (const [pattern, replacement] of GENERIC_SINGULAR_RULES) {
211
+ if (!pattern.test(word)) {
212
+ continue;
213
+ }
214
+ return word.replace(pattern, (matched, ...groups) => {
215
+ const expanded = replacement.replace(/\$(\d)/g, (_, index) => String(groups[Number(index) - 1] ?? ''));
216
+ return matchCase(matched, expanded);
217
+ });
218
+ }
219
+ return null;
220
+ }
221
+ /**
222
+ * Singularize using suffix rules only — the fallback for words absent from the
223
+ * exception table (including coined identifiers that no dictionary knows).
224
+ */
225
+ function singularizeByRules(word) {
226
+ const normalizedWord = normalizeMalformedDoubleS(word);
227
+ const lowerWord = normalizedWord.toLowerCase();
228
+ if (ALREADY_SINGULAR_REGEX.test(normalizedWord)) {
229
+ return normalizedWord;
230
+ }
231
+ if (ICE_REGEX.test(normalizedWord)) {
232
+ const mouse = Object.prototype.hasOwnProperty.call(MOUSE_PLURALS, lowerWord)
233
+ ? MOUSE_PLURALS[lowerWord]
234
+ : null;
235
+ return mouse ? restoreWordCase(normalizedWord, mouse) : normalizedWord;
236
+ }
237
+ for (const [pluralSuffix, singularSuffix] of LATIN_SUFFIX_OVERRIDES) {
238
+ if (lowerWord.endsWith(pluralSuffix)) {
239
+ const suffixStart = normalizedWord.length - pluralSuffix.length;
240
+ const prefix = normalizedWord.slice(0, suffixStart);
241
+ const originalSuffix = normalizedWord.slice(suffixStart);
242
+ const isAllCaps = originalSuffix === originalSuffix.toUpperCase();
243
+ const isUpperSuffix = originalSuffix[0] === originalSuffix[0].toUpperCase();
244
+ let newSuffix;
245
+ if (isAllCaps) {
246
+ newSuffix = singularSuffix.toUpperCase();
247
+ }
248
+ else if (isUpperSuffix) {
249
+ newSuffix =
250
+ singularSuffix.charAt(0).toUpperCase() + singularSuffix.slice(1);
251
+ }
252
+ else {
253
+ newSuffix = singularSuffix;
254
+ }
255
+ return prefix + newSuffix;
256
+ }
257
+ }
258
+ // Compound *base words: the inflection library's (b)a branch in the ses$
259
+ // rule incorrectly produces "codebasis" instead of "codebase".
260
+ if (COMPOUND_BASE_REGEX.test(normalizedWord)) {
261
+ return normalizedWord.slice(0, -1);
262
+ }
263
+ const generic = applyGenericSingularRules(normalizedWord);
264
+ if (generic) {
265
+ return generic;
266
+ }
267
+ return normalizeMalformedDoubleS(inflection.singularize(normalizedWord));
268
+ }