UNPKG

@rashedmakkouk/dev-utils

Version:
25 lines (24 loc) 560 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** Utilities */ const lodash_1 = require("lodash"); /** * Trims last character if ends with 's' or replaces 'ies' with 'y'. * * @returns Trimmed text. */ function singular(text) { if (!text || !(0, lodash_1.isString)(text)) { return ''; } if (text.endsWith('ies')) { return text.replace(/ies$/, 'y'); } else if (text.endsWith('s')) { return text.slice(0, -1); } else { return text; } } exports.default = singular;