-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
53 lines (39 loc) · 1.41 KB
/
main.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
import {
Column,
stringify,
} from "https://deno.land/[email protected]/csv/stringify.ts";
// just for finding compiling time
console.time("Time to compile");
//get json file from web and assign it to "inputJson" variable?
import inputJson from "https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.json" with { type: "json" };
const start = /^\^|^\(/g
const end = /-.{0,2}.$|\..*|\\.*$| \(.*$|\s$/g
const end2 = /\?$|\[.*$/g
const remParentheses = /^\(/g
function cleanFile () {
for (let i = 0; i<inputJson.length; i++) {
inputJson[i].hwidmatch = inputJson[i].hwidmatch.replaceAll(start, "");
inputJson[i].hwidmatch = inputJson[i].hwidmatch.replaceAll(end, "");
inputJson[i].hwidmatch = inputJson[i].hwidmatch.replaceAll(end2, "");
inputJson[i].hwidmatch = inputJson[i].hwidmatch.replaceAll(remParentheses, "");
};
};
function convertToCsv() {
// Desired values: hwidmatch manufacturer md5 model url chrome_version
// maps json values to csv for stringify
const columns: Column[] = [
"hwidmatch",
"manufacturer",
"md5",
"model",
"url",
"chrome_version"
];
return stringify(inputJson, { columns });
};
cleanFile();
const result = convertToCsv();
//console.log(result);
const outputCsv = new TextEncoder().encode(result);
Deno.writeFileSync("output.csv", outputCsv);
console.timeEnd("Time to compile");