import {readFileSync} from 'fs'; import formatProperty from './format-property'; import {FileConfig, PropertyResult} from './types'; function tryToReadFile( propertyConfig: FileConfig, ): PropertyResult { const {encoding = 'utf8', filePath} = propertyConfig; try { return {error: false, value: readFileSync(filePath, encoding)}; } catch (error) { return {error: error as Error, value: undefined}; } } export default function loadFilePropertySync( propertyConfig: FileConfig, ): PropertyResult { return formatProperty(tryToReadFile(propertyConfig), propertyConfig); }