forked from todd-toast/Quotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
67 lines (61 loc) · 2.31 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Comma separated string converter</title>
<style>
#textAreaContainer {
display: flex;
justify-content: space-evenly;
}
#container {
display: flex;
flex-direction: column;
}
textarea {
width: 40%;
height: 600px;
}
#selectContainer {
margin-top: 2rem;
display: flex;
justify-content: center;
}
</style>
</head>
<body>
<div id="container">
<div id="textAreaContainer">
<textarea aria-label="Input Text Container" id="inputText" oninput="convertStrings()"></textarea>
<textarea aria-label="Output Text Container" id="outputText"></textarea>
</div>
<div id="selectContainer">
<select aria-label="Quote Selector" id="quoteSelector" onchange="convertStrings()">
<option value="double">Double Quotes</option>
<option value="single">Single Quotes</option>
<option value="none">No Quotes</option>
</select>
</div>
</div>
<script>
function convertStrings() {
const quoteSelectorValue = document.getElementById('quoteSelector').value
const quoteType =
quoteSelectorValue === 'double'
? `"`
: quoteSelectorValue === 'single'
? `'`
: ``
const inputTextArea = document.getElementById('inputText')
const styledLines = inputTextArea.value.split(/\n/).map((line) => `${quoteType}${line}${quoteType},`)
const lastIndex = styledLines.length - 1
styledLines[lastIndex] = styledLines[lastIndex].split(/,/)[0]
const outputTextArea = document.getElementById('outputText')
outputTextArea.value = ''
styledLines.forEach((line) => {
outputTextArea.value += `${line}\n`
})
}
</script>
</body>
</html>