Skip to content

Commit

Permalink
Breaking: modernize syntax (Level/community#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Apr 24, 2021
1 parent a59494a commit 32c5d60
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ updates:
interval: monthly
ignore:
- dependency-name: dependency-check
- dependency-name: standard
- package-ecosystem: github-actions
directory: /
schedule:
Expand Down
20 changes: 9 additions & 11 deletions compose.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'

var xtend = require('xtend')

module.exports = function compose () {
var layers = []
const layers = []

function shell (location, options, callback) {
if (typeof location === 'function') {
Expand Down Expand Up @@ -34,7 +32,7 @@ module.exports = function compose () {
// If db is levelup, it will auto-open and call the callback. If
// abstract-leveldown, it won't. If abstract-db (a concept), it might.
if (callback && !isLevelup(db) && db.status === 'new') {
db.open(xtend(layer.defaults, options), function (err) {
db.open(Object.assign({}, layer.defaults, options), function (err) {
if (err) return callback(err)
callback(null, db)
})
Expand All @@ -47,16 +45,16 @@ module.exports = function compose () {

shell.use = function (layer, defaults) {
if (Array.isArray(layer)) {
for (var i = 0; i < layer.length; i++) {
shell.use(layer[i], xtend(isOpts(layer[i + 1]) && layer[++i], defaults))
for (let i = 0; i < layer.length; i++) {
shell.use(layer[i], Object.assign({}, isOpts(layer[i + 1]) && layer[++i], defaults))
}

return shell
}

layers.push(function wrapped (db, options, callback) {
wrapped.defaults = defaults
return layer(db, xtend(defaults, options), callback)
return layer(db, Object.assign({}, defaults, options), callback)
})

decorate(shell, layer)
Expand All @@ -75,13 +73,13 @@ function decorate (shell, nut) {
shell.errors = nut.errors
}

['destroy', 'repair'].forEach(function (m) {
for (const m of ['destroy', 'repair']) {
if (typeof nut[m] === 'function') {
shell[m] = function () {
nut[m].apply(nut, arguments)
shell[m] = function (...args) {
nut[m](...args)
}
}
})
}
}

function isLevelup (db) {
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
"CONTRIBUTORS.md",
"UPGRADING.md"
],
"dependencies": {
"xtend": "~4.0.1"
},
"dependencies": {},
"devDependencies": {
"dependency-check": "^3.3.0",
"encoding-down": "^6.0.2",
"hallmark": "^3.1.0",
"level-community": "^3.0.0",
"levelup": "^4.0.1",
"nyc": "^15.0.0",
"standard": "^14.0.0",
"standard": "^16.0.3",
"tape": "^5.0.1"
},
"hallmark": {
Expand Down
16 changes: 8 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'

var test = require('tape')
var encode = require('encoding-down')
var levelup = require('levelup')
var compose = require('.')
const test = require('tape')
const encode = require('encoding-down')
const levelup = require('levelup')
const compose = require('.')

var packager = function (down) {
const packager = function (down) {
return compose(down, encode, levelup)
}

Expand Down Expand Up @@ -49,7 +49,7 @@ test('packager - Level constructor with default options', function (t) {
open: function (opts, cb) {}
}
}
var levelup = packager(Down)('location')
const levelup = packager(Down)('location')

// In level-packager, this works because encoding-down mutates the shared
// options object. That level-packager test should be updated.
Expand Down Expand Up @@ -79,13 +79,13 @@ test('packager - Level constructor with callback', function (t) {

test('packager - Level constructor with custom options', function (t) {
t.plan(3)
var Down = function (location) {
const Down = function (location) {
t.is(location, 'location', 'location is correct')
return {
open: function (opts, cb) {}
}
}
var levelup = packager(Down)('location', {
const levelup = packager(Down)('location', {
keyEncoding: 'binary',
valueEncoding: 'binary'
})
Expand Down

0 comments on commit 32c5d60

Please sign in to comment.