Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Commit 0bd41cc

Browse files
committed
Modernize syntax and bump standard
1 parent f7ee1e3 commit 0bd41cc

4 files changed

Lines changed: 121 additions & 121 deletions

File tree

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var subdown = require('./leveldown')
2-
var levelup = require('levelup')
3-
var encoding = require('encoding-down')
1+
const subdown = require('./leveldown')
2+
const levelup = require('levelup')
3+
const encoding = require('encoding-down')
44

55
module.exports = function (db, prefix, opts) {
66
if (typeof prefix === 'object' && !opts) return module.exports(db, null, prefix)

leveldown.js

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var inherits = require('inherits')
2-
var abstract = require('abstract-leveldown')
3-
var wrap = require('level-option-wrap')
4-
var reachdown = require('reachdown')
5-
var matchdown = require('./matchdown')
1+
const inherits = require('inherits')
2+
const abstract = require('abstract-leveldown')
3+
const wrap = require('level-option-wrap')
4+
const reachdown = require('reachdown')
5+
const matchdown = require('./matchdown')
66

7-
var rangeOptions = 'start end gt gte lt lte'.split(' ')
8-
var defaultClear = abstract.AbstractLevelDOWN.prototype._clear
9-
var hasOwnProperty = Object.prototype.hasOwnProperty
7+
const rangeOptions = 'start end gt gte lt lte'.split(' ')
8+
const defaultClear = abstract.AbstractLevelDOWN.prototype._clear
9+
const hasOwnProperty = Object.prototype.hasOwnProperty
1010

1111
function concat (prefix, key, force) {
1212
if (typeof key === 'string' && (force || key.length)) return prefix + key
@@ -28,10 +28,9 @@ inherits(SubIterator, abstract.AbstractIterator)
2828
SubIterator.prototype._next = function (cb) {
2929
if (maybeError(this.db.leveldown, cb)) return
3030

31-
var self = this
32-
this.iterator.next(function (err, key, value) {
31+
this.iterator.next((err, key, value) => {
3332
if (err) return cb(err)
34-
if (key) key = key.slice(self.prefix.length)
33+
if (key) key = key.slice(this.prefix.length)
3534
cb(err, key, value)
3635
})
3736
}
@@ -50,15 +49,15 @@ function SubDown (db, prefix, opts) {
5049
if (typeof opts === 'string') opts = { separator: opts }
5150
if (!opts) opts = {}
5251

53-
var separator = opts.separator
52+
let separator = opts.separator
5453

5554
if (!prefix) prefix = ''
5655
if (!separator) separator = '!'
5756
if (prefix[0] === separator) prefix = prefix.slice(1)
5857
if (prefix[prefix.length - 1] === separator) prefix = prefix.slice(0, -1)
5958

60-
var code = separator.charCodeAt(0) + 1
61-
var ceiling = String.fromCharCode(code)
59+
const code = separator.charCodeAt(0) + 1
60+
const ceiling = String.fromCharCode(code)
6261

6362
Buffer.from(prefix).forEach(function (byte) {
6463
if (byte <= code) {
@@ -70,16 +69,15 @@ function SubDown (db, prefix, opts) {
7069
this.prefix = separator + prefix + separator
7170
this._beforeOpen = opts.open
7271

73-
var self = this
74-
var manifest = db.supports || {}
72+
let manifest = db.supports || {}
7573

7674
// The parent db must open itself or be (re)opened by the user because a
7775
// sublevel can't (shouldn't) initiate state changes on the rest of the db.
7876
if (!manifest.deferredOpen && !reachdown.is(db, 'levelup')) {
7977
throw new Error('Parent database must support deferredOpen')
8078
}
8179

82-
var subdb = reachdown(db, 'subleveldown')
80+
const subdb = reachdown(db, 'subleveldown')
8381

8482
if (subdb) {
8583
// Old subleveldown doesn't know its prefix and leveldown until opened
@@ -102,20 +100,22 @@ function SubDown (db, prefix, opts) {
102100
}
103101

104102
this._wrap = {
105-
gt: function (x) {
106-
return concat(self.prefix, x || '', true)
103+
gt: (x) => {
104+
return concat(this.prefix, x || '', true)
107105
},
108-
lt: function (x) {
106+
lt: (x) => {
109107
if (!x || isEmptyBuffer(x)) {
110-
return self.prefix.slice(0, -1) + ceiling
108+
return this.prefix.slice(0, -1) + ceiling
111109
} else {
112-
return concat(self.prefix, x)
110+
return concat(this.prefix, x)
113111
}
114112
}
115113
}
116114

117-
// Inherit manifest from parent db
118-
manifest = Object.assign({}, manifest, {
115+
manifest = {
116+
// Inherit manifest from parent db
117+
...manifest,
118+
119119
// Disable unsupported features
120120
getMany: false,
121121
keyIterator: false,
@@ -126,7 +126,7 @@ function SubDown (db, prefix, opts) {
126126
// Unset additional methods (like approximateSize) which we can't support
127127
// here and should typically be called on the underlying store instead.
128128
additionalMethods: {}
129-
})
129+
}
130130

131131
abstract.AbstractLevelDOWN.call(this, manifest)
132132
}
@@ -139,27 +139,25 @@ SubDown.prototype.type = 'subleveldown'
139139
// because that means we can always do operations on this.leveldown.
140140
// Alternatively have the sublevel follow the open state of this.db.
141141
SubDown.prototype._open = function (opts, cb) {
142-
var self = this
143-
144142
// TODO: make _isOpening public in levelup or add a method like
145143
// ready(cb) which waits for - but does not initiate - a state change.
146-
var m = typeof this.db.isOpening === 'function' ? 'isOpening' : '_isOpening'
147-
148-
if (this.db[m]()) {
149-
this.db.once('open', onopen)
150-
} else {
151-
this._nextTick(onopen)
152-
}
144+
const m = typeof this.db.isOpening === 'function' ? 'isOpening' : '_isOpening'
153145

154-
function onopen () {
155-
if (!self.db.isOpen()) return cb(new Error('Parent database is not open'))
156-
if (self.leveldown.status !== 'open') return cb(new Error('Inner database is not open'))
146+
const onopen = () => {
147+
if (!this.db.isOpen()) return cb(new Error('Parent database is not open'))
148+
if (this.leveldown.status !== 'open') return cb(new Error('Inner database is not open'))
157149

158150
// TODO: add hooks to abstract-leveldown
159-
if (self._beforeOpen) return self._beforeOpen(cb)
151+
if (this._beforeOpen) return this._beforeOpen(cb)
160152

161153
cb()
162154
}
155+
156+
if (this.db[m]()) {
157+
this.db.once('open', onopen)
158+
} else {
159+
this._nextTick(onopen)
160+
}
163161
}
164162

165163
SubDown.prototype._serializeKey = function (key) {
@@ -185,7 +183,7 @@ SubDown.prototype._batch = function (operations, opts, cb) {
185183
if (maybeError(this.leveldown, cb)) return
186184

187185
// No need to make a copy of the array, abstract-leveldown does that
188-
for (var i = 0; i < operations.length; i++) {
186+
for (let i = 0; i < operations.length; i++) {
189187
operations[i].key = concat(this.prefix, operations[i].key)
190188
}
191189

@@ -206,7 +204,7 @@ SubDown.prototype._clear = function (opts, cb) {
206204
}
207205

208206
function addRestOptions (target, opts) {
209-
for (var k in opts) {
207+
for (const k in opts) {
210208
if (hasOwnProperty.call(opts, k) && !isRangeOption(k)) {
211209
target[k] = opts[k]
212210
}
@@ -260,7 +258,7 @@ function fixRange (opts) {
260258
}
261259

262260
SubDown.prototype._iterator = function (opts) {
263-
var xopts = extend(wrap(fixRange(opts), this._wrap), opts)
261+
const xopts = extend(wrap(fixRange(opts), this._wrap), opts)
264262
return new SubIterator(this, this.leveldown.iterator(xopts), this.prefix)
265263
}
266264

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"level-concat-iterator": "^3.0.0",
3333
"memdown": "^5.0.0",
3434
"nyc": "^14.0.0",
35-
"standard": "^14.0.0",
35+
"standard": "^16.0.3",
3636
"tape": "^5.0.1"
3737
},
3838
"hallmark": {

0 commit comments

Comments
 (0)