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

Function loadFile

utility.js:67–88  ·  view source on GitHub ↗

* Load a file's content * * - Check if the file exists, if not found check * if the file exists with appending the extension * * Throws * - The provided file doesn't exit * - Any reading errors * * @param {String} filePath an absolute or a relative path * @param {String} extension *

(filePath, extension)

Source from the content-addressed store, hash-verified

65 * @return {String}
66 */
67function loadFile(filePath, extension) {
68
69 var content = null;
70
71 // Resolve the path into an absolute path
72 filePath = resolveFilePath(filePath, extension);
73
74 // The file doesn't exist
75 if (!isFile(filePath)) {
76 throw new Error('The provided file doesn\'t exit');
77 }
78
79 // Read the file
80 try {
81 content = di.fs.readFileSync(filePath);
82 } catch (error) {
83 throw new Error(error);
84 }
85
86 return content;
87
88}
89
90/**
91 * Check, load, and parse YAML files

Callers 2

loadYAMLFunction · 0.85
loadJSONFunction · 0.85

Calls 2

resolveFilePathFunction · 0.85
isFileFunction · 0.85

Tested by

no test coverage detected