You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
599 B
JavaScript

'use strict';
var irregularPlurals = require('irregular-plurals');
module.exports = function (str, plural, count) {
if (typeof plural === 'number') {
count = plural;
}
if (str in irregularPlurals) {
plural = irregularPlurals[str];
} else if (typeof plural !== 'string') {
plural = (str.replace(/(?:s|x|z|ch|sh)$/i, '$&e').replace(/([^aeiou])y$/i, '$1ie') + 's')
.replace(/i?e?s$/i, function (m) {
var isTailLowerCase = str.slice(-1) === str.slice(-1).toLowerCase();
return isTailLowerCase ? m.toLowerCase() : m.toUpperCase();
});
}
return count === 1 ? str : plural;
};