프로젝트

일반

사용자정보

통계
| 개정판:

root / HServer / 00.Server / 00.Program / node_modules / mongoose-legacy-pluralize / index.js

이력 | 보기 | 이력해설 | 다운로드 (1.8 KB)

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