/
toActor.js
62 lines (60 loc) · 1.01 KB
/
toActor.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
//turn 'walk' into 'walker'
const irregulars = {
'tie': 'tier',
'dream': 'dreamer',
'sail': 'sailer',
'run': 'runner',
'rub': 'rubber',
'begin': 'beginner',
'win': 'winner',
'claim': 'claimant',
'deal': 'dealer',
'spin': 'spinner'
};
const dont = {
'aid': 1,
'fail': 1,
'appear': 1,
'happen': 1,
'seem': 1,
'try': 1,
'say': 1,
'marry': 1,
'be': 1,
'forbid': 1,
'understand': 1,
'bet': 1
};
const rules = [{
'reg': /e$/i,
'repl': 'er'
}, {
'reg': /([aeiou])([mlgp])$/i,
'repl': '$1$2$2er'
}, {
'reg': /([rlf])y$/i,
'repl': '$1ier'
}, {
'reg': /^(.?.[aeiou])t$/i,
'repl': '$1tter'
}];
const toActor = function(inf) {
//check blacklist
if (dont[inf]) {
return null
}
//check irregulars
if (irregulars[inf]) {
return irregulars[inf]
}
//try rules
for (let i = 0; i < rules.length; i++) {
if (inf.match(rules[i].reg)) {
return inf.replace(rules[i].reg, rules[i].repl)
}
}
//yup,
return inf + 'er'
}
module.exports = toActor