Unplural

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function en_unplural (s) {
if (s.match (/(status|goods)$/)) return s
var table = [
[/tives$/, 'tive'],
[/ives$/, 'ife'],
[/ves$/, 'f'],
[/ies$/, 'y'],
[/ice$/, 'ouse'],
[/men$/, 'man'],
[/eet(h?)$/, 'oot$1'],
[/(o|ch|sh|ss|x)es$/, '$1'],
[/s$/, '']
]
for (i = 0; i < table.length; i++) {
var re = table [i] [0]
if (!s.match (re)) continue
return s.replace (re, table [i] [1])
}
return s;
}