forked from AskUbuntu/ProFormaComments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.js
More file actions
22 lines (17 loc) · 776 Bytes
/
verify.js
File metadata and controls
22 lines (17 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* This relatively simple script loads the JSONP file
* from disk and attempts to verify the JSON. */
var fs = require('fs');
// Read the file's contents and attempt to extract the JSON from it.
fs.readFile('comments.jsonp', 'utf8', function(err, data) {
// First make sure the file exists.
if(err) throw err;
// Extract the JSON from it.
var json = data.match(/^callback\(([\S\s]*)\)\s*$/);
if(json === null) throw 'JSONP is malformed - unable to extract JSON data';
json = JSON.parse(json[1]);
// Verify the JSON data.
for(var i=0;i<json.length;++i) {
if(!'name' in json[i]) throw '"name" is missing from element';
if(!'description' in json[i]) throw '"description" is missing from element';
}
});