diff --git a/README.md b/README.md index 49618b2..ac40eac 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ [![npm next](https://img.shields.io/npm/v/level-js/next.svg)](https://www.npmjs.com/package/level-js) [![Travis](https://secure.travis-ci.org/Level/level.js.svg?branch=master)](http://travis-ci.org/Level/level.js) [![npm](https://img.shields.io/npm/dm/level-js.svg)](https://www.npmjs.com/package/level-js) +[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) ## Background diff --git a/index.js b/index.js index 1c17ca5..5741d54 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +/* global indexedDB */ + 'use strict' module.exports = Level @@ -85,7 +87,7 @@ Level.prototype._get = function (key, options, callback) { }) } -Level.prototype._del = function(key, options, callback) { +Level.prototype._del = function (key, options, callback) { this.await(this.store('readwrite').delete(key), callback) } @@ -181,10 +183,10 @@ Level.destroy = function (db, callback) { location = db } var request = indexedDB.deleteDatabase(prefix + location) - request.onsuccess = function() { + request.onsuccess = function () { callback() } - request.onerror = function(err) { + request.onerror = function (err) { callback(err) } } diff --git a/iterator.js b/iterator.js index 4571a8e..51961f0 100644 --- a/iterator.js +++ b/iterator.js @@ -1,7 +1,9 @@ +/* global IDBKeyRange */ + 'use strict' var util = require('util') -var AbstractIterator = require('abstract-leveldown').AbstractIterator +var AbstractIterator = require('abstract-leveldown').AbstractIterator var ltgt = require('ltgt') var mixedToBuffer = require('./util/mixed-to-buffer') var setImmediate = require('./util/immediate') @@ -117,7 +119,7 @@ Iterator.prototype._next = function (callback) { var err = this._error this._error = null - setImmediate(function() { + setImmediate(function () { callback(err) }) } else if (this._cache.length > 0) { @@ -127,7 +129,7 @@ Iterator.prototype._next = function (callback) { if (this._keyAsBuffer) key = mixedToBuffer(key) if (this._valueAsBuffer) value = mixedToBuffer(value) - setImmediate(function() { + setImmediate(function () { callback(null, key, value) }) } else if (this._completed) { diff --git a/package.json b/package.json index a73e331..26014cc 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "leveldown/leveldb library for browsers using IndexedDB", "main": "index.js", "scripts": { - "test": "airtap --local --no-coverage test/index.js", - "test-browsers": "airtap --sauce-connect --loopback airtap.local --no-coverage test/index.js" + "test": "standard && airtap --local --no-coverage test/index.js", + "test-browsers": "standard && airtap --sauce-connect --loopback airtap.local --no-coverage test/index.js" }, "repository": { "type": "git", @@ -23,6 +23,7 @@ "encoding-down": "~5.0.2", "levelup": "~3.0.0", "pinkie": "~2.0.4", + "standard": "^11.0.1", "tape": "^4.0.0" }, "dependencies": { @@ -33,5 +34,10 @@ }, "browser": { "./util/immediate.js": "./util/immediate-browser.js" + }, + "standard": { + "ignore": [ + "test/util/idb-shim.js" + ] } } diff --git a/test/custom-test.js b/test/custom-test.js index ff69cef..eec8694 100644 --- a/test/custom-test.js +++ b/test/custom-test.js @@ -5,13 +5,13 @@ var levelup = require('levelup') module.exports = function (leveljs, test, testCommon) { test('setUp', testCommon.setUp) - test('buffer value', function(t) { + test('buffer value', function (t) { var level = leveljs(testCommon.location()) - level.open(function(err) { + level.open(function (err) { t.notOk(err, 'no error') level.put('key', Buffer.from('00ff', 'hex'), function (err) { t.notOk(err, 'no error') - level.get('key', function(err, value) { + level.get('key', function (err, value) { t.notOk(err, 'no error') t.ok(Buffer.isBuffer(value), 'is buffer') t.same(value, Buffer.from('00ff', 'hex')) @@ -89,7 +89,7 @@ module.exports = function (leveljs, test, testCommon) { // NOTE: in chrome (at least) indexeddb gets buggy if you try and destroy a db, // then create it again, then try and destroy it again. these avoid doing that - test('test levelup .destroy w/ string', function(t) { + test('test levelup .destroy w/ string', function (t) { var location = testCommon.location() var db = levelup(leveljs(location)) db.put('key', 'value', function (err) { @@ -112,7 +112,7 @@ module.exports = function (leveljs, test, testCommon) { }) }) - test('test levelup .destroy w/ db instance', function(t) { + test('test levelup .destroy w/ db instance', function (t) { var location = testCommon.location() var db = levelup(leveljs(location)) db.put('key', 'value', function (err) { diff --git a/test/structured-clone-test.js b/test/structured-clone-test.js index 5cede78..4e27ec3 100644 --- a/test/structured-clone-test.js +++ b/test/structured-clone-test.js @@ -1,6 +1,5 @@ 'use strict' -var levelup = require('levelup') var isDataCloneError = require('../util/is-data-clone-error') var bytes = [0, 127] @@ -27,8 +26,8 @@ var types = [ { type: '+Infinity', value: Infinity }, { type: '-Infinity', value: -Infinity }, { type: 'string', value: 'test' }, - { type: 'Boolean object', value: new Boolean(false) }, - { type: 'String object', value: new String('test') }, + { type: 'Boolean object', value: new Boolean(false) }, // eslint-disable-line + { type: 'String object', value: new String('test') }, // eslint-disable-line { type: 'Date', ctor: true, value: new Date() }, { type: 'RegExp', ctor: true, value: /r/g }, { type: 'Array', ctor: true, value: [0, null, undefined] }, @@ -59,9 +58,9 @@ var types = [ type: 'Map', ctor: true, allowFailure: true, - createValue: function (ctor) { + createValue: function (Constructor) { // Replacement for Map constructor arguments (for IE 11) - var value = new ctor() + var value = new Constructor() value.set('test', 123) return value }, @@ -73,9 +72,9 @@ var types = [ type: 'Set', ctor: true, allowFailure: true, - createValue: function (ctor) { + createValue: function (Constructor) { // Replacement for Set constructor arguments (for IE 11) - var value = new ctor() + var value = new Constructor() value.add(123) return value }, @@ -87,8 +86,8 @@ var types = [ type: 'Blob', ctor: true, allowFailure: true, - createValue: function (ctor) { - return new ctor(['test']) + createValue: function (Constructor) { + return new Constructor(['test']) }, test: function (value) { // TODO. This test would be asynchronous. @@ -99,8 +98,8 @@ var types = [ type: 'File', ctor: true, allowFailure: true, - createValue: function (ctor) { - return new ctor(['test'], 'filename') + createValue: function (Constructor) { + return new Constructor(['test'], 'filename') }, test: function (value) { // TODO. This test would be asynchronous. @@ -121,8 +120,8 @@ var types = [ type: 'ImageData', ctor: true, allowFailure: true, - createValue: function (ctor) { - return new ctor(1, 1) + createValue: function (Constructor) { + return new Constructor(1, 1) }, test: function (value) { return value.data.length === 4 diff --git a/test/support-test.js b/test/support-test.js index 6ed4e5a..b297c3e 100644 --- a/test/support-test.js +++ b/test/support-test.js @@ -1,3 +1,5 @@ +/* global indexedDB */ + 'use strict' var support = require('../util/support') diff --git a/test/util/test-common.js b/test/util/test-common.js index 5891fd8..2b4ebd9 100644 --- a/test/util/test-common.js +++ b/test/util/test-common.js @@ -1,94 +1,90 @@ var dbidx = 0 - , leveljs = require('../..') - , location = function () { - return '_leveldown_test_db_' + dbidx++ - } +var leveljs = require('../..') +var location = function () { + return '_leveldown_test_db_' + dbidx++ +} - , lastLocation = function () { - return '_leveldown_test_db_' + dbidx - } +var lastLocation = function () { + return '_leveldown_test_db_' + dbidx +} - , cleanup = function (callback) { - var list = [] - if (dbidx === 0) return callback() - for (var i = 0; i < dbidx; i++) { - list.push('_leveldown_test_db_' + i) - } +var cleanup = function (callback) { + var list = [] + if (dbidx === 0) return callback() + for (var i = 0; i < dbidx; i++) { + list.push('_leveldown_test_db_' + i) + } - function destroy() { - var f = list.pop() - if (list.length === 0) return callback() - leveljs.destroy(f, destroy) - } + function destroy () { + var f = list.pop() + if (list.length === 0) return callback() + leveljs.destroy(f, destroy) + } - destroy() - } + destroy() +} - , setUp = function (t) { - cleanup(function (err) { - t.notOk(err, 'cleanup returned an error') - t.end() - }) - } +var setUp = function (t) { + cleanup(function (err) { + t.notOk(err, 'cleanup returned an error') + t.end() + }) +} - , tearDown = function (t) { - setUp(t) // same cleanup! - } +var tearDown = function (t) { + setUp(t) // same cleanup! +} - , collectEntries = function (iterator, callback) { - var data = [] - , next = function () { - iterator.next(function (err, key, value) { - if (err) return callback(err) - if (!arguments.length) { - return iterator.end(function (err) { - callback(err, data) - }) - } - data.push({ key: key, value: value }) - process.nextTick(next) - }) - } - next() - } +var collectEntries = function (iterator, callback) { + var data = [] + var next = function () { + iterator.next(function (err, key, value) { + if (err) return callback(err) + if (!arguments.length) { + return iterator.end(function (err) { + callback(err, data) + }) + } + data.push({ key: key, value: value }) + process.nextTick(next) + }) + } + next() +} - , makeExistingDbTest = function (name, test, leveldown, testFn) { - test(name, function (t) { - cleanup(function () { - var loc = location() - , db = leveldown(loc) - , done = function (close) { - if (close === false) - return cleanup(t.end.bind(t)) - db.close(function (err) { - t.notOk(err, 'no error from close()') - cleanup(t.end.bind(t)) - }) - } - db.open(function (err) { - t.notOk(err, 'no error from open()') - db.batch( - [ - { type: 'put', key: 'one', value: '1' } - , { type: 'put', key: 'two', value: '2' } - , { type: 'put', key: 'three', value: '3' } - ] - , function (err) { - t.notOk(err, 'no error from batch()') - testFn(db, t, done, loc) - } - ) - }) +var makeExistingDbTest = function (name, test, leveldown, testFn) { + test(name, function (t) { + cleanup(function () { + var loc = location() + var db = leveldown(loc) + var done = function (close) { + if (close === false) { return cleanup(t.end.bind(t)) } + db.close(function (err) { + t.notOk(err, 'no error from close()') + cleanup(t.end.bind(t)) + }) + } + db.open(function (err) { + t.notOk(err, 'no error from open()') + db.batch([ + { type: 'put', key: 'one', value: '1' }, + { type: 'put', key: 'two', value: '2' }, + { type: 'put', key: 'three', value: '3' } + ], function (err) { + t.notOk(err, 'no error from batch()') + testFn(db, t, done, loc) }) }) - } + }) + }) +} module.exports = { - location : location - , cleanup : cleanup - , lastLocation : lastLocation - , setUp : setUp - , tearDown : tearDown - , collectEntries : collectEntries - , makeExistingDbTest : makeExistingDbTest + location: location, + cleanup: cleanup, + lastLocation: lastLocation, + setUp: setUp, + tearDown: tearDown, + collectEntries: collectEntries, + makeExistingDbTest: makeExistingDbTest }