-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelse_dup_cheker.js
88 lines (80 loc) · 2.26 KB
/
else_dup_cheker.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
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
let fs = require( 'fs');
let R = require('ramda');
let nExcel = require("node-xlsx");
let catFile = JSON.parse(fs.readFileSync("./cat.json"));
let fileList = fs.readdirSync("./else_xlsx/");
let untransed = {};
const tester = /[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+|[々〆〤]+/u;
const replacer = (str)=>{
return R.reduce((acc, key)=>{
let regExp = new RegExp(key,'g')
acc = acc.replace(regExp, catFile[key]);
return acc;
},str,R.keys(catFile));
}
let result = R.reduce((acc, fileName)=>{
if(fileName.indexOf('.xlsx') < 0)return acc;
let targetFile = nExcel.parse(__dirname+'/else_xlsx/'+fileName);
let datas = targetFile[0].data;
R.map((data)=>{
console.log(data);
if(data.length === 1){
if(!acc[data[0]]){
console.log(data[0] +"is undefined");
}
}else{
if(!acc[data[0]]){
acc[data[0]] = data[1];
}else{
if(data[1] !== acc[data[0]]) console.log(data[0] +" is not equal val : "+ data[1] +"|"+acc[data[0]]);
}
}
},datas);
return acc;
},{}, fileList)
R.forEach((fileName)=>{
if(fileName.indexOf('.xlsx') < 0)return;
let targetFile = nExcel.parse(__dirname+'/else_xlsx/'+fileName);
let datas = targetFile[0].data;
R.map((data)=>{
console.log(data);
if(data.length === 1){
if(!result[data[0]]){
console.log(data[0] +"is undefined");
untransed[data[0]] = true;
}
}
},datas);
},fileList)
R.forEach((fileName)=>{
if(fileName.indexOf('.xlsx') < 0)return;
let targetFile = nExcel.parse(__dirname+'/else_xlsx/'+fileName);
let datas = targetFile[0].data;
datas = R.map((data)=>{
if(data.length === 1){
let firstStep = result[data[0]];
let replac = replacer(data[0]);
if(!!firstStep){
return data.concat([firstStep]);
}
else if(replac !== data[0] && !R.test(tester, replac))
return data.concat([replac])
else {
return data;
}
}
else {
return data
}
},datas);
var buffer = nExcel.build([{name: targetFile[0].name, data: datas}]); // Returns a buffer
fs.writeFileSync(__dirname + "/n_"+fileName+"", buffer, 'utf8')
},fileList)
console.log();
fs.writeFileSync("./else.json",JSON.stringify(result, null,2) )
fs.writeFileSync("./else_untransed.json",JSON.stringify(untransed, null,2) )
let length = R.reduce((acc,str) => {
acc += str.length;
return acc;
},0,R.keys(untransed));
console.log(length)