forked from mongo-express/mongo-express
-
Notifications
You must be signed in to change notification settings - Fork 4
/
filters.js
54 lines (46 loc) · 1.54 KB
/
filters.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
'use strict';
exports.json = function(input) {
return JSON.stringify(input, null, ' ');
};
exports.convertBytes = function(input) {
input = parseInt(input, 10);
if (input < 1024) {
return input.toString() + ' Bytes';
} else if (input < 1024 * 1024) {
//Convert to KB and keep 2 decimal values
input = Math.round((input / 1024) * 100) / 100;
return input.toString() + ' KB';
} else if (input < 1024 * 1024 * 1024) {
input = Math.round((input / (1024 * 1024)) * 100) / 100;
return input.toString() + ' MB';
} else if (input < 1024 * 1024 * 1024 * 1024) {
input = Math.round((input / (1024 * 1024 * 1024)) * 100) / 100;
return input.toString() + ' GB';
} else if (input < 1024 * 1024 * 1024 * 1024 * 1024) {
input = Math.round((input / (1024 * 1024 * 1024 * 1024)) * 100) / 100;
return input.toString() + ' TB';
} else {
return input.toString() + ' Bytes';
}
};
exports.to_string = function(input) {
return (input !== null && input !== undefined) ? input.toString() : '';
};
exports.to_display = function(input) {
if (
typeof input === 'string' &&
(
input.substr(0, 22) === 'data:image/png;base64,' ||
input.substr(0, 22) === 'data:image/gif;base64,' ||
input.substr(0, 23) === 'data:image/jpeg;base64,')
) {
return '<img src="' + input + '"/>';
}
if (input !== null && input !== undefined) {
return input.toString();
}
return '';
};
exports.is_embeddedDocumentNotation = function(input) {
return /^(?:[a-zA-Z0-9_]+\.)+[a-zA-Z0-9_]+/.test(input);
};