UNPKG

ae-biu

Version:

Born For AE, Born To Do

34 lines (29 loc) 684 B
// @flow import fs from 'fs' import { promisify } from 'util' export const readJSONFile = async (file: string): Promise<Object> => { if (!file) { throw new Error('Invalid File Path') } try { const fileContent = await promisify(fs.readFile)(file, 'utf8') if (!fileContent) { return {} } try { const data = JSON.parse(fileContent) return data } catch (error) { throw error } } catch (error) { throw error } } export const readJSONFileSync = (file: string): Object => { if (!file) { throw new Error('Invalid File Path') } const fileContent = fs.readFileSync(file, 'utf8') return JSON.parse(fileContent) }