Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

use Standard #112

Merged
merged 9 commits into from
May 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global indexedDB */

'use strict'

module.exports = Level
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
8 changes: 5 additions & 3 deletions iterator.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand All @@ -33,5 +34,10 @@
},
"browser": {
"./util/immediate.js": "./util/immediate-browser.js"
},
"standard": {
"ignore": [
"test/util/idb-shim.js"
]
}
}
10 changes: 5 additions & 5 deletions test/custom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
25 changes: 12 additions & 13 deletions test/structured-clone-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

var levelup = require('levelup')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah. Wrong commit message.

var isDataCloneError = require('../util/is-data-clone-error')
var bytes = [0, 127]

Expand All @@ -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] },
Expand Down Expand Up @@ -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
},
Expand All @@ -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
},
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/support-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global indexedDB */

'use strict'

var support = require('../util/support')
Expand Down
156 changes: 76 additions & 80 deletions test/util/test-common.js
Original file line number Diff line number Diff line change
@@ -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
}