From 4770d1740c73a2e04056b027d6c31364b3322d72 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sat, 17 Apr 2021 12:06:01 +0200 Subject: [PATCH] Breaking: modernize syntax and bump standard (Level/community#98) --- .github/dependabot.yml | 1 - abstract/base-test.js | 12 +++++------ abstract/db-values-test.js | 22 +++++++++++---------- abstract/destroy-test.js | 6 +++--- abstract/error-if-exists-test.js | 2 +- abstract/location.js | 4 +++- abstract/repair-test.js | 2 +- level-packager.js | 14 +++++++------ package.json | 2 +- test.js | 34 ++++++++++++++++---------------- 10 files changed, 52 insertions(+), 47 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0482d96..d3ed65b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,4 +7,3 @@ updates: ignore: - dependency-name: dependency-check - dependency-name: nyc - - dependency-name: standard diff --git a/abstract/base-test.js b/abstract/base-test.js index 79fc6ca..7e1b921 100644 --- a/abstract/base-test.js +++ b/abstract/base-test.js @@ -1,6 +1,6 @@ 'use strict' -var location = require('./location') +const location = require('./location') module.exports = function (test, level) { test('test db open and use, level(location, cb)', function (t) { @@ -24,7 +24,7 @@ module.exports = function (test, level) { }) test('test db open and use, db=level(location)', function (t) { - var db = level(location) + const db = level(location) db.put('test3', 'success', function (err) { t.notOk(err, 'no error') db.close(t.end.bind(t)) @@ -32,9 +32,9 @@ module.exports = function (test, level) { }) test('options.keyEncoding and options.valueEncoding are passed on to encoding-down', function (t) { - var db = level(location, { keyEncoding: 'json', valueEncoding: 'json' }) + const db = level(location, { keyEncoding: 'json', valueEncoding: 'json' }) db.on('ready', function () { - var codec = db.db.codec + const codec = db.db.codec t.equal(codec.opts.keyEncoding, 'json', 'keyEncoding correct') t.equal(codec.opts.valueEncoding, 'json', 'valueEncoding correct') db.close(t.end.bind(t)) @@ -42,9 +42,9 @@ module.exports = function (test, level) { }) test('encoding options default to utf8', function (t) { - var db = level(location) + const db = level(location) db.on('ready', function () { - var codec = db.db.codec + const codec = db.db.codec t.equal(codec.opts.keyEncoding, 'utf8', 'keyEncoding correct') t.equal(codec.opts.valueEncoding, 'utf8', 'valueEncoding correct') db.close(t.end.bind(t)) diff --git a/abstract/db-values-test.js b/abstract/db-values-test.js index 1c07677..9b4bb71 100644 --- a/abstract/db-values-test.js +++ b/abstract/db-values-test.js @@ -1,18 +1,20 @@ 'use strict' -var location = require('./location') +const location = require('./location') module.exports = function (test, level, nonPersistent) { test('test db values', function (t) { - var c = 0 - var db = level(location) - var setup = nonPersistent ? function (callback) { - db.batch([ - { type: 'put', key: 'test1', value: 'success' }, - { type: 'put', key: 'test2', value: 'success' }, - { type: 'put', key: 'test3', value: 'success' } - ], callback) - } : function (callback) { callback() } + let c = 0 + const db = level(location) + const setup = nonPersistent + ? function (callback) { + db.batch([ + { type: 'put', key: 'test1', value: 'success' }, + { type: 'put', key: 'test2', value: 'success' }, + { type: 'put', key: 'test3', value: 'success' } + ], callback) + } + : function (callback) { callback() } function read (err, value) { t.notOk(err, 'no error') diff --git a/abstract/destroy-test.js b/abstract/destroy-test.js index 36dc9e7..f8646f3 100644 --- a/abstract/destroy-test.js +++ b/abstract/destroy-test.js @@ -1,8 +1,8 @@ 'use strict' -var fs = require('fs') -var path = require('path') -var location = require('./location') +const fs = require('fs') +const path = require('path') +const location = require('./location') module.exports = function (test, level) { test('test destroy', function (t) { diff --git a/abstract/error-if-exists-test.js b/abstract/error-if-exists-test.js index 56c7e17..8406cc7 100644 --- a/abstract/error-if-exists-test.js +++ b/abstract/error-if-exists-test.js @@ -1,6 +1,6 @@ 'use strict' -var location = require('./location') +const location = require('./location') module.exports = function (test, level) { test('test db open and use, level(location, options, cb) force error', function (t) { diff --git a/abstract/location.js b/abstract/location.js index 8c1a2a5..8d6fb47 100644 --- a/abstract/location.js +++ b/abstract/location.js @@ -1,3 +1,5 @@ -var path = require('path') +'use strict' + +const path = require('path') module.exports = path.join(__dirname, 'level-test-' + process.pid + '.db') diff --git a/abstract/repair-test.js b/abstract/repair-test.js index 30bbc74..560312e 100644 --- a/abstract/repair-test.js +++ b/abstract/repair-test.js @@ -1,6 +1,6 @@ 'use strict' -var location = require('./location') +const location = require('./location') module.exports = function (test, level) { test('test repair', function (t) { diff --git a/level-packager.js b/level-packager.js index afdbfed..dbb4186 100644 --- a/level-packager.js +++ b/level-packager.js @@ -1,5 +1,7 @@ -var levelup = require('levelup') -var encode = require('encoding-down') +'use strict' + +const levelup = require('levelup') +const encode = require('encoding-down') function packager (leveldown) { function Level (location, options, callback) { @@ -20,13 +22,13 @@ function packager (leveldown) { return typeof o === 'object' && o !== null } - ['destroy', 'repair'].forEach(function (m) { + for (const m of ['destroy', 'repair']) { if (typeof leveldown[m] === 'function') { - Level[m] = function () { - leveldown[m].apply(leveldown, arguments) + Level[m] = function (...args) { + leveldown[m](...args) } } - }) + } Level.errors = levelup.errors diff --git a/package.json b/package.json index 50444f5..8f7903b 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "hallmark": "^3.1.0", "level-community": "^3.0.0", "nyc": "^14.0.0", - "standard": "^14.0.0", + "standard": "^16.0.3", "tape": "^5.0.1" }, "hallmark": { diff --git a/test.js b/test.js index 7e108c5..3c5180e 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,7 @@ 'use strict' -var test = require('tape') -var packager = require('.') +const test = require('tape') +const packager = require('.') test('Level constructor has access to levelup errors', function (t) { function Down () {} @@ -18,16 +18,16 @@ test('Level constructor relays .destroy and .repair if they exist', function (t) function test (method) { function Down () {} - Down[method] = function () { - t.same([].slice.call(arguments), args, 'supports variadic arguments') + Down[method] = function (...actual) { + t.same(actual, expected, 'supports variadic arguments') } - var level = packager(Down) - var args = [] + const level = packager(Down) + const expected = [] - for (var i = 0; i < 4; i++) { - args.push(i) - level[method].apply(level, args) + for (let i = 0; i < 4; i++) { + expected.push(i) + level[method](...expected) } } }) @@ -48,7 +48,7 @@ test('Level constructor', function (t) { } } } - var levelup = packager(Down)() + const levelup = packager(Down)() t.is(levelup.options.keyEncoding, 'utf8') t.is(levelup.options.valueEncoding, 'utf8') }) @@ -68,7 +68,7 @@ test('Level constructor with location', function (t) { } } } - var levelup = packager(Down)('location') + const levelup = packager(Down)('location') t.is(levelup.options.keyEncoding, 'utf8') t.is(levelup.options.valueEncoding, 'utf8') }) @@ -134,7 +134,7 @@ test('Level constructor with location & callback', function (t) { test('Level constructor with location & options passed to levelup', function (t) { t.plan(4) - var Down = function (location) { + const Down = function (location) { t.is(location, 'location', 'location is correct') return { open: function (opts, cb) { @@ -147,7 +147,7 @@ test('Level constructor with location & options passed to levelup', function (t) } } } - var levelup = packager(Down)('location', { + const levelup = packager(Down)('location', { keyEncoding: 'binary', valueEncoding: 'binary' }) @@ -157,7 +157,7 @@ test('Level constructor with location & options passed to levelup', function (t) test('Level constructor with options passed to levelup', function (t) { t.plan(3) - var Down = function () { + const Down = function () { return { open: function (opts, cb) { t.same(opts, { @@ -169,7 +169,7 @@ test('Level constructor with options passed to levelup', function (t) { } } } - var levelup = packager(Down)({ + const levelup = packager(Down)({ keyEncoding: 'binary', valueEncoding: 'binary' }) @@ -179,7 +179,7 @@ test('Level constructor with options passed to levelup', function (t) { test('Level constructor with options & callback passed to levelup', function (t) { t.plan(5) - var Down = function () { + const Down = function () { return { open: function (opts, cb) { t.same(opts, { @@ -192,7 +192,7 @@ test('Level constructor with options & callback passed to levelup', function (t) } } } - var levelup = packager(Down)({ + const levelup = packager(Down)({ keyEncoding: 'binary', valueEncoding: 'binary' }, function (err, db) {