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

Commit

Permalink
Breaking: modernize syntax and bump standard (Level/community#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Apr 9, 2021
1 parent 6677358 commit 404f20f
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 95 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ updates:
ignore:
- dependency-name: dependency-check
- dependency-name: nyc
- dependency-name: standard
41 changes: 22 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
'use strict'

var AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
var AbstractChainedBatch = require('abstract-leveldown').AbstractChainedBatch
var AbstractIterator = require('abstract-leveldown').AbstractIterator
var inherits = require('inherits')
var Codec = require('level-codec')
var EncodingError = require('level-errors').EncodingError
var rangeMethods = ['approximateSize', 'compactRange']
const AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
const AbstractChainedBatch = require('abstract-leveldown').AbstractChainedBatch
const AbstractIterator = require('abstract-leveldown').AbstractIterator
const inherits = require('inherits')
const Codec = require('level-codec')
const EncodingError = require('level-errors').EncodingError
const rangeMethods = ['approximateSize', 'compactRange']

module.exports = DB.default = DB

function DB (db, opts) {
if (!(this instanceof DB)) return new DB(db, opts)

var manifest = db.supports || {}
var additionalMethods = manifest.additionalMethods || {}
const manifest = db.supports || {}
const additionalMethods = manifest.additionalMethods || {}

AbstractLevelDOWN.call(this, manifest)

Expand All @@ -23,7 +23,7 @@ function DB (db, opts) {

rangeMethods.forEach(function (m) {
// TODO (future major): remove this fallback
var fallback = typeof db[m] === 'function'
const fallback = typeof db[m] === 'function'

if (additionalMethods[m] || fallback) {
this.supports.additionalMethods[m] = true
Expand Down Expand Up @@ -68,16 +68,18 @@ DB.prototype._put = function (key, value, opts, cb) {
}

DB.prototype._get = function (key, opts, cb) {
var self = this
key = this.codec.encodeKey(key, opts)
opts.asBuffer = this.codec.valueAsBuffer(opts)
this.db.get(key, opts, function (err, value) {

this.db.get(key, opts, (err, value) => {
if (err) return cb(err)

try {
value = self.codec.decodeValue(value, opts)
value = this.codec.decodeValue(value, opts)
} catch (err) {
return cb(new EncodingError(err))
}

cb(null, value)
})
}
Expand Down Expand Up @@ -119,24 +121,25 @@ function Iterator (db, opts) {
inherits(Iterator, AbstractIterator)

Iterator.prototype._next = function (cb) {
var self = this
this.it.next(function (err, key, value) {
this.it.next((err, key, value) => {
if (err) return cb(err)

try {
if (self.keys && typeof key !== 'undefined') {
key = self.codec.decodeKey(key, self.opts)
if (this.keys && typeof key !== 'undefined') {
key = this.codec.decodeKey(key, this.opts)
} else {
key = undefined
}

if (self.values && typeof value !== 'undefined') {
value = self.codec.decodeValue(value, self.opts)
if (this.values && typeof value !== 'undefined') {
value = this.codec.decodeValue(value, this.opts)
} else {
value = undefined
}
} catch (err) {
return cb(new EncodingError(err))
}

cb(null, key, value)
})
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"memdown": "^5.0.0",
"nyc": "^14.0.0",
"safe-buffer": "^5.1.1",
"standard": "^14.0.0",
"standard": "^16.0.3",
"tape": "^5.0.1"
},
"hallmark": {
Expand Down
Loading

0 comments on commit 404f20f

Please sign in to comment.