Repository URL to install this package:
|
Version:
1.0.2 ▾
|
import { readFileSync } from 'fs'
/**
* @see http://stackabuse.com/read-files-with-node-js/
*/
export function read(dir: string) {
// try {
// // if (!dir) warn
// // isAbsolute(dir)
// // var resolved = helpers.resolve(dir)
// } catch (exception) {
// // ignored
// }
return readFileSync(dir, 'utf8')
}
export function tryJSON(json: string) {
try {
const parsed = JSON.parse(json)
return parsed
} catch (parseException) {
return false
}
}
export function readJSON(dir: string) {
return tryJSON(read(dir))
}