diff --git a/README.md b/README.md index 23261d0..f4f4f7e 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,9 @@ Being `abstract-leveldown` compliant means you can use many of the [Level module **If you are upgrading:** please see [UPGRADING.md](UPGRADING.md). ```js -var levelup = require('levelup') -var leveljs = require('level-js') -var db = levelup(leveljs('bigdata')) +const levelup = require('levelup') +const leveljs = require('level-js') +const db = levelup(leveljs('bigdata')) db.put('hello', Buffer.from('world'), function (err) { if (err) throw err @@ -61,7 +61,7 @@ db.put('hello', Buffer.from('world'), function (err) { }) ``` -In ES6 browsers: +With `async/await`: ```js const levelup = require('levelup') @@ -74,13 +74,13 @@ const value = await db.get('hello') ## Browser Support -[![Sauce Test Status](https://saucelabs.com/browser-matrix/level-js.svg)](https://saucelabs.com/u/level-js) +[![Sauce Test Status](https://app.saucelabs.com/browser-matrix/level-js.svg)](https://app.saucelabs.com/u/level-js) ## Type Support Keys and values can be a string or [`Buffer`][buffer]. Any other type will be irreversibly stringified. The only exceptions are `null` and `undefined`. Keys and values of that type are rejected. -In order to sort string and Buffer keys the same way, for compatibility with `leveldown` and the larger ecosystem, `level-js` internally converts keys and values to binary before passing them to IndexedDB. If binary keys are not supported by the environment (like IE11) `level-js` falls back to `String(key)`. +In order to sort string and Buffer keys the same way, for compatibility with `leveldown` and the larger ecosystem, `level-js` internally converts keys and values to binary before passing them to IndexedDB. If you desire non-destructive encoding (e.g. to store and retrieve numbers as-is), wrap `level-js` with [`encoding-down`][encoding-down]. Alternatively install [`level`][level] which conveniently bundles [`levelup`][levelup], `level-js` and `encoding-down`. Such an approach is also recommended if you want to achieve universal (isomorphic) behavior. For example, you could have [`leveldown`][leveldown] in a backend and `level-js` in the frontend. The `level` package does exactly that. @@ -118,17 +118,6 @@ The optional `options` argument may contain: See [`IDBFactory#open`](https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory/open) for more details. -## Running Tests - -```sh -git clone git@github.com:Level/level-js.git -cd level-js -npm install -npm test -``` - -It will print out a URL to open in a browser of choice. - ## Big Thanks Cross-browser Testing Platform and Open Source ♥ Provided by [Sauce Labs](https://saucelabs.com). diff --git a/test/custom-test.js b/test/custom-test.js index b9c4827..5d63140 100644 --- a/test/custom-test.js +++ b/test/custom-test.js @@ -121,7 +121,7 @@ module.exports = function (leveljs, test, testCommon) { var db = testCommon.factory() if (!db.supports.bufferKeys) { - t.pass('environment does not support buffer keys') + t.fail('environment does not support buffer keys') return t.end() } @@ -165,7 +165,7 @@ module.exports = function (leveljs, test, testCommon) { var db = testCommon.factory() if (!db.supports.bufferKeys) { - t.pass('environment does not support buffer keys') + t.fail('environment does not support buffer keys') return t.end() } @@ -200,7 +200,7 @@ module.exports = function (leveljs, test, testCommon) { var db = testCommon.factory() if (!db.supports.bufferKeys) { - t.pass('environment does not support buffer keys') + t.fail('environment does not support buffer keys') return t.end() } diff --git a/test/upgrade-test.js b/test/upgrade-test.js index c474116..8a15887 100644 --- a/test/upgrade-test.js +++ b/test/upgrade-test.js @@ -10,14 +10,14 @@ module.exports = function (leveljs, test, testCommon) { { key: -1, value: 'a' }, { key: '0', value: ab('b') }, { key: '1', value: 1 }, - { key: maybeBinary('2'), value: new Uint8Array(ab('2')) } + { key: ab('2'), value: new Uint8Array(ab('2')) } ] var output = [ - { key: maybeBinary('-1'), value: new Uint8Array(ab('a')) }, - { key: maybeBinary('0'), value: new Uint8Array(ab('b')) }, - { key: maybeBinary('1'), value: new Uint8Array(ab('1')) }, - { key: maybeBinary('2'), value: new Uint8Array(ab('2')) } + { key: ab('-1'), value: new Uint8Array(ab('a')) }, + { key: ab('0'), value: new Uint8Array(ab('b')) }, + { key: ab('1'), value: new Uint8Array(ab('1')) }, + { key: ab('2'), value: new Uint8Array(ab('2')) } ] db.open(function (err) { @@ -34,12 +34,7 @@ module.exports = function (leveljs, test, testCommon) { t.ifError(err, 'no concat error') entries.forEach(function (entry) { - if (db.supports.bufferKeys) { - t.ok(entry.key instanceof ArrayBuffer) - } else { - t.is(typeof entry.key, 'string') - } - + t.ok(entry.key instanceof ArrayBuffer) t.ok(entry.value instanceof Uint8Array) }) @@ -50,10 +45,6 @@ module.exports = function (leveljs, test, testCommon) { }) }) - function maybeBinary (key) { - return db.supports.bufferKeys ? ab(key) : String(key) - } - function concatRaw (callback) { var it = db.iterator() it._deserializeKey = it._deserializeValue = identity