-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
30 lines (26 loc) · 869 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
var level = require('level')
var hypercore = require('hypercore')
var createImportPipeline = require('./lib/import.js')
module.exports = Jawn
function Jawn (opts) {
if (!opts) opts = {}
this.core = initializeHypercore(opts)
this.db = this.core.db
}
Jawn.prototype.createImportPipeline = function (opts) {
return createImportPipeline(this, opts)
}
// Initializes hypercore and its database
// @default Creates a leveldb database called `data.jawn` and initializes hypercore using that db
// @option 'core' the hypercore instance to use
// @option 'db' the db instace (leveldb) to initialize hypercore with. This is ignored if you use the `core` option
function initializeHypercore (opts) {
var core
if (opts.hasOwnProperty('core')) {
core = opts.core
} else {
var db = opts.db || level('data.jawn')
core = hypercore(db)
}
return core
}