/
index.js
50 lines (48 loc) · 1.01 KB
/
index.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
'use strict';
class SlackBuilder {
constructor(base){
this.str = base || "";
}
build() {
return this.str;
}
isEmpty() {
return this.str.length === 0;
}
text(txt) {
this.str = `${this.str}${txt}`;
return this;
}
add(tag, next) {
this.str = next ? `${this.str} ${tag}${next}${tag} ` : `${tag}${this.str}${tag} `;
return this;
}
b(next){
return this.add("*", next);
}
del(next){
return this.add("~", next);
}
i(next){
return this.add("_", next);
}
a(title, href){
this.str = `${this.str} <${href}|${title}>`
return this;
}
code(next){
return this.add("`", next);
}
pre(next) {
return this.add("```", next);
}
comment(next) {
this.str = next ? `${this.str}\n>>>\n${next}` : `>>>\n${this.str}`;
return this;
}
br() {
this.str = `${this.str}\n`;
return this;
}
}
module.exports = SlackBuilder;