-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathclean_tags.js
43 lines (34 loc) · 1.12 KB
/
clean_tags.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
export function utilCleanTags(tags) {
var out = {};
for (var k in tags) {
if (!k) continue;
var v = tags[k];
if (v !== undefined) {
out[k] = cleanValue(k, v);
}
}
return out;
function cleanValue(k, v) {
function keepSpaces(k) {
return /_hours|_times|:conditional$/.test(k);
}
function skip(k) {
return /^(description|note|fixme)$/.test(k);
}
if (skip(k)) return v;
var cleaned = v
.split(';')
.map(function(s) { return s.trim(); })
.join(keepSpaces(k) ? '; ' : ';');
// The code below is not intended to validate websites and emails.
// It is only intended to prevent obvious copy-paste errors. (#2323)
// clean website- and email-like tags
if (k.indexOf('website') !== -1 ||
k.indexOf('email') !== -1 ||
cleaned.indexOf('http') === 0) {
cleaned = cleaned
.replace(/[\u200B-\u200F\uFEFF]/g, ''); // strip LRM and other zero width chars
}
return cleaned;
}
}