singularize function
Minimal English singularization used for resource parameter names
(posts → post, categories → category, people → people).
Implementation
String singularize(String word) {
if (word.endsWith('ies') && word.length > 3) {
return '${word.substring(0, word.length - 3)}y';
}
if (word.endsWith('ses') ||
word.endsWith('xes') ||
word.endsWith('ches') ||
word.endsWith('shes')) {
return word.substring(0, word.length - 2);
}
if (word.endsWith('us') || word.endsWith('ss') || word.endsWith('is')) {
return word;
}
if (word.endsWith('s') && word.length > 1) {
return word.substring(0, word.length - 1);
}
return word;
}