maggie-api
Version:
🧙♀️ A magical Express middleware to auto-generate CRUD APIs for Mongoose models with validation, unique keys, and middlewares.
20 lines (19 loc) • 617 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.singularToPlural = void 0;
const singularToPlural = (word) => {
if (!word)
return word;
const lower = word.toLowerCase();
// Words ending in 'y' preceded by a consonant → 'ies'
if (lower.endsWith("y") && !/[aeiou]y$/.test(lower)) {
return word.slice(0, -1) + "ies";
}
// Words ending in s, x, z, ch, sh → add 'es'
if (/(s|x|z|ch|sh)$/.test(lower)) {
return word + "es";
}
// Default: just add 's'
return word + "s";
};
exports.singularToPlural = singularToPlural;