forked from ritz078/embed-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmiley.js
More file actions
88 lines (81 loc) · 1.45 KB
/
Copy pathsmiley.js
File metadata and controls
88 lines (81 loc) · 1.45 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {escapeRegExp} from '../utils'
const defaultIcons = [{
'text': ':)',
'code': ''
}, {
'text': ':D',
'code': ''
}, {
'text': ':d',
'code': ''
}, {
'text': ':(',
'code': ''
}, {
'text': ':/',
'code': ''
}, {
'text': ':P',
'code': ''
}, {
'text': ':p',
'code': ''
}, {
'text': '3:)',
'code': ''
}, {
'text': '(^)',
'code': ''
}, {
'text': ';)',
'code': ''
}, {
'text': ':o',
'code': ''
}, {
'text': '-_-',
'code': ''
}, {
'text': '(y)',
'code': ''
}, {
'text': ':*',
'code': ''
}, {
'text': '<3',
'code': ''
}, {
'text': '<3',
'code': ''
}, {
'text': '</3',
'code': ''
}, {
'text': '</3',
'code': ''
}, {
'text': '^_^',
'code': ''
}, {
'text': '8-)',
'code': ''
}, {
'text': '8|',
'code': ''
}, {
'text': ':S',
'code': ''
}, {
'text': ':s',
'code': ''
}];
export default function (input, options) {
const icons = options.customFontIcons.length ? options.customFontIcons : defaultIcons;
const escapedSymbols = icons.map((val) => escapeRegExp(val.text));
const smileyRegex = new RegExp(`(^|\\s)(${escapedSymbols.join('|')})(?=\\s|$)`, 'gi');
return input.replace(smileyRegex, (match, pre, text) => {
let index = escapedSymbols.indexOf(escapeRegExp(text));
let code = icons[index].code;
return options.template.smiley(text, pre, code, options);
});
}