I am currently seeking a way to "singularize" English words. I have found ways to do the opposite. Here's what I've come up with so far:
function singularize(word) {
const endings = {
ves: 'fe',
ies: 'y',
i: 'us',
zes: '',
ses: '',
es: '',
s: ''
};
return word.replace(
new RegExp(`(${Object.keys(endings).join('|')})$`),
r => endings[r]
);
}
However, this is not working in many cases (e.g. analysis – analyses, phenomenon – phenomena, series – series). Is there a more accurate way to do this without embedding a whole dictionary? Is there a way to access the dictionary of the browser?
And if there is no way without a dictionary, what would be at least a slightly more accurate solution?