Skip to content

Commit 780f619

Browse files
author
Matt Zumwalt
committed
Cleaner initialization of hypercore
1 parent b2da350 commit 780f619

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

index.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,25 @@ module.exports = Jawn
66

77
function Jawn (opts) {
88
if (!opts) opts = {}
9-
var db = opts.db || level('data.jawn')
10-
this.core = opts.core || hypercore(db)
9+
this.core = initializeHypercore(opts)
1110
this.db = this.core.db
1211
}
1312

1413
Jawn.prototype.createImportPipeline = function (opts) {
1514
return createImportPipeline(this, opts)
1615
}
16+
17+
// Initializes hypercore and its database
18+
// @default Creates a leveldb database called `data.jawn` and initializes hypercore using that db
19+
// @option 'core' the hypercore instance to use
20+
// @option 'db' the db instace (leveldb) to initialize hypercore with. This is ignored if you use the `core` option
21+
function initializeHypercore (opts) {
22+
var core
23+
if (opts.hasOwnProperty('core')) {
24+
core = opts.core
25+
} else {
26+
var db = opts.db || level('data.jawn')
27+
core = hypercore(db)
28+
}
29+
return core
30+
}

0 commit comments

Comments
 (0)