-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock.localStorage.js
More file actions
37 lines (37 loc) · 937 Bytes
/
mock.localStorage.js
File metadata and controls
37 lines (37 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*!
* mock.localStorage.js
*
* Basic mocking for HTML5 window.localStorage.
* https://developer.mozilla.org/en/docs/Web/Guide/API/DOM/Storage
*
* Created by Pete Saia <pete@lev-interactive.com>
*
* Copyright 2013, 2014 Lev Interacitve, LLC
* Released under the MIT license
* http://lev-interactive.com/
*/
(function(global) {
global.localStorageMock = function() {
var ls = {};
ls.setItem = function (key, val) {
this[escape(key)] = escape(val);
};
ls.getItem = function (key) {
return this[escape(key)];
};
ls.removeItem = function (key) {
if (this[escape(key)]) {
delete this[escape(key)];
}
};
ls.hasOwnProperty = function(key) {
return Object.keys(this).indexOf(escape(key)) !== -1;
};
Object.defineProperty(ls, 'length', {
get: function () {
return Object.keys(this).length - 4;
}
});
return ls;
};
})(window);