MCPcopy
hub / github.com/faressoft/terminalizer / loadJSON

Function loadJSON

utility.js:136–154  ·  view source on GitHub ↗

* Check, load, and parse JSON files * * - Add .json extension when needed * * Throws * - The provided file doesn't exit * - The provided file is not a valid JSON file * - Any reading errors * * @param {String} filePath an absolute or a relative path * @return {Object}

(filePath)

Source from the content-addressed store, hash-verified

134 * @return {Object}
135 */
136function loadJSON(filePath) {
137
138 var file = loadFile(filePath, 'json');
139
140 // Read the file
141 try {
142 file = di.fs.readFileSync(filePath);
143 } catch (error) {
144 throw new Error(error);
145 }
146
147 // Parse the file
148 try {
149 return JSON.parse(file);
150 } catch (error) {
151 throw new Error('The provided file is not a valid JSON file');
152 }
153
154}
155
156/**
157 * Resolve to an absolute path

Callers

nothing calls this directly

Calls 1

loadFileFunction · 0.85

Tested by

no test coverage detected