You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# DataStore
2
2
3
-
DataStore is a JavaScript module that makes it easy to save key valuepairs to [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) with an API similar to [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
3
+
DataStore is a JavaScript module that makes it easy to save key value/pairs to [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) with an API similar to [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage).
4
4
5
-
IndexedDB is allowed more storage space than localStorage. It also can store more data types than strings. That means you can save structured data without having to convert it to JSON first. IndexedDB, unlike localStorage, isn’t blocking—all operations are asynchronous.
5
+
IndexedDB is allowed more storage space than localStorage. It can also store more data types than strings. That means you can save structured data without having to convert it to JSON first. IndexedDB, unlike localStorage, isn’t blocking—all operations are asynchronous.
6
6
7
-
IndexedDB can do a _lot_ more, but the above reasons above are enough to use it even in relatively simple cases. This DataStore class is woefully underusing IndexedDB features. It merely replicates localStorage but by using IndexedDB behind the scenes for its advantages.
7
+
IndexedDB can do a _lot_ more, but the reasons above are enough to use it even in relatively simple cases. This DataStore class is woefully underusing IndexedDB features. It merely replicates localStorage but by using IndexedDB behind the scenes for its advantages.
8
8
9
9
## Usage
10
10
11
-
While DataStore aims to be as simple as localStorage, it does have one extra setup step: an instance needs to be instantiated.
11
+
While DataStore aims to be as simple as localStorage, it does have one extra setup step: you must create an instance.
12
12
13
13
```js
14
14
importDataStorefrom'./path/to/DataStore.js';
@@ -97,7 +97,7 @@ While localStorage gives you a `length` property that you can read from, DataSto
97
97
asyncfunctionmain() {
98
98
let num =awaitstore.count();
99
99
// Ex: 3
100
-
100
+
101
101
// if you prefer the word "length," this method is identical
102
102
num =awaitstore.length();
103
103
// still 3
@@ -123,7 +123,7 @@ DataStore.setupDb({
123
123
onUpgradeNeeded:async (db, stores) => {
124
124
// Perform any database operations you want to do.
125
125
// `stores` represents a DataStore instance for each store you created.
126
-
}
126
+
},
127
127
});
128
128
```
129
129
@@ -140,15 +140,15 @@ async function main() {
140
140
conststore=newDataStore('My Database');
141
141
// number keys get turned into strings under the hood
142
142
constpost=awaitstore.getItem(1);
143
-
144
-
//pecify database name and object store name if not using default.
143
+
144
+
//specify database name and object store name if not using default.
Datastore only supports strings as keys. That said, you *can* use numbers in `getItem`, `setItem`, and `removeItems`. Just be aware that they get converted to strings under the hood. The `keys()` method always returns an array of strings.
154
+
DataStore only supports strings as keys. That said, you _can_ use numbers in `getItem`, `setItem`, and `removeItem`. Just be aware that they get converted to strings under the hood. The `keys()` method always returns an array of strings.
0 commit comments