-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers.js
57 lines (43 loc) · 925 Bytes
/
matchers.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
var fs = require('fs');
module.exports = {
getTitle: function(input) {
if (!hasMatchFn(input)) {
return false;
}
return input.match(/# (\S+.*)\n/)
},
getTitleFs: function(input) {
return this.getTitle(fs.readFileSync(input).toString());
},
hasCode: function(input) {
if (!hasMatchFn(input)) {
return false;
}
return input.match(/<pre class="/);
},
hasColumn: function(input) {
if (!hasMatchFn(input)) {
return false;
}
var columnMatch = input.match(/(\S*?\|\|\||<div class="col">)/);
if (!columnMatch) {
return false;
}
if (columnMatch[0].match(/(<code>|`)/)) {
return false;
}
return columnMatch;
},
singleColumn: function(input) {
return !this.hasColumn(input);
}
};
function hasMatchFn(input) {
if (!input) {
return false;
}
if (!input.match) {
return false;
}
return true;
}