Skip to content

Commit 8ed05fb

Browse files
committed
released v2.0.3 #41 #8
1 parent 5bb6653 commit 8ed05fb

File tree

5 files changed

+60
-48
lines changed

5 files changed

+60
-48
lines changed

dist/store.cjs.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**!
2-
* storejs v2.0.2
2+
* storejs v2.0.3
33
* Local storage localstorage package provides a simple API
44
*
55
* Copyright (c) 2023 kenny wang <[email protected]>
@@ -10,7 +10,6 @@
1010

1111
'use strict';
1212

13-
var storage = window.localStorage;
1413
function isJSON(obj) {
1514
obj = JSON.stringify(obj);
1615
if (!/^\{[\s\S]*\}$/.test(obj)) {
@@ -39,29 +38,36 @@ function isArray(value) {
3938
}
4039
// https://github.com/jaywcjlove/store.js/pull/8
4140
// Error: QuotaExceededError
42-
function dealIncognito(storage) {
41+
function dealIncognito() {
42+
var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.localStorage;
4343
var _KEY = '_Is_Incognit',
4444
_VALUE = 'yes';
4545
try {
4646
storage.setItem(_KEY, _VALUE);
47+
storage.removeItem(_KEY);
4748
} catch (e) {
48-
if (e.name === 'QuotaExceededError') {
49-
var _nothing = function _nothing() {};
50-
storage.__proto__ = {
51-
setItem: _nothing,
52-
getItem: _nothing,
53-
removeItem: _nothing,
54-
clear: _nothing
55-
};
56-
}
49+
Storage.prototype._data = {};
50+
Storage.prototype.setItem = function (id, val) {
51+
return this._data[id] = String(val);
52+
};
53+
Storage.prototype.getItem = function (id) {
54+
return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
55+
};
56+
Storage.prototype.removeItem = function (id) {
57+
return delete this._data[id];
58+
};
59+
Storage.prototype.clear = function () {
60+
return this._data = {};
61+
};
62+
storage = Storage;
5763
} finally {
5864
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY);
5965
}
6066
return storage;
6167
}
6268

6369
// deal QuotaExceededError if user use incognito mode in browser
64-
storage = dealIncognito(storage);
70+
var storage = dealIncognito();
6571
function Store() {
6672
if (!(this instanceof Store)) {
6773
return new Store();

dist/store.esm.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**!
2-
* storejs v2.0.2
2+
* storejs v2.0.3
33
* Local storage localstorage package provides a simple API
44
*
55
* Copyright (c) 2023 kenny wang <[email protected]>
@@ -8,7 +8,6 @@
88
* Licensed under the MIT license.
99
*/
1010

11-
var storage = window.localStorage;
1211
function isJSON(obj) {
1312
obj = JSON.stringify(obj);
1413
if (!/^\{[\s\S]*\}$/.test(obj)) {
@@ -37,29 +36,36 @@ function isArray(value) {
3736
}
3837
// https://github.com/jaywcjlove/store.js/pull/8
3938
// Error: QuotaExceededError
40-
function dealIncognito(storage) {
39+
function dealIncognito() {
40+
var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.localStorage;
4141
var _KEY = '_Is_Incognit',
4242
_VALUE = 'yes';
4343
try {
4444
storage.setItem(_KEY, _VALUE);
45+
storage.removeItem(_KEY);
4546
} catch (e) {
46-
if (e.name === 'QuotaExceededError') {
47-
var _nothing = function _nothing() {};
48-
storage.__proto__ = {
49-
setItem: _nothing,
50-
getItem: _nothing,
51-
removeItem: _nothing,
52-
clear: _nothing
53-
};
54-
}
47+
Storage.prototype._data = {};
48+
Storage.prototype.setItem = function (id, val) {
49+
return this._data[id] = String(val);
50+
};
51+
Storage.prototype.getItem = function (id) {
52+
return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
53+
};
54+
Storage.prototype.removeItem = function (id) {
55+
return delete this._data[id];
56+
};
57+
Storage.prototype.clear = function () {
58+
return this._data = {};
59+
};
60+
storage = Storage;
5561
} finally {
5662
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY);
5763
}
5864
return storage;
5965
}
6066

6167
// deal QuotaExceededError if user use incognito mode in browser
62-
storage = dealIncognito(storage);
68+
var storage = dealIncognito();
6369
function Store() {
6470
if (!(this instanceof Store)) {
6571
return new Store();

dist/store.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**!
2-
* storejs v2.0.2
2+
* storejs v2.0.3
33
* Local storage localstorage package provides a simple API
44
*
55
* Copyright (c) 2023 kenny wang <[email protected]>
@@ -14,7 +14,6 @@
1414
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.store = factory());
1515
})(this, (function () { 'use strict';
1616

17-
var storage = window.localStorage;
1817
function isJSON(obj) {
1918
obj = JSON.stringify(obj);
2019
if (!/^\{[\s\S]*\}$/.test(obj)) {
@@ -43,29 +42,36 @@
4342
}
4443
// https://github.com/jaywcjlove/store.js/pull/8
4544
// Error: QuotaExceededError
46-
function dealIncognito(storage) {
45+
function dealIncognito() {
46+
var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.localStorage;
4747
var _KEY = '_Is_Incognit',
4848
_VALUE = 'yes';
4949
try {
5050
storage.setItem(_KEY, _VALUE);
51+
storage.removeItem(_KEY);
5152
} catch (e) {
52-
if (e.name === 'QuotaExceededError') {
53-
var _nothing = function _nothing() {};
54-
storage.__proto__ = {
55-
setItem: _nothing,
56-
getItem: _nothing,
57-
removeItem: _nothing,
58-
clear: _nothing
59-
};
60-
}
53+
Storage.prototype._data = {};
54+
Storage.prototype.setItem = function (id, val) {
55+
return this._data[id] = String(val);
56+
};
57+
Storage.prototype.getItem = function (id) {
58+
return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
59+
};
60+
Storage.prototype.removeItem = function (id) {
61+
return delete this._data[id];
62+
};
63+
Storage.prototype.clear = function () {
64+
return this._data = {};
65+
};
66+
storage = Storage;
6167
} finally {
6268
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY);
6369
}
6470
return storage;
6571
}
6672

6773
// deal QuotaExceededError if user use incognito mode in browser
68-
storage = dealIncognito(storage);
74+
var storage = dealIncognito();
6975
function Store() {
7076
if (!(this instanceof Store)) {
7177
return new Store();

dist/store.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "storejs",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "Local storage localstorage package provides a simple API",
55
"homepage": "https://jaywcjlove.github.io/store.js/",
66
"author": "kenny wang <[email protected]>",
@@ -32,12 +32,6 @@
3232
"dist/*.js",
3333
"types/index.d.ts"
3434
],
35-
"markdown-to-html": {
36-
"reurls": {
37-
"./README-zh.md": "index.zh.html",
38-
"./README.md": "index.html"
39-
}
40-
},
4135
"devDependencies": {
4236
"@babel/cli": "^7.21.0",
4337
"@babel/core": "^7.21.0",

0 commit comments

Comments
 (0)