-
Notifications
You must be signed in to change notification settings - Fork 0
/
join.ts
65 lines (53 loc) · 1.5 KB
/
join.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, writeFile } from "fs/promises";
async function main() {
const users = (await readFile("data-export-dup.tsv", "utf8"))
.split("\n")
.filter((line) => line !== "")
.slice(1)
.map((line) => {
const [lineId, nickname, name, chatUrl] = line.split("\t");
return { lineId, nickname, name, chatUrl };
});
const customers = (await readFile("data-customers.tsv", "utf8"))
.split("\n")
.filter((line) => line !== "")
.slice(1)
.map((line) => {
const [number, name, deliveryStaff, tel, mobile] = line.split("\t");
return { number, name, deliveryStaff, tel, mobile };
});
const lineUserIdMap = new Map(
users.map((user) => {
const key = user.nickname.replace(/\s/g, "");
const value = user.lineId;
return [key, value];
})
);
const lines: string[] = [];
lines.push(
["番号", "顧客名", "LINE ID", "配達スタッフ", "固定電話", "携帯電話"].join(
"\t"
)
);
let count: number = 0;
for (const customer of customers) {
const key = customer.name.replace(/\s/g, "");
const lineId = lineUserIdMap.get(key) || "";
if (lineId !== "") {
count += 1;
}
lines.push(
[
customer.number,
customer.name,
lineId,
customer.deliveryStaff,
customer.tel,
customer.mobile,
].join("\t")
);
}
console.log(count);
writeFile("data-export.tsv", lines.join("\n"));
}
main().catch((err) => console.error(err));