{"size": 946, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "GeoCoacher/gishub", "max_stars_repo_stars_event_min_datetime": "2016-03-15T20:03:27.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-13T12:49:02.000Z", "max_issues_repo_path": "index.js", "max_issues_repo_name": "GeoCoacher/gishub", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "GeoCoacher/gishub", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.6666666667, "max_line_length": 93, "alphanum_fraction": 0.6733615222}
var dat = require('dat-core')
var resolve = require('resolve')
var readConfig = require('./lib/util/config.js')

module.exports = Dat

function Dat (path, opts) {
  if (!opts) opts = {}
  if (!opts.valueEncoding) opts.valueEncoding = 'json'

  // prevent new repos from being created if someone runs a read-only dat command in a folder
  if (typeof opts.createIfMissing === 'undefined') opts.createIfMissing = false

  var config = readConfig({path: path})

  if (config.dat && config.dat.backend) {
    var res = resolve.sync(config.dat.backend.module, { basedir: process.cwd() })
    var addon = require(res)
    var env = process.env[config.dat.backend.env]
    opts.backend = function () {
      return addon(env)
    }
  }

  var db = dat(path, opts)

  // make sure this is not set by dat-core before we set it
  if (typeof db.config !== 'undefined') throw new Error('db should not have config set yet')
  db.config = config

  return db
}
