You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
584 B
25 lines
584 B
var memStorage = require('./memStorage'); |
|
exports = function(type) { |
|
type = type || 'local'; |
|
var ret; |
|
switch (type) { |
|
case 'local': |
|
ret = window.localStorage; |
|
break; |
|
case 'session': |
|
ret = window.sessionStorage; |
|
break; |
|
} |
|
try { |
|
var x = 'test-localStorage-' + Date.now(); |
|
ret.setItem(x, x); |
|
var y = ret.getItem(x); |
|
ret.removeItem(x); |
|
if (y !== x) throw new Error(); |
|
} catch (e) { |
|
return memStorage; |
|
} |
|
return ret; |
|
}; |
|
|
|
module.exports = exports;
|
|
|