-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemoji-string.js
65 lines (52 loc) · 1.74 KB
/
emoji-string.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
58
59
60
61
62
63
64
65
exports.toUniString = function (input_string) {
return input_string.split('').map(function (value, index, array) {
var temp = value.charCodeAt(0).toString(16).toUpperCase();
if (temp.length > 2) {
return '\\u' + temp;
}
return value;
}).join('');
}
exports.emoji_length = function (input_string) {
try {
return Array.from(input_string).length
} catch (e) {
console.log(e)
return -1
}
}
exports.isEmoji = function (input_string) {
var reg = RegExp(/[\uD83C-\uD83F][\uDC00-\uDFFF]/)
return reg.test(input_string)
}
exports.findEmoji = function (input_string) {
var reg = RegExp(/[\uD83C-\uD83F][\uDC00-\uDFFF]/g)
result = reg.exec(input_string)
return input_string.search(reg)
}
exports.findLastEmoji = function (input_string) {
var reg = RegExp(/[\uD83C-\uD83F][\uDC00-\uDFFF]/g)
lastindex = 0
while ((result = reg.exec(input_string)) !== null) {
lastindex = result['index']
}
return lastindex
}
exports.findAllEmoji = function (input_string) {
var reg = RegExp(/[\uD83C-\uD83F][\uDC00-\uDFFF]/g)
var result, results = []
while ((result = reg.exec(input_string)) !== null) {
results.push({ emoji: `${result[0]}`, index: `${result['index']}` })
}
return results
}
exports.RemoveEmoji = function (input_string) {
return input_string.replace(/[\uD83C-\uD83F][\uDC00-\uDFFF]/g, "")
}
exports.RemoveEmojiIndex = function (input_string, index) {
var temp = input_string.slice(0, index)
var handle = input_string.slice(index)
handle = handle.replace(/[\uD83C-\uD83F][\uDC00-\uDFFF]/g, "")
return temp + handle
}
//emoji range ref : https://unicode.org/emoji/charts-12.0/full-emoji-list.html