syntax highlighting

This commit is contained in:
AJ ONeal 2014-03-01 10:19:38 -06:00
parent c617241c52
commit 9b930a09aa
1 changed files with 28 additions and 24 deletions

View File

@ -11,23 +11,25 @@ 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 })
// in-memory, does call `String(val)` on values (i.e. `{}` becomes `'[object Object]'` // in-memory, does call `String(val)` on values (i.e. `{}` becomes `'[object Object]'`
, sessionStorage = new Storage(null, { strict: true }) , sessionStorage = new Storage(null, { strict: true })
, 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
--- ---