Skip to content

Commit 2b1ad39

Browse files
committed
충돌오류 해결, output.js 파일 분리
1 parent 1e06188 commit 2b1ad39

File tree

6 files changed

+391
-346
lines changed

6 files changed

+391
-346
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}

asset/css/select.css

+7-8
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
.select-wrap .selected .arrow {
2121
width: 24px;
22-
background: url('../img/L-arrow-down.svg') no-repeat 70% 50%;
22+
background: url("../img/L-arrow-down.svg") no-repeat 70% 50%;
2323
background-size: 100% 100%;
2424
transition: all 0.3s;
2525
}
2626

27-
.select-wrap.active {
27+
.select-wrap.active {
2828
outline: 1px solid #c4c4c4;
2929
}
3030

@@ -33,7 +33,7 @@
3333
}
3434

3535
.select-wrap .selected:before {
36-
content: '';
36+
content: "";
3737
display: block;
3838
height: 50%;
3939
/* margin-top: 0; */
@@ -43,7 +43,7 @@
4343
right: 70px;
4444
}
4545

46-
.select-wrap select {
46+
.select-wrap #select-box {
4747
width: 100%;
4848
flex-direction: column;
4949
border: 1px solid #c4c4c4;
@@ -59,18 +59,17 @@
5959
display: none;
6060
}
6161

62-
63-
.select-wrap select.active {
62+
.select-wrap.active #select-box {
6463
display: flex;
6564
}
6665

67-
.select-wrap select option {
66+
.select-wrap #select-box option {
6867
padding: 7px 10px;
6968
color: #fff;
7069
border-radius: 15px;
7170
}
7271

73-
.select-wrap select option:hover {
72+
.select-wrap #select-box option:hover {
7473
background-color: var(--purple);
7574
/* color: #000; */
7675
}

asset/js/menubar.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ const bottomSheetModal = document.getElementById('bottomSheetModal');
44
const modalContent = document.querySelector('.modal-content');
55

66
openModalBtn.addEventListener('click', () => {
7-
bottomSheetModal.style.height = '100%';
8-
});
9-
10-
closeModalBtn.addEventListener('click', () => {
11-
bottomSheetModal.style.height = '0';
12-
});
13-
14-
function checkScroll() {
15-
const contentHeight = modalContent.clientHeight;
16-
const scrollHeight = modalContent.scrollHeight;
17-
18-
if (scrollHeight > contentHeight) {
19-
modalContent.style.overflowY = 'auto';
20-
} else {
21-
modalContent.style.overflowY = 'visible';
22-
}
7+
bottomSheetModal.style.height = '100%';
8+
});
9+
10+
closeModalBtn.addEventListener('click', () => {
11+
bottomSheetModal.style.height = '0';
12+
});
13+
14+
function checkScroll() {
15+
const contentHeight = modalContent.clientHeight;
16+
const scrollHeight = modalContent.scrollHeight;
17+
18+
if (scrollHeight > contentHeight) {
19+
modalContent.style.overflowY = 'auto';
20+
} else {
21+
modalContent.style.overflowY = 'visible';
2322
}
23+
}
2424

25-
// 모달 내용 변경 시 호출
25+
// 모달 내용 변경 시 호출
2626
function updateModalContent(newContent) {
27-
modalContent.innerHTML = newContent;
28-
checkScroll();
29-
}
30-
31-
// 초기 모달 내용 확인
32-
checkScroll();
27+
modalContent.innerHTML = newContent;
28+
checkScroll();
29+
}
30+
31+
// 초기 모달 내용 확인
32+
checkScroll();

asset/js/output.js

+256
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
let first_name = ["이", "김", "한", "차", "남"];
2+
let last_name = [
3+
"가람",
4+
"가온",
5+
"그린",
6+
"겨루",
7+
"나래",
8+
"늘봄",
9+
"다슬",
10+
"라라",
11+
"루리",
12+
"마루",
13+
"바다",
14+
"새길",
15+
"새나",
16+
];
17+
18+
function uuid() {
19+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
20+
/[xy]/g,
21+
function (c) {
22+
let r = (Math.random() * 16) | 0;
23+
let v = c == "x" ? r : randomItem(["A", "B", "C"]);
24+
return v.toString(16);
25+
}
26+
);
27+
}
28+
29+
function randomInteger(min, max) {
30+
return Math.floor(Math.random() * (max - min + 1)) + min;
31+
}
32+
33+
function randomItem(items) {
34+
return items[Math.floor(Math.random() * items.length)];
35+
}
36+
37+
function generateData(template, index) {
38+
return template.replace(/{{([^{}]+)}}/g, function (_, key) {
39+
// key 값은 중괄호 안에 들어있는 값
40+
// console.log(key)
41+
const func = key.split("(")[0];
42+
const [...args] = key
43+
.split("(")[1]
44+
.replace(")", "")
45+
.replaceAll(" ", "")
46+
.replaceAll("'", "")
47+
.replaceAll('"', "")
48+
.split(",");
49+
// console.log(func, args)
50+
51+
switch (func) {
52+
case "id":
53+
return uuid();
54+
case "index":
55+
return index;
56+
case "integer":
57+
return randomInteger(parseInt(args[0]), parseInt(args[1]));
58+
case "random":
59+
return randomItem(args.map((s) => s.replace(/"/g, "").trim()));
60+
case "name":
61+
return randomItem(first_name) + randomItem(last_name);
62+
default:
63+
return _;
64+
}
65+
});
66+
}
67+
68+
document
69+
.getElementById("generate-button")
70+
.addEventListener("click", function () {
71+
// let input = JSON.parse(document.getElementById('json-input').value.replace(/'/g, '"'));
72+
let input = `[
73+
"{{repeat(5)}}",
74+
{
75+
"_id": "{{id()}}",
76+
"index": "{{index()}}",
77+
"picture": "http://via.placeholder.com/32x32",
78+
"age": "{{integer(20, 40)}}",
79+
"eyeColor": "{{random('blue', 'brown', 'green')}}",
80+
"name": "{{name()}}"
81+
}]`;
82+
input = JSON.parse(input);
83+
console.log(input);
84+
85+
let repeatCount = parseInt(input[0].match(/(\d+)/)[0]);
86+
console.log(repeatCount);
87+
88+
let template = JSON.stringify(input[1]);
89+
console.log(template);
90+
91+
let output = [];
92+
console.log(repeatCount);
93+
94+
for (let i = 0; i < repeatCount; i++) {
95+
output.push(JSON.parse(generateData(template, i)));
96+
}
97+
console.log(output);
98+
99+
document.getElementById("json-output").value = JSON.stringify(
100+
output,
101+
null,
102+
2
103+
);
104+
});
105+
106+
// csv 다운로드 버튼 클릭시 이벤트
107+
document
108+
.getElementById("downloadcsv-button")
109+
.addEventListener("click", function () {
110+
// json-output textarea의 값을 가져온다.
111+
let json = document.getElementById("json-output").value;
112+
// json을 객체로 변환한다.
113+
let data = JSON.parse(json);
114+
// csv 파일의 첫번째 줄에 들어갈 키를 추출한다.
115+
let keys = Object.keys(data[0]);
116+
// csv 파일의 첫번째 줄을 만든다.
117+
let csv = keys.join(",") + "\n";
118+
// csv 파일의 두번째 줄부터 데이터를 넣는다.
119+
data.forEach(function (row) {
120+
// csv 파일의 한 줄을 만든다.
121+
let line = keys
122+
.map(function (key) {
123+
return row[key];
124+
})
125+
.join(",");
126+
// csv 파일에 한 줄을 추가한다.
127+
csv += line + "\n";
128+
});
129+
// csv 파일을 다운로드한다.
130+
download("data.csv", csv);
131+
});
132+
133+
// json 다운로드 버튼 클릭시 이벤트
134+
document
135+
.getElementById("downloadjson-button")
136+
.addEventListener("click", function () {
137+
// json-output textarea의 값을 가져온다.
138+
let json = document.getElementById("json-output").value;
139+
// json 파일을 다운로드한다.
140+
download("data.json", json);
141+
});
142+
143+
// html 다운로드 버튼 클릭시 이벤트
144+
document
145+
.getElementById("downloadhtml-button")
146+
.addEventListener("click", function () {
147+
// json-output textarea의 값을 가져온다.
148+
let json = document.getElementById("json-output").value;
149+
// json을 객체로 변환한다.
150+
let data = JSON.parse(json);
151+
// html 파일을 만든다.
152+
let html = "<table>\n";
153+
// html 파일의 첫번째 줄에 들어갈 키를 추출한다.
154+
let keys = Object.keys(data[0]);
155+
// html 파일의 첫번째 줄을 만든다.
156+
html += "\t<tr>\n";
157+
// html 파일의 첫번째 줄에 키를 넣는다.
158+
keys.forEach(function (key) {
159+
html += "\t\t<th>" + key + "</th>\n";
160+
});
161+
// html 파일의 첫번째 줄을 닫는다.
162+
html += "\t</tr>\n";
163+
// html 파일의 두번째 줄부터 데이터를 넣는다.
164+
data.forEach(function (row) {
165+
// html 파일의 한 줄을 만든다.
166+
html += "\t<tr>\n";
167+
// html 파일의 한 줄에 데이터를 넣는다.
168+
keys.forEach(function (key) {
169+
html += "\t\t<td>" + row[key] + "</td>\n";
170+
});
171+
// html 파일의 한 줄을 닫는다.
172+
html += "\t</tr>\n";
173+
});
174+
// html 파일을 닫는다.
175+
html += "</table>";
176+
// html 파일을 다운로드한다.
177+
download("data.html", html);
178+
});
179+
180+
// xml 다운로드 버튼 클릭시 이벤트
181+
document
182+
.getElementById("downloadxml-button")
183+
.addEventListener("click", function () {
184+
// json-output textarea의 값을 가져온다.
185+
let json = document.getElementById("json-output").value;
186+
// json을 객체로 변환한다.
187+
let data = JSON.parse(json);
188+
// xml 파일을 만든다.
189+
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
190+
// xml 파일의 첫번째 줄에 들어갈 키를 추출한다.
191+
let keys = Object.keys(data[0]);
192+
// xml 파일의 첫번째 줄을 만든다.
193+
xml += "<rows>\n";
194+
// xml 파일의 두번째 줄부터 데이터를 넣는다.
195+
data.forEach(function (row) {
196+
// xml 파일의 한 줄을 만든다.
197+
xml += "\t<row>\n";
198+
// xml 파일의 한 줄에 데이터를 넣는다.
199+
keys.forEach(function (key) {
200+
xml += "\t\t<" + key + ">" + row[key] + "</" + key + ">\n";
201+
});
202+
// xml 파일의 한 줄을 닫는다.
203+
xml += "\t</row>\n";
204+
});
205+
// xml 파일을 닫는다.
206+
xml += "</rows>";
207+
// xml 파일을 다운로드한다.
208+
download("data.xml", xml);
209+
});
210+
211+
// sql query 다운로드 버튼 클릭시 이벤트
212+
document
213+
.getElementById("downloadsql-button")
214+
.addEventListener("click", function () {
215+
// json-output textarea의 값을 가져온다.
216+
let json = document.getElementById("json-output").value;
217+
// json을 객체로 변환한다.
218+
let data = JSON.parse(json);
219+
// sql query 파일을 만든다.
220+
let sql = "INSERT INTO table_name (";
221+
// sql query 파일의 첫번째 줄에 들어갈 키를 추출한다.
222+
let keys = Object.keys(data[0]);
223+
// sql query 파일의 첫번째 줄을 만든다.
224+
sql += keys.join(", ") + ") VALUES\n";
225+
// sql query 파일의 두번째 줄부터 데이터를 넣는다.
226+
data.forEach(function (row, index) {
227+
// sql query 파일의 한 줄을 만든다.
228+
sql += "\t(";
229+
// sql query 파일의 한 줄에 데이터를 넣는다.
230+
keys.forEach(function (key) {
231+
sql += "'" + row[key] + "', ";
232+
});
233+
// sql query 파일의 한 줄을 닫는다.
234+
sql = sql.slice(0, -2) + ")";
235+
// sql query 파일의 한 줄을 닫는다.
236+
sql += index === data.length - 1 ? ";" : ",";
237+
// sql query 파일의 한 줄을 닫는다.
238+
sql += "\n";
239+
});
240+
// sql query 파일을 다운로드한다.
241+
download("data.sql", sql);
242+
});
243+
244+
function download(filename, text) {
245+
// a 태그를 만든다.
246+
let element = document.createElement("a");
247+
// href 속성을 추가한다.
248+
element.setAttribute(
249+
"href",
250+
"data:text/plain;charset=utf-8," + encodeURIComponent(text)
251+
);
252+
// download 속성을 추가한다.
253+
element.setAttribute("download", filename);
254+
// a 태그를 클릭한다.
255+
element.click();
256+
}

asset/js/select.js

+7
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ function selectOption(optionElement) {
2121
const selectedElement = selectBox.querySelector(".selected-value");
2222
selectedElement.textContent = optionElement.textContent;
2323
}
24+
25+
const select = document.querySelector("#select-box");
26+
const selectedValue = document.querySelector("#selected-value");
27+
select.addEventListener("change", function () {
28+
const selectedOptions = Array.from(select.selectedOptions, option => option.text);
29+
selectedValue.textContent = selectedOptions.join(", ");
30+
});

0 commit comments

Comments
 (0)