-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatting.js
74 lines (63 loc) · 2.34 KB
/
formatting.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function format() {
const medications = document.getElementById('medications').value;
const results = document.getElementById('results');
formatted_medications = medications
/* Remove extra spaces */
.replaceAll(/[ \t]+/g, ' ')
/* Remove spaces at line start */
.replaceAll(/^\s/mg, '')
/* Replace Swedish chars */
.replaceAll(/[‰]/g, 'ä')
.replaceAll(/[ˆ]/g, 'ö')
/* Remove @ */
.replaceAll(/@/g, '')
/* Remove HSAID */
.replaceAll(/ \(cs....\)\,|cs....\,/gi, '')
.replaceAll(/ cs....\.\.\./gi, '')
.replaceAll(/ \(cs....\)/gi, '')
.replaceAll(/ cs..../gi, '')
/* Replace dosage intervals */
.replaceAll(/\/ 24 h/g, 'x 1')
.replaceAll(/\/ 12 h/g, 'x 2')
.replaceAll(/\/ 8 h/g, 'x 3')
.replaceAll(/\/ 6 h/g, 'x 4')
.replaceAll(/\/ 4 h/g, 'x 6')
/* Replace ... with - */
.replaceAll(/(\d)\.\.\.(\d)/g, '$1-$2')
/* Trim trailing spaces */
.replaceAll(/\s+$/gm, '')
/* Return results */
results.value = formatted_medications;
autosize(results);
success();
/* Copy selected text into clipboard */
navigator.clipboard.writeText(formatted_medications);
}
function autosize(element) {
element.style.height = "12rem";
element.style.width = "820px";
if (element.scrollHeight > 192) {
element.style.height = (element.scrollHeight + 5) + "px";
}
if (element.scrollWidth > 820) {
element.style.width = (element.scrollWidth + 20) + "px";
}
}
function reset() {
document.getElementById('medications').value = '';
document.getElementById('results').value = '';
}
function copy() {
navigator.clipboard.writeText(document.getElementById('results').value);
}
function success() {
/* Animate success icon */
document.getElementById('success').classList.replace('h-0', 'h-6')
document.getElementById('success').classList.replace('w-0', 'w-6')
document.getElementById('success').classList.replace('opacity-0', 'opacity-1')
setTimeout(function () {
document.getElementById('success').classList.replace('h-6', 'h-0')
document.getElementById('success').classList.replace('w-6', 'w-0')
document.getElementById('success').classList.replace('opacity-1', 'opacity-0')
}, 3000)
}