-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
59 lines (54 loc) · 1.71 KB
/
script.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
/**
* 19.01.2018 by Oren Aksakal
* Excel to JIRA Converter, written in like 15min;
* inspired from an internet resource, feel free to contribute.
*/
// main functionality
function excelToJira() {
var text = document.querySelector('#text-given').value;
var columns;
var splitter;
var divider;
var columnTrim;
switch (document.querySelector('#delimiter').value) {
case 'comma':
splitter = /,/g;
text = text.replace(/,/g, ' ,');
break;
case 'semicolon':
splitter = /;/g;
text = text.replace(/;/g, ' ;');
break;
case 'tab':
default:
splitter = /\t/g;
text = text.replace(/\t/g, ' \t');
break;
}
text = text.replace(/\n/g, ' \n');
text = text.split('\n');
for (var i = 0; i < text.length; i++) {
divider = i === 0 ? '|' : '|';
text[i] = divider + text[i].replace(splitter, divider) + divider;
columns = text[i].split(divider);
for (var j = 0; j < columns.length; j++) {
columnTrim = columns[j].trim();
if (columnTrim === 'NULL') {
columnTrim = '_' + columnTrim + '_';
}
columns[j] = columnTrim !== '' ? columnTrim : ' ';
}
text[i] = columns.join(divider).trim();
}
text = text.join("\r\n");
// insert results
document.querySelector('#result').innerHTML = text;
}
// run function on input
document.querySelector('#text-given').addEventListener('input', function () {
excelToJira();
});
// selection helper
document.querySelector('#result').addEventListener('click', function () {
document.querySelector('#result').select();
});