1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-17 03:56:00 -05:00
notes/node_modules/plur/index.js

21 lines
599 B
JavaScript
Raw Normal View History

2017-03-09 13:16:08 -05:00
'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;
};