UNPKG

xeira

Version:

One Web Dev stack tool to rule them all

30 lines (26 loc) 674 B
import fsPromises from 'fs/promises' import {readFileSync} from 'fs' import { log_error } from './log.mjs' async function readJsonFile(jsonPath) { try { const data = await fsPromises.readFile(jsonPath) const obj = JSON.parse(data) return obj } catch (err){ log_error(`readJsonFile${jsonPath}`, err) return {} } } function readJsonFileSync(jsonPath, silent= false) { try { const data = readFileSync(jsonPath, {encoding:'utf8', flag:'r'}) const obj = JSON.parse(data) return obj } catch (err){ if (!silent) { log_error(`readJsonFileSync${jsonPath}`, err) } return {} } } export {readJsonFile, readJsonFileSync}