-
-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathfieldValue.js
More file actions
46 lines (36 loc) · 1.06 KB
/
fieldValue.js
File metadata and controls
46 lines (36 loc) · 1.06 KB
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
const _ = require('lodash');
const htmlSanitize = require('./htmlSanitize');
function getStringValue(property) {
// numeric value, cast to string
if (_.isNumber(property)) {
return _.toString(property);
}
// isEmpty check works for all types of values: strings, arrays, objects
if (_.isEmpty(property)) {
return '';
}
if (_.isString(property)) {
return property;
}
// array value, take first item in array (at this time only used for admin & name values)
if (_.isArray(property)) {
return property[0];
}
return _.toString(property);
}
function getArrayValue(property) {
// numeric value, cast to array
if (_.isNumber(property)) {
return [property];
}
// isEmpty check works for all types of values: strings, arrays, objects
if (_.isEmpty(property)) {
return [];
}
if (_.isArray(property)) {
return property;
}
return [property];
}
module.exports.getStringValue = (property) => htmlSanitize(getStringValue(property));
module.exports.getArrayValue = (property) => htmlSanitize(getArrayValue(property));