-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTreeText.js
59 lines (56 loc) · 1.15 KB
/
TreeText.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
import { CSV } from "./CSV.js";
import { StrictCSV } from "https://code4fukui.github.io/StrictCSV/js/StrictCSV.js";
class TreeText {
static makeCSV(s) {
const ss = s.split("\n")
const list = [];
let max = 0;
for (const s of ss) {
if (s.length == 0) {
continue;
}
let n = 0;
for (let i = 0;; i++, n++) {
if (s[i] != " ") {
break;
}
}
const d = [];
const lv = n / 2;
for (let i = 0; i < lv; i++) {
d.push("");
}
if (lv >= max) {
max = lv;
}
d.push(s.substring(n));
list.push(d);
}
/*
const l = [];
for (let i = 0; i <= max; i++) {
l.push("name" + (i + 1))
}
list.unshift(l);
*/
console.log("list", list);
const scsv = CSV.stringify(list);
console.log("scsv", scsv);
return scsv;
/*
const scsv = StrictCSV.stringify(list);
console.log("scsv", scsv);
return StrictCSV.parse(data);
*/
/*
const csv = CSV.encode(list);
const data2 = StrictCSV.parse(csv);
return data2;
*/
}
/*
static stringify(json) {
}
*/
}
export { TreeText };