-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract-nicknames.ts
65 lines (54 loc) · 1.39 KB
/
extract-nicknames.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
import { readFile } from "fs/promises";
async function main() {
const text = await readFile("data-chats.json", "utf-8");
const items = JSON.parse(text) as {
list: {
chatId: string;
profile: {
name?: string;
nickname?: string;
iconHash?: string;
};
}[];
}[];
const users: {
chatId: string;
name: string;
nickname: string;
icon: string;
}[] = [];
for (const item of items) {
for (const listItem of item.list) {
if (!listItem.profile?.name) {
continue;
}
const chatId = listItem.chatId;
const name = listItem.profile.name;
const nickname = listItem.profile.nickname ?? "";
const icon = listItem.profile.iconHash
? `https://profile.line-scdn.net/${listItem.profile.iconHash}`
: "";
const user = { chatId, name, nickname, icon };
users.push(user);
}
}
const userNames = users.map((user) => user.name);
const duplicateNames: string[] = [];
userNames.forEach((userName, i) => {
if (userNames.indexOf(userName) !== i) {
duplicateNames.push(userName);
}
});
const duplicateNamesSet = new Set(duplicateNames);
console.log(
JSON.stringify(
users.map((user) => ({
...user,
isDuplicated: duplicateNamesSet.has(user.name),
})),
null,
2
)
);
}
main().catch((err) => console.error(err));