-
Notifications
You must be signed in to change notification settings - Fork 0
/
pom-pom.js
47 lines (41 loc) · 907 Bytes
/
pom-pom.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
/**
{
"api":1,
"name":"Text with pom pom",
"description":"Convert text to contain pom pom",
"author":"Max",
"icon":"quote",
"tags":"emoji,slack,funny,yellow"
}
**/
const prefix = 'alphabet-yellow-';
const infix = ':pom-pom:';
function main(input) {
try {
input.text = input.text
.split('')
.map(emoji)
.reduce((list, test) => {
return [...list, infix, test];
})
.join('');
} catch (e) {
input.postError(e.message);
}
}
const regex = /^[a-zA-Z]$/gm;
const mapping = {
'#': 'hash',
'!': 'exclamation',
'?': 'question',
'@': 'at',
};
function emoji(char) {
if (char in mapping) {
return ':' + prefix + mapping[char] + ':';
}
if (! char.match(regex)) {
return char;
}
return ':' + prefix + char.toLowerCase() + ':';
}