fake-indexeddb 1.0.8 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,11 +8,15 @@ It passes [the W3C IndexedDB test suite](https://github.com/w3c/web-platform-tes
8
8
 
9
9
  For use with CommonJS (Node.js/Browserify), [install through npm](https://www.npmjs.com/package/fake-indexeddb):
10
10
 
11
- $ npm install fake-indexeddb
11
+ ```sh
12
+ npm install fake-indexeddb
13
+ ```
12
14
 
13
15
  Otherwise, download [the bundled version](dist/fakeIndexedDB.js) and include it in your page like:
14
16
 
15
- <script type="text/javascript" src="fakeIndexedDB.js"></script>
17
+ ```html
18
+ <script type="text/javascript" src="fakeIndexedDB.js"></script>
19
+ ```
16
20
 
17
21
  If you're using AMD, you'll have to shim it.
18
22
 
@@ -22,42 +26,44 @@ Functionally, it works exactly like IndexedDB except data is not persisted to di
22
26
 
23
27
  Example usage:
24
28
 
25
- var fakeIndexedDB = require('fake-indexeddb');
26
- var FDBKeyRange = require('fake-indexeddb/lib/FDBKeyRange');
27
-
28
- var request = fakeIndexedDB.open('test', 3);
29
- request.onupgradeneeded = function () {
30
- var db = request.result;
31
- var store = db.createObjectStore("books", {keyPath: "isbn"});
32
- store.createIndex("by_title", "title", {unique: true});
33
-
34
- store.put({title: "Quarry Memories", author: "Fred", isbn: 123456});
35
- store.put({title: "Water Buffaloes", author: "Fred", isbn: 234567});
36
- store.put({title: "Bedrock Nights", author: "Barney", isbn: 345678});
37
- }
38
- request.onsuccess = function (event) {
39
- var db = event.target.result;
40
-
41
- var tx = db.transaction("books");
42
-
43
- tx.objectStore("books").index("by_title").get("Quarry Memories").addEventListener('success', function (event) {
44
- console.log('From index:', event.target.result);
45
- });
46
- tx.objectStore("books").openCursor(FDBKeyRange.lowerBound(200000)).onsuccess = function (event) {
47
- var cursor = event.target.result;
48
- if (cursor) {
49
- console.log('From cursor:', cursor.value);
50
- cursor.continue();
51
- }
52
- };
53
- tx.oncomplete = function () {
54
- console.log('All done!');
55
- };
29
+ ```js
30
+ var fakeIndexedDB = require('fake-indexeddb');
31
+ var FDBKeyRange = require('fake-indexeddb/lib/FDBKeyRange');
32
+
33
+ var request = fakeIndexedDB.open('test', 3);
34
+ request.onupgradeneeded = function () {
35
+ var db = request.result;
36
+ var store = db.createObjectStore("books", {keyPath: "isbn"});
37
+ store.createIndex("by_title", "title", {unique: true});
38
+
39
+ store.put({title: "Quarry Memories", author: "Fred", isbn: 123456});
40
+ store.put({title: "Water Buffaloes", author: "Fred", isbn: 234567});
41
+ store.put({title: "Bedrock Nights", author: "Barney", isbn: 345678});
42
+ }
43
+ request.onsuccess = function (event) {
44
+ var db = event.target.result;
45
+
46
+ var tx = db.transaction("books");
47
+
48
+ tx.objectStore("books").index("by_title").get("Quarry Memories").addEventListener('success', function (event) {
49
+ console.log('From index:', event.target.result);
50
+ });
51
+ tx.objectStore("books").openCursor(FDBKeyRange.lowerBound(200000)).onsuccess = function (event) {
52
+ var cursor = event.target.result;
53
+ if (cursor) {
54
+ console.log('From cursor:', cursor.value);
55
+ cursor.continue();
56
+ }
56
57
  };
58
+ tx.oncomplete = function () {
59
+ console.log('All done!');
60
+ };
61
+ };
62
+ ```
57
63
 
58
64
  Variable names of all the objects are like the normal IndexedDB ones except with F replacing I, e.g. `FDBIndex` instead of `IDBIndex`.
59
65
 
60
- If you're using the bundled version (not installed through npm), then all of the variables are created and attached to `window`, like `window.fakeIndexedDB`, `window.FDBKeyRange`, etc.
66
+ If you're using the bundled version (not installed through npm), then all of the variables are created and attached to `window` (or `self` in a Web Worker), like `window.fakeIndexedDB`, `window.FDBKeyRange`, etc.
61
67
 
62
68
  ## Potential applications:
63
69