MCPcopy
hub / github.com/MagicMirrorOrg/MagicMirror / loadJSON

Function loadJSON

js/translator.js:10–24  ·  view source on GitHub ↗

* Load a JSON file via fetch. * @param {string} file Path of the file we want to load. * @returns {Promise } the translations in the specified file

(file)

Source from the content-addressed store, hash-verified

8 * @returns {Promise<object>} the translations in the specified file
9 */
10 async function loadJSON (file) {
11 const baseHref = document.baseURI;
12 const url = new URL(file, baseHref);
13
14 try {
15 const response = await fetch(url);
16 if (!response.ok) {
17 throw new Error(`Unexpected response status: ${response.status}`);
18 }
19 return await response.json();
20 } catch {
21 Log.error(`Loading json file =${file} failed`);
22 return null;
23 }
24 }
25
26 return {
27 coreTranslations: {},

Callers 3

loadFunction · 0.85
loadCoreTranslationsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected