import fs from 'fs' ; async function fsReadFileAsync ( pathname , encoding ) { return new Promise ( ( resolve , reject ) : void => { fs . readFile ( pathname , encoding , ( error , contents ) : void => { if ( error ) { reject ( error ) ; return ; } resolve ( contents ) ; } ) ; } ) ; } interface Options { throwNotFound ? : boolean ; } async function readFile ( filepath , options = { } ) { const throwNotFound = options . throwNotFound === true ; try { const content = await fsReadFileAsync ( filepath , 'utf8' ) ; return content ; } catch ( error ) { if ( throwNotFound === false && ( error . code === 'ENOENT' || error . code === 'EISDIR' ) ) { return null ; } throw error ; } } function readFileSync ( filepath , options = { } ) { const throwNotFound = options . throwNotFound === true ; try { const content = fs . readFileSync ( filepath , 'utf8' ) ; return content ; } catch ( error ) { if ( throwNotFound === false && ( error . code === 'ENOENT' || error . code === 'EISDIR' ) ) { return null ; } throw error ; } } export { readFile , readFileSync } ;