forked from App2Sales/react-native-emoticons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringify.js
More file actions
30 lines (24 loc) · 775 Bytes
/
Copy pathstringify.js
File metadata and controls
30 lines (24 loc) · 775 Bytes
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
import emojiData from 'emoji-datasource';
import _ from 'lodash';
require('string.fromcodepoint');
const stringify = (text) => {
let result = '';
_.each(emojiData, (value, key) => {
const emoji = String.fromCodePoint(...value.unified.split('-').map(u => '0x' + u));
const pointAt = emoji.codePointAt();
emojiData[key].pointAt = pointAt;
});
const arr = _.toArray(text);
_.each(arr, (value, key) => {
const index = _.findIndex(emojiData, function (o) {
return o.pointAt == value.codePointAt();
});
if (index > -1) {
result += '[' + emojiData[index]['unified'] + ']';
} else {
result += value;
}
});
return result;
};
export default stringify;