[IndexedDB] Add IDBKeyRange.includes(key) (#41)

Pretty straightforward. A polyfill would be like:

```js
IDBKeyRange.prototype.includes = function(key) {
  var r = this, c;
  if (r.lower !== undefined) {
    c = indexedDB.cmp(key, r.lower)
    if (r.lowerOpen && c <= 0) return false;
    if (!r.lowerOpen && c < 0) return false;
  }
  if (r.upper !== undefined) {
    c = indexedDB.cmp(key, r.upper)
    if (r.upperOpen && c >= 0) return false;
    if (!r.upperOpen && c > 0) return false;
  }
  return true;
};
```

And some sample cases:

```js
// basic cases
IDBKeyRange.bound(12, 34).includes(11); // false
IDBKeyRange.bound(12, 34).includes(12); // true
IDBKeyRange.bound(12, 34).includes(22); // true
IDBKeyRange.bound(12, 34).includes(44); // false

// closed bound (inclusive)
IDBKeyRange.lowerBound(12).includes(11); // false
IDBKeyRange.lowerBound(12).includes(12); // true
IDBKeyRange.lowerBound(12).includes(13); // true

// open bound (exclusive)
IDBKeyRange.lowerBound(12, true).includes(11); // false
IDBKeyRange.lowerBound(12, true).includes(12); // false
IDBKeyRange.lowerBound(12, true).includes(13); // true

// only
IDBKeyRange.only(12).includes(12); // true
IDBKeyRange.only(12).includes(11); // false
```


---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/IndexedDB/issues/41

Received on Wednesday, 7 October 2015 16:56:28 UTC