-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
101 lines (89 loc) · 2.46 KB
/
index.ts
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
*
* @author fuyg
* @date 2020-08-21
*/
import gemoji from './libs/gemoji/index.json'
import emojiRank from './libs/tracker/index.json'
import * as fs from 'fs'
const maxSnippets = 256
const counter: { [key: string]: number } = {}
const lineBreak = '\r\n'
const byteSize = (str: string): number => new Buffer(str).length
const markdownContent = [
'# supported emoji',
'',
'> This file is generated by code. Do not modify.',
'',
'| index | rank |snippets trigger | emoji | description |',
'| :--------------- | :---- | :---- | :---------- |:----------|',
]
let indexNumber = 0
function createEmojiSnippet(
emoji: string,
name: string,
description: string,
rankIndex: number,
isTag = false,
): string[] {
if (counter[name] == null) {
counter[name] = 0
} else {
counter[name] += 1
}
const theCounter = counter[name]
const theName = theCounter > 0 ? `${name}${theCounter}` : name
const lines = [
'',
isTag ? '# tag' : '# name',
`snippet ${theName} "emoji ${emoji}: ${description}"`,
`${emoji}`,
`endsnippet`,
]
indexNumber += 1
markdownContent.push(
`| ${indexNumber} | ${rankIndex} | ${theName} | ${emoji} | ${description} |`,
)
return lines
}
function createEmojiSnippetAll(): string {
const topEmojiList: string[] = []
for (let count = 0; count < maxSnippets; count++) {
const rankItem = emojiRank[count]
topEmojiList.push(rankItem.char)
}
const snippets: Array<string[]> = []
topEmojiList.forEach((topEmoji, index) => {
const found = gemoji.find((item) => item.emoji === topEmoji)
if (!found) {
return
}
const { names, tags, emoji, description } = found
const rankIndex = index + 1
names.forEach((name) => {
const snippet = createEmojiSnippet(emoji, name, description, rankIndex)
snippets.push(snippet)
})
tags.forEach((tag) => {
const snippet = createEmojiSnippet(
emoji,
tag,
description,
rankIndex,
true,
)
snippets.push(snippet)
})
})
console.log(`create ${snippets.length} snippets`)
const lines = snippets.map((item) => {
return item.join(lineBreak)
})
lines.unshift('# This file is generated by code. Do not modified')
const content = lines.join(lineBreak)
return content
}
let snippets = createEmojiSnippetAll()
fs.writeFileSync('./UltiSnips/all.snippets', snippets)
fs.writeFileSync('./list.md', markdownContent.join(lineBreak))
process.exit()