-
Notifications
You must be signed in to change notification settings - Fork 10
/
propertyFormatter.js
62 lines (55 loc) · 2.48 KB
/
propertyFormatter.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
var propertyFormatter = (function() {
"use strict";
return {
extractPropertiesForDisplay: function(source, ignoreId) {
var propertiesForDisplay = [];
if (!source || (!ignoreId && source.id !== +source.id) || _.keys(source).length === 0) {
return propertiesForDisplay;
}
_.each(_.pairs(source), function(keyValue) {
var isDate = typeof keyValue[1] === 'object' && keyValue[1] instanceof Date;
if (isDate || typeof keyValue[1] === 'boolean' || typeof keyValue[1] === 'number' ||
typeof keyValue[1] === 'string') {
propertiesForDisplay.push("Property: " + keyValue[0] + " of type: " + typeof keyValue[1] + " has value: " + keyValue[1]);
} else {
propertiesForDisplay.push("Property: " + keyValue[0] + " cannot be displayed.");
}
});
return propertiesForDisplay;
},
extractDataPropertiesForDisplay: function(source, ignoreId) {
var propertiesForDisplay = [];
if (!source || (!ignoreId && source.id !== +source.id) || _.keys(source).length === 0) {
return propertiesForDisplay;
}
var functionNames = _.functions(source);
_.each(_.pairs(source), function(keyValue) {
var isDate = typeof keyValue[1] === 'object' && keyValue[1] instanceof Date;
if (isDate || typeof keyValue[1] === 'boolean' || typeof keyValue[1] === 'number' ||
typeof keyValue[1] === 'string') {
propertiesForDisplay.push("Property: " + keyValue[0] + " of type: " + typeof keyValue[1] + " has value: " + keyValue[1]);
} else if (!_.contains(functionNames, keyValue[0])) {
propertiesForDisplay.push("Property: " + keyValue[0] + " cannot be displayed.");
}
});
return propertiesForDisplay;
},
extractAllPropertiesForDisplay: function(source, ignoreId) {
if (!source || (!ignoreId && source.id !== +source.id) || _.keys(source).length === 0) {
return [];
}
return _.reduce(source, function(memo, value, key) {
if (memo && memo !== "") {
memo += "<br/>";
}
var isDate = typeof value === 'object' && value instanceof Date;
if (isDate || typeof value === 'boolean' || typeof value === 'number' ||
typeof value === 'string') {
return memo + "Property: " + key + " of type: " + typeof value + " has value: " + value;
}
return memo + "Property: " + key + " cannot be displayed.";
},
"");
}
};
}());