4049
|
1 #!/usr/bin/env node
|
4067
|
2 (function() {
|
|
3 var consonant_then_o, ends_with_consonant, ends_with_e, name, starts_with_o;
|
|
4
|
|
5 name = process.argv[2];
|
|
6
|
|
7 if (!(name != null ? name.length : void 0)) {
|
|
8 console.log('Usage: ello <name>');
|
|
9 process.exit();
|
|
10 }
|
|
11
|
|
12 ends_with_e = /(.*)(e)$/i;
|
|
13
|
|
14 consonant_then_o = /(.*)([bcdfghjklmnpqrstvwxz])([o0].*)/i;
|
|
15
|
|
16 ends_with_consonant = /[bcdfghjklmnpqrstvwxz]$/i;
|
|
17
|
|
18 starts_with_o = /[o0]/i;
|
|
19
|
|
20 console.log(consonant_then_o.test(name) ? name.replace(consonant_then_o, function(match, before, consonant, rest) {
|
|
21 return before + consonant + 'ell' + rest;
|
|
22 }) : starts_with_o.test(name) ? 'hell' + name : ends_with_e.test(name) ? name.replace(ends_with_e, function(match, before) {
|
|
23 return before + 'ello';
|
|
24 }) : ends_with_consonant.test(name) ? name + 'ello' : "Hello, " + name + "!");
|
|
25
|
|
26 }).call(this); |