-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
48 lines (44 loc) · 1.17 KB
/
utils.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
array2string = function(data) {
var out = "";
if (data && "url" in data && "title" in data) {
out = data.title + " ( " + data.url + " ) ";
}
for (var key in data) {
if (key !== "title" && key !== "url" && data[key]) {
out = out + " " + key + ':' + data[key];
}
};
return out;
}
array2string_html = function(data) {
var out = "";
if (data && "url" in data) {
out = out + " <a href=\"" + data.url + "\">" + data.title + "</a>";
}
for (var key in data) {
if (key !== "title" && key !== "url" && data[key]) {
out = out + " " + key + ':' + data[key];
}
};
return out;
}
exports.arraylist2string = function(data) {
var out = ""
for (var i = 0; i < data.length; i++) {
out = out + array2string_html(data[i]) + " ";
};
return out;
}
exports.arraylist2string_html = function(data) {
var out = "<ul>"
for (var i = 0; i < data.length; i++) {
out = out + "<li>" + array2string_html(data[i]) + "</li>";
};
return out + "</ul>";
}
exports.subset = function(obj, propList) {
return propList.reduce(function(newObj, prop) {
obj.hasOwnProperty(prop) && (newObj[prop] = obj[prop]);
return newObj;
}, {});
}