Skip to content

Commit

Permalink
Breaking: modernize syntax and bump standard
Browse files Browse the repository at this point in the history
Drops support of node 6, node 8 and old browsers.

Ref Level/community#98
  • Loading branch information
vweevers committed Apr 8, 2021
1 parent 7e7692a commit 5d7cc6d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 45 deletions.
7 changes: 7 additions & 0 deletions .airtap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
providers:
- airtap-playwright

browsers:
- name: chromium
- name: firefox
- name: webkit
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: node_js

node_js:
- 6
- 8
- 10
- 12
- 14

after_success: npm run coverage
12 changes: 4 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
'use strict'

// For (old) browser support
var xtend = require('xtend')
var assign = require('xtend/mutable')
module.exports = function supports (...manifests) {
const manifest = manifests.reduce((acc, m) => Object.assign(acc, m), {})

module.exports = function supports () {
var manifest = xtend.apply(null, arguments)

return assign(manifest, {
return Object.assign(manifest, {
// Features of abstract-leveldown
bufferKeys: manifest.bufferKeys || false,
snapshots: manifest.snapshots || false,
Expand All @@ -30,6 +26,6 @@ module.exports = function supports () {
encodings: manifest.encodings || false,

// Methods that are not part of abstract-leveldown or levelup
additionalMethods: xtend(manifest.additionalMethods)
additionalMethods: Object.assign({}, manifest.additionalMethods)
})
}
18 changes: 7 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,26 @@
"license": "MIT",
"scripts": {
"test": "standard && hallmark && (nyc -s node test/self.js | faucet) && nyc report",
"test-browser-local": "airtap --coverage --local test/self.js",
"test-browsers-local": "airtap --coverage test/self.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"hallmark": "hallmark --fix",
"dependency-check": "dependency-check --no-dev . test/*.js",
"prepublishOnly": "npm run dependency-check"
"hallmark": "hallmark --fix"
},
"files": [
"test",
"CHANGELOG.md",
"CONTRIBUTORS.md",
"index.js"
],
"dependencies": {
"xtend": "^4.0.2"
},
"dependencies": {},
"devDependencies": {
"airtap": "^3.0.0",
"airtap": "^4.0.3",
"airtap-playwright": "^1.0.1",
"coveralls": "^3.0.6",
"dependency-check": "^4.1.0",
"faucet": "^0.0.1",
"hallmark": "^3.1.0",
"level-community": "^3.0.0",
"nyc": "^14.1.1",
"standard": "^14.3.1",
"standard": "^16.0.3",
"tape": "^5.0.1"
},
"hallmark": {
Expand All @@ -48,6 +44,6 @@
"manifest"
],
"engines": {
"node": ">=6"
"node": ">=10"
}
}
4 changes: 2 additions & 2 deletions test/cloneable.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict'

var supports = require('..')
const supports = require('..')

// Every object in a manifest must have a unique identity, to avoid accidental
// mutation. In supports() we only shallowly clone the manifest object itself
// and additionalMethods. If in the future we add more objects to manifests,
// this test will break and we'll know to start performing a deep clone.
module.exports = function cloneable (t, manifest) {
var copy = supports(manifest)
const copy = supports(manifest)
verifyUnique(t, 'manifest', manifest, copy)
}

Expand Down
13 changes: 6 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
'use strict'

var xtend = require('xtend')
var shape = require('./shape')
var cloneable = require('./cloneable')
const shape = require('./shape')
const cloneable = require('./cloneable')

module.exports = function suite (test, testCommon) {
test('db has manifest', function (t) {
var db = testCommon.factory()
var manifest = db.supports
const db = testCommon.factory()
const manifest = db.supports

shape(t, manifest)
cloneable(t, manifest)

var before = xtend(manifest, {
additionalMethods: xtend(manifest.additionalMethods)
const before = Object.assign({}, manifest, {
additionalMethods: Object.assign({}, manifest.additionalMethods)
})

db.open(function (err) {
Expand Down
26 changes: 13 additions & 13 deletions test/self.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

var test = require('tape')
var supports = require('..')
var shape = require('./shape')
var cloneable = require('./cloneable')
const test = require('tape')
const supports = require('..')
const shape = require('./shape')
const cloneable = require('./cloneable')

test('no options', function (t) {
shape(t, supports())
Expand All @@ -13,7 +13,7 @@ test('no options', function (t) {

test('falsy options', function (t) {
;[null, false, undefined, 0, ''].forEach(function (value) {
var manifest = supports({
const manifest = supports({
bufferKeys: value,
additionalMethods: {
foo: value
Expand All @@ -29,7 +29,7 @@ test('falsy options', function (t) {

test('truthy options', function (t) {
;[true, {}, 'yes', 1, []].forEach(function (value) {
var manifest = supports({
const manifest = supports({
streams: value,
additionalMethods: {
foo: value
Expand All @@ -45,9 +45,9 @@ test('truthy options', function (t) {
})

test('merges input objects without mutating them', function (t) {
var input1 = { bufferKeys: null, streams: false }
var input2 = { streams: true, additionalMethods: {} }
var manifest = supports(input1, input2)
const input1 = { bufferKeys: null, streams: false }
const input2 = { streams: true, additionalMethods: {} }
const manifest = supports(input1, input2)

manifest.foobar = true
manifest.additionalMethods.baz = true
Expand All @@ -61,15 +61,15 @@ test('merges input objects without mutating them', function (t) {
})

test('inherits additionalMethods', function (t) {
var manifest = supports({ additionalMethods: { foo: true } }, {})
const manifest = supports({ additionalMethods: { foo: true } }, {})
t.same(manifest.additionalMethods, { foo: true })
t.end()
})

test('does not merge additionalMethods', function (t) {
var input1 = { additionalMethods: { foo: true } }
var input2 = { additionalMethods: { bar: true } }
var manifest = supports(input1, input2)
const input1 = { additionalMethods: { foo: true } }
const input2 = { additionalMethods: { bar: true } }
const manifest = supports(input1, input2)
t.same(manifest.additionalMethods, { bar: true })
t.end()
})
4 changes: 2 additions & 2 deletions test/shape.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

var hasOwnProperty = Object.prototype.hasOwnProperty
const hasOwnProperty = Object.prototype.hasOwnProperty

module.exports = function shape (t, manifest) {
t.ok(isObject(manifest), 'manifest is object')
t.ok(isObject(manifest.additionalMethods), 'additionalMethods is object')

for (var k in manifest) {
for (const k in manifest) {
if (!hasOwnProperty.call(manifest, k)) continue

if (manifest[k]) {
Expand Down

0 comments on commit 5d7cc6d

Please sign in to comment.