-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathjson.js
60 lines (50 loc) · 1.43 KB
/
json.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
(function() {
'use strict';
module.exports = {
//format information
id: 'json',
/**
* Return content to be printed before all file results.
* @return {String} to prepend before all results
*/
startFormat: function() {
return '';
},
/**
* Return content to be printed after all file results.
* @return {String} to append after all results
*/
endFormat: function() {
return '';
},
formatResults: function(messages, filename, options) {
var output = '';
/**
* Capitalize and return given string.
* @param str {String} to capitalize
* @return {String} capitalized
*/
var capitalize = function(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
};
if (messages.length === 0) {
return '{ "errors": [] }';
}
var len = messages.length;
output += '{ "errors": [';
for (var x = 0; x < len; x++) {
output += '{ "type": "' + capitalize(messages[x].type) + '", "rule": "';
output += capitalize(messages[x].rule.name) + '", "message": "' + capitalize(messages[x].rule.message);
if(options.printElement && messages[x].element) {
output += '", "element": "' + messages[x].element;
}
output+= '" }';
if (x < (len - 1)) {
output += ',';
}
}
output += ']}';
return output;
}
};
}());