forked from dat-ecosystem/dat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (35 loc) · 882 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var path = require('path')
var meta = require(path.join(__dirname, 'lib', 'meta.js'))
module.exports = Dat
// new Dat(cb)
// new Dat({foo: bar})
// new Dat({foo: bar}, cb)
// new Dat('./foo)
// new Dat('./foo', cb)
// new Dat('./foo', {foo: bar})
// new Dat('./foo', {foo: bar}, cb)
function Dat(dir, opts, onReady) {
var self = this
// if 'new' was not used
if (!(this instanceof Dat)) return new Dat(dir, opts)
if (typeof dir === 'function') {
onReady = dir
opts = {}
dir = process.cwd()
}
if (typeof opts === 'function') {
onReady = opts
opts = {}
}
if (typeof dir === 'object') {
onReady = opts
opts = dir
dir = process.cwd()
}
this.dir = dir
this.opts = opts
this.meta = meta(this.dir, function(err) {
if (onReady) onReady(err)
})
}
Dat.prototype = require(path.join(__dirname, 'lib', 'commands'))