From 32c5d60413b2f10b1b9d83c6d4725137ae18ae26 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sat, 24 Apr 2021 20:05:30 +0200 Subject: [PATCH] Breaking: modernize syntax (Level/community#98) --- .github/dependabot.yml | 1 - compose.js | 20 +++++++++----------- package.json | 6 ++---- test.js | 16 ++++++++-------- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 941f1dd..6f12a34 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,7 +6,6 @@ updates: interval: monthly ignore: - dependency-name: dependency-check - - dependency-name: standard - package-ecosystem: github-actions directory: / schedule: diff --git a/compose.js b/compose.js index bd9c989..85e20da 100644 --- a/compose.js +++ b/compose.js @@ -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') { @@ -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) }) @@ -47,8 +45,8 @@ 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 @@ -56,7 +54,7 @@ module.exports = function compose () { 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) @@ -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) { diff --git a/package.json b/package.json index ce5bbb3..6b94344 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,7 @@ "CONTRIBUTORS.md", "UPGRADING.md" ], - "dependencies": { - "xtend": "~4.0.1" - }, + "dependencies": {}, "devDependencies": { "dependency-check": "^3.3.0", "encoding-down": "^6.0.2", @@ -27,7 +25,7 @@ "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": { diff --git a/test.js b/test.js index 6fb62dc..16e40fd 100644 --- a/test.js +++ b/test.js @@ -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) } @@ -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. @@ -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' })