-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilityModule.js
More file actions
42 lines (36 loc) · 1.06 KB
/
Copy pathUtilityModule.js
File metadata and controls
42 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
const fs = require('fs');
module.exports = {
generateSpaces,
parseJSONFile
};
/** This function will return a string will a number of "big spaces" (five simple spaces). The function will be used for indentation
* @param {Integer} nrBigSpaces
* @returns {String}
* @public
*/
function generateSpaces(nrBigSpaces) {
let text = '';
for (var i = 0; i < nrBigSpaces; i++)
text += ' ';
return text;
}
/** This function will read a JSON from a file and also will show an error message when it won't be able to read the JSON
* @param {String} path This will be the path to the JSON file
* @returns {JSON}
* @public
*/
function parseJSONFile( path ) {
let rawData = fs.readFileSync( path );
if(typeof rawData === 'undefined'){
console.log('I cannot find this file: ' + path);
}
let modelData;
try{
modelData = JSON.parse( rawData );
}catch( e )
{
console.log( e );
}
console.log( modelData );
return modelData;
}