wallet-core/node_modules/plur/index.js

21 lines
599 B
JavaScript
Raw Normal View History

2016-10-10 03:43:44 +02: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;
};