1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-09 07:17:31 -05:00
notes/node_modules/plur/index.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

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;
};