Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@aretecode/flipfile / src / read.ts
Size: Mime:
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))
}