mirror of
https://github.com/thangisme/notes.git
synced 2024-11-01 00:37:33 -04:00
21 lines
599 B
JavaScript
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;
|
||
|
};
|