-
Notifications
You must be signed in to change notification settings - Fork 10
/
propertyFormatter.js
38 lines (35 loc) · 1.29 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
var propertyFormatter = (function() {
"use strict";
return {
extractPropertiesForDisplayAsArray: function(source) {
if (!source || source.id !== +source.id) {
return [];
}
return _.map(source, function(value, key) {
var isDate = typeof value === 'object' && value instanceof Date;
if (isDate || typeof value === 'boolean' || typeof value === 'number' ||
typeof value === 'string') {
return "Property: " + key + " of type: " + typeof value + " has value: " + value;
}
return "Property: " + key + " cannot be displayed.";
});
},
extractPropertiesForDisplayAsString: function(source) {
if (!source || source.id !== +source.id) {
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.";
},
"");
}
};
}());