Completed
Pull Request — master (#77)
by
unknown
03:26
created

SmileyConf.getSmileys   B

Complexity

Conditions 1

Size

Total Lines 100
Code Lines 74

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 74
dl 0
loc 100
rs 7.8509
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
export default class SmileyConf {
2
    static getSmileys() {
3
        return [
4
            {
5
                syntax: '8-)',
6
                icon: 'icon_cool.gif',
7
            },
8
            {
9
                syntax: '8-O',
10
                icon: 'icon_eek.gif',
11
            },
12
            {
13
                syntax: '8-o',
14
                icon: 'icon_eek.gif',
15
            },
16
            {
17
                syntax: ':-(',
18
                icon: 'icon_sad.gif',
19
            },
20
            {
21
                syntax: ':-)',
22
                icon: 'icon_smile.gif',
23
            },
24
            {
25
                syntax: '=)',
26
                icon: 'icon_smile2.gif',
27
            },
28
            {
29
                syntax: ':-/',
30
                icon: 'icon_doubt.gif',
31
            },
32
            {
33
                syntax: ':-\\',
34
                icon: 'icon_doubt2.gif',
35
            },
36
            {
37
                syntax: ':-?',
38
                icon: 'icon_confused.gif',
39
            },
40
            {
41
                syntax: ':-D',
42
                icon: 'icon_biggrin.gif',
43
            },
44
            {
45
                syntax: ':-P',
46
                icon: 'icon_razz.gif',
47
            },
48
            {
49
                syntax: ':-o',
50
                icon: 'icon_surprised.gif',
51
            },
52
            {
53
                syntax: ':-O',
54
                icon: 'icon_surprised.gif',
55
            },
56
            {
57
                syntax: ':-x',
58
                icon: 'icon_silenced.gif',
59
            },
60
            {
61
                syntax: ':-X',
62
                icon: 'icon_silenced.gif',
63
            },
64
            {
65
                syntax: ':-|',
66
                icon: 'icon_neutral.gif',
67
            },
68
            {
69
                syntax: ';-)',
70
                icon: 'icon_wink.gif',
71
            },
72
            {
73
                syntax: 'm(',
74
                icon: 'facepalm.gif',
75
            },
76
            {
77
                syntax: '^_^',
78
                icon: 'icon_fun.gif',
79
            },
80
            {
81
                syntax: ':?:',
82
                icon: 'icon_question.gif',
83
            },
84
            {
85
                syntax: ':!:',
86
                icon: 'icon_exclaim.gif',
87
            },
88
            {
89
                syntax: 'LOL',
90
                icon: 'icon_lol.gif',
91
            },
92
            {
93
                syntax: 'FIXME',
94
                icon: 'fixme.gif',
95
            },
96
            {
97
                syntax: 'DELETEME',
98
                icon: 'delete.gif',
99
            },
100
        ];
101
    }
102
103
    /**
104
     * Regex escape as recommended by MDN
105
     *
106
     * @param {string} string
107
     * @returns {string}
108
     */
109
    static escapeRegExp(string) {
110
        return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
111
    }
112
113
    /**
114
     * Regex from conf
115
     *
116
     * @returns {RegExp}
117
     */
118
    static getRegex() {
119
        const smileyGroups = this.getSmileys().map(smiley => `(${SmileyConf.escapeRegExp(smiley.syntax)})`);
120
        const regexstring = smileyGroups.join('|');
121
        return new RegExp(`${regexstring}`);
122
    }
123
}
124