-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
46 lines (38 loc) · 1.01 KB
/
index.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
import emojiFromWord from 'emoji-from-word'
const arr = []
const each = arr.forEach
const slice = arr.slice
export function defaults (obj) {
each.call(slice.call(arguments, 1), (source) => {
if (source) {
for (var prop in source) {
if (obj[prop] === undefined) obj[prop] = source[prop]
}
}
})
return obj
}
export default {
name: 'emoji',
type: 'postProcessor',
options: {
wordSeparator: ' '
},
setOptions (options) {
this.options = defaults(options, this.options || {})
},
process (value, key, options, translator) {
const opt = this.options = defaults(options, this.options || {})
const p = (value || key || '').split(opt.wordSeparator)
return p.map((word) => {
const ret = emojiFromWord(word)
if (!ret || !ret.emoji || !ret.emoji.char) return emojiFromWord('question').emoji.char
return ret.emoji.char
}).join(opt.wordSeparator)
},
overloadTranslationOptionHandler (args) {
return {
postProcess: 'emoji'
}
}
}