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