singularize words
Feb 21, 2025
1 minute to read
I’ll keep this short! English, despite its many weird grammar exceptions, has pretty clear-cut pluralisation patterns. We can revert them to get the singular versions:
function singularize(word) {
const endings = {
ves: 'fe',
ies: 'y',
i: 'us',
zes: 'ze',
ses: 's',
xes: 'x',
es: 'e',
s: ''
};
return word.replace(
new RegExp(`(${Object.keys(endings).join('|')})$`),
r => endings[r]
);
}