index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. module.exports = pluralize;
  2. /**
  3. * Pluralization rules.
  4. *
  5. * These rules are applied while processing the argument to `toCollectionName`.
  6. *
  7. * @deprecated remove in 4.x gh-1350
  8. */
  9. exports.pluralization = [
  10. [/(m)an$/gi, '$1en'],
  11. [/(pe)rson$/gi, '$1ople'],
  12. [/(child)$/gi, '$1ren'],
  13. [/^(ox)$/gi, '$1en'],
  14. [/(ax|test)is$/gi, '$1es'],
  15. [/(octop|vir)us$/gi, '$1i'],
  16. [/(alias|status)$/gi, '$1es'],
  17. [/(bu)s$/gi, '$1ses'],
  18. [/(buffal|tomat|potat)o$/gi, '$1oes'],
  19. [/([ti])um$/gi, '$1a'],
  20. [/sis$/gi, 'ses'],
  21. [/(?:([^f])fe|([lr])f)$/gi, '$1$2ves'],
  22. [/(hive)$/gi, '$1s'],
  23. [/([^aeiouy]|qu)y$/gi, '$1ies'],
  24. [/(x|ch|ss|sh)$/gi, '$1es'],
  25. [/(matr|vert|ind)ix|ex$/gi, '$1ices'],
  26. [/([m|l])ouse$/gi, '$1ice'],
  27. [/(kn|w|l)ife$/gi, '$1ives'],
  28. [/(quiz)$/gi, '$1zes'],
  29. [/s$/gi, 's'],
  30. [/([^a-z])$/, '$1'],
  31. [/$/gi, 's']
  32. ];
  33. var rules = exports.pluralization;
  34. /**
  35. * Uncountable words.
  36. *
  37. * These words are applied while processing the argument to `toCollectionName`.
  38. * @api public
  39. */
  40. exports.uncountables = [
  41. 'advice',
  42. 'energy',
  43. 'excretion',
  44. 'digestion',
  45. 'cooperation',
  46. 'health',
  47. 'justice',
  48. 'labour',
  49. 'machinery',
  50. 'equipment',
  51. 'information',
  52. 'pollution',
  53. 'sewage',
  54. 'paper',
  55. 'money',
  56. 'species',
  57. 'series',
  58. 'rain',
  59. 'rice',
  60. 'fish',
  61. 'sheep',
  62. 'moose',
  63. 'deer',
  64. 'news',
  65. 'expertise',
  66. 'status',
  67. 'media'
  68. ];
  69. var uncountables = exports.uncountables;
  70. /*!
  71. * Pluralize function.
  72. *
  73. * @author TJ Holowaychuk (extracted from _ext.js_)
  74. * @param {String} string to pluralize
  75. * @api private
  76. */
  77. function pluralize(str) {
  78. var found;
  79. str = str.toLowerCase();
  80. if (!~uncountables.indexOf(str)) {
  81. found = rules.filter(function(rule) {
  82. return str.match(rule[0]);
  83. });
  84. if (found[0]) {
  85. return str.replace(found[0][0], found[0][1]);
  86. }
  87. }
  88. return str;
  89. }