* 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)
| 134 | * @return {Object} |
| 135 | */ |
| 136 | function 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 |
nothing calls this directly
no test coverage detected