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

Commit 2c20127

Browse files
committed
Every browser in our test matrix now supports binary keys
1 parent 720aced commit 2c20127

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

README.md

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ Being `abstract-leveldown` compliant means you can use many of the [Level module
4646
**If you are upgrading:** please see [UPGRADING.md](UPGRADING.md).
4747

4848
```js
49-
var levelup = require('levelup')
50-
var leveljs = require('level-js')
51-
var db = levelup(leveljs('bigdata'))
49+
const levelup = require('levelup')
50+
const leveljs = require('level-js')
51+
const db = levelup(leveljs('bigdata'))
5252

5353
db.put('hello', Buffer.from('world'), function (err) {
5454
if (err) throw err
@@ -61,7 +61,7 @@ db.put('hello', Buffer.from('world'), function (err) {
6161
})
6262
```
6363

64-
In ES6 browsers:
64+
With `async/await`:
6565

6666
```js
6767
const levelup = require('levelup')
@@ -74,13 +74,13 @@ const value = await db.get('hello')
7474

7575
## Browser Support
7676

77-
[![Sauce Test Status](https://saucelabs.com/browser-matrix/level-js.svg)](https://saucelabs.com/u/level-js)
77+
[![Sauce Test Status](https://app.saucelabs.com/browser-matrix/level-js.svg)](https://app.saucelabs.com/u/level-js)
7878

7979
## Type Support
8080

8181
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.
8282

83-
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)`.
83+
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.
8484

8585
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.
8686

@@ -118,17 +118,6 @@ The optional `options` argument may contain:
118118

119119
See [`IDBFactory#open`](https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory/open) for more details.
120120

121-
## Running Tests
122-
123-
```sh
124-
git clone git@github.com:Level/level-js.git
125-
cd level-js
126-
npm install
127-
npm test
128-
```
129-
130-
It will print out a URL to open in a browser of choice.
131-
132121
## Big Thanks
133122

134123
Cross-browser Testing Platform and Open Source ♥ Provided by [Sauce Labs](https://saucelabs.com).

test/custom-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ module.exports = function (leveljs, test, testCommon) {
121121
var db = testCommon.factory()
122122

123123
if (!db.supports.bufferKeys) {
124-
t.pass('environment does not support buffer keys')
124+
t.fail('environment does not support buffer keys')
125125
return t.end()
126126
}
127127

@@ -165,7 +165,7 @@ module.exports = function (leveljs, test, testCommon) {
165165
var db = testCommon.factory()
166166

167167
if (!db.supports.bufferKeys) {
168-
t.pass('environment does not support buffer keys')
168+
t.fail('environment does not support buffer keys')
169169
return t.end()
170170
}
171171

@@ -200,7 +200,7 @@ module.exports = function (leveljs, test, testCommon) {
200200
var db = testCommon.factory()
201201

202202
if (!db.supports.bufferKeys) {
203-
t.pass('environment does not support buffer keys')
203+
t.fail('environment does not support buffer keys')
204204
return t.end()
205205
}
206206

test/upgrade-test.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ module.exports = function (leveljs, test, testCommon) {
1010
{ key: -1, value: 'a' },
1111
{ key: '0', value: ab('b') },
1212
{ key: '1', value: 1 },
13-
{ key: maybeBinary('2'), value: new Uint8Array(ab('2')) }
13+
{ key: ab('2'), value: new Uint8Array(ab('2')) }
1414
]
1515

1616
var output = [
17-
{ key: maybeBinary('-1'), value: new Uint8Array(ab('a')) },
18-
{ key: maybeBinary('0'), value: new Uint8Array(ab('b')) },
19-
{ key: maybeBinary('1'), value: new Uint8Array(ab('1')) },
20-
{ key: maybeBinary('2'), value: new Uint8Array(ab('2')) }
17+
{ key: ab('-1'), value: new Uint8Array(ab('a')) },
18+
{ key: ab('0'), value: new Uint8Array(ab('b')) },
19+
{ key: ab('1'), value: new Uint8Array(ab('1')) },
20+
{ key: ab('2'), value: new Uint8Array(ab('2')) }
2121
]
2222

2323
db.open(function (err) {
@@ -34,12 +34,7 @@ module.exports = function (leveljs, test, testCommon) {
3434
t.ifError(err, 'no concat error')
3535

3636
entries.forEach(function (entry) {
37-
if (db.supports.bufferKeys) {
38-
t.ok(entry.key instanceof ArrayBuffer)
39-
} else {
40-
t.is(typeof entry.key, 'string')
41-
}
42-
37+
t.ok(entry.key instanceof ArrayBuffer)
4338
t.ok(entry.value instanceof Uint8Array)
4439
})
4540

@@ -50,10 +45,6 @@ module.exports = function (leveljs, test, testCommon) {
5045
})
5146
})
5247

53-
function maybeBinary (key) {
54-
return db.supports.bufferKeys ? ab(key) : String(key)
55-
}
56-
5748
function concatRaw (callback) {
5849
var it = db.iterator()
5950
it._deserializeKey = it._deserializeValue = identity

0 commit comments

Comments
 (0)