forked from wowo/commarize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
86 lines (83 loc) · 5.02 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:creator" content="@sznapka">
<meta name="twitter:site" content="@sznapka">
<meta property="og:image" content="https://commarize.com/commarize-screenshot.png">
<meta property="og:type" content="website">
<meta property="og:url" content="https://commarize.com/">
<title>Commarize - turn multi-line input into comma-separated output</title>
<meta property="og:title" content="Commarize - turn multi-line input into comma-separated output">
<meta property="og:description" content="A simple tool which turns items from new lines into a comma-separated string, especially useful when transforming Excel or CSV data into SQL WHERE IN query parameters for ad-hoc analysis or debugging">
<meta name="description" content="A simple tool which turns items from new lines into a comma-separated string, especially useful when transforming Excel or CSV data into SQL WHERE IN query parameters for ad-hoc analysis or debugging">
<script type="text/javascript">
function commarize() {
const input = document.getElementById('input').value;
const quote = document.getElementById('quote').checked;
const trim = document.getElementById('trim').checked;
let output = input;
if (trim) {
output = output.replace(/\s+\n/g, '\n');
}
output = output.replace(/\n/g, ', ');
output = output.replace(/, ?$/, '');
if (quote) {
output = output.replace(/, /g, '\', \'');
output = output.replace(/^/, '\'');
output = output.replace(/$/, '\'');
}
document.getElementById('output').value = output;
document.getElementById('count').innerHTML = (input.match(/\n/g) || []).length + 1;
}
function clipboard() {
const copyText = document.getElementById('output');
copyText.select();
copyText.setSelectionRange(0, 99999); /*For mobile devices*/
document.execCommand('copy');
}
</script>
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<style type="text/css">
textarea {
height: 200px !important;
}
</style>
</head>
<body onload="commarize()">
<div class="w-auto m-4">
<h1 class="text-3xl border-l-2 border-blue-600 pl-4 text-blue-900">Commarize</h1>
<p class="my-4 text-gray-600 leading-normal">A simple tool which turns items from new lines into a comma-separated string, especially useful when transforming Excel or CSV data into SQL WHERE IN query parameters for ad-hoc analysis or debugging.</p>
<div class="flex">
<div class="w-1/2">
<p class="text-gray-700 text-sm font-bold mb-2">
<label for="input">Multi-line input (<span id="count">0</span> lines)</label>
</p>
</div>
<div class="w-1/2 pl-4">
<p class="text-gray-700 text-sm font-bold mb-2">
<label for="output">Output</label>
<span class="block">
<label for="quote"><input type="checkbox" class="mr-1 leading-tight" id="quote" onclick="commarize()"/> Quote</label>
<label for="trim"><input type="checkbox" class="mr-1 leading-tight" id="trim" onclick="commarize()"/> Trim</label>
</span>
</p>
</div>
</div>
<div class="flex">
<div class="w-1/2 pr-4">
<textarea class="w-full h-auto shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="input" onkeyup="commarize()"></textarea>
</div>
<div class="w-1/2 pl-4">
<textarea class="w-full h-auto shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="output" readonly></textarea>
</div>
</div>
<div class="mt-4">
<button class="shadow bg-blue-500 hover:bg-blue-700 focus:shadow-outline focus:outline-none text-white font-bold py-2 px-4 rounded" onclick="commarize()" type="button">Commarize!</button>
<a href="#" class="float-right text-blue-800 text-xs" onclick="clipboard()">Copy to clipboard</a>
<footer class="mt-8 text-center text-gray-800 text-s">
© 2020 <a href="https://blog.sznapka.pl" class="underline text-blue-500">sznapka.pl</a>
</footer>
</div>
</body>
</html>