syntax highlighting
This commit is contained in:
parent
c617241c52
commit
9b930a09aa
40
README.md
40
README.md
|
@ -11,7 +11,8 @@ This is meant for the purpose of being able to run unit-tests and such for brows
|
||||||
Usage
|
Usage
|
||||||
----
|
----
|
||||||
|
|
||||||
var Storage = require('dom-storage')
|
```javascript
|
||||||
|
var Storage = require('dom-storage')
|
||||||
|
|
||||||
// in-file, doesn't call `String(val)` on values (default)
|
// in-file, doesn't call `String(val)` on values (default)
|
||||||
, localStorage = new Storage('./db.json', { strict: false })
|
, localStorage = new Storage('./db.json', { strict: false })
|
||||||
|
@ -22,12 +23,13 @@ Usage
|
||||||
, myValue = { foo: 'bar', baz: 'quux' }
|
, myValue = { foo: 'bar', baz: 'quux' }
|
||||||
;
|
;
|
||||||
|
|
||||||
localStorage.setItem('myKey', myValue);
|
localStorage.setItem('myKey', myValue);
|
||||||
myValue = localStorage.getItem('myKey');
|
myValue = localStorage.getItem('myKey');
|
||||||
|
|
||||||
// use JSON to stringify / parse when using strict w3c compliance
|
// use JSON to stringify / parse when using strict w3c compliance
|
||||||
sessionStorage.setItem('myKey', JSON.stringify(myValue));
|
sessionStorage.setItem('myKey', JSON.stringify(myValue));
|
||||||
myValue = JSON.parse(localStorage.getItem('myKey'));
|
myValue = JSON.parse(localStorage.getItem('myKey'));
|
||||||
|
```
|
||||||
|
|
||||||
API
|
API
|
||||||
---
|
---
|
||||||
|
@ -42,22 +44,24 @@ API
|
||||||
Tests
|
Tests
|
||||||
---
|
---
|
||||||
|
|
||||||
0 === localStorage.length;
|
```javascript
|
||||||
null === localStorage.getItem('doesn't exist');
|
0 === localStorage.length;
|
||||||
undefined === localStorage['doesn't exist'];
|
null === localStorage.getItem('doesn't exist');
|
||||||
|
undefined === localStorage['doesn't exist'];
|
||||||
|
|
||||||
localStorage.setItem('myItem');
|
localStorage.setItem('myItem');
|
||||||
"undefined" === localStorage.getItem('myItem');
|
"undefined" === localStorage.getItem('myItem');
|
||||||
1 === localStorage.length;
|
1 === localStorage.length;
|
||||||
|
|
||||||
localStorage.setItem('myItem', 0);
|
localStorage.setItem('myItem', 0);
|
||||||
"0" === localStorage.getItem('myItem');
|
"0" === localStorage.getItem('myItem');
|
||||||
|
|
||||||
localStorage.removeItem('myItem', 0);
|
localStorage.removeItem('myItem', 0);
|
||||||
0 === localStorage.length;
|
0 === localStorage.length;
|
||||||
|
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
0 === localStorage.length;
|
0 === localStorage.length;
|
||||||
|
```
|
||||||
|
|
||||||
Notes
|
Notes
|
||||||
---
|
---
|
||||||
|
|
Loading…
Reference in New Issue