-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (28 loc) · 1.01 KB
/
script.js
File metadata and controls
29 lines (28 loc) · 1.01 KB
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
function commarize() {
const input = document.getElementById('input').value;
const quote = document.getElementById('quote').checked;
const trim = document.getElementById('trim').checked;
const whitespaces = document.getElementById('whitespaces').checked;
let output = input;
if (trim) {
output = output.replace(/\s+\n/g, '\n');
}
if (whitespaces) {
output = output.replace(/ /g, '');
}
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');
}