-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bb6653
commit 8ed05fb
Showing
5 changed files
with
60 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/**! | ||
* storejs v2.0.2 | ||
* storejs v2.0.3 | ||
* Local storage localstorage package provides a simple API | ||
* | ||
* Copyright (c) 2023 kenny wang <[email protected]> | ||
|
@@ -10,7 +10,6 @@ | |
|
||
'use strict'; | ||
|
||
var storage = window.localStorage; | ||
function isJSON(obj) { | ||
obj = JSON.stringify(obj); | ||
if (!/^\{[\s\S]*\}$/.test(obj)) { | ||
|
@@ -39,29 +38,36 @@ function isArray(value) { | |
} | ||
// https://github.com/jaywcjlove/store.js/pull/8 | ||
// Error: QuotaExceededError | ||
function dealIncognito(storage) { | ||
function dealIncognito() { | ||
var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.localStorage; | ||
var _KEY = '_Is_Incognit', | ||
_VALUE = 'yes'; | ||
try { | ||
storage.setItem(_KEY, _VALUE); | ||
storage.removeItem(_KEY); | ||
} catch (e) { | ||
if (e.name === 'QuotaExceededError') { | ||
var _nothing = function _nothing() {}; | ||
storage.__proto__ = { | ||
setItem: _nothing, | ||
getItem: _nothing, | ||
removeItem: _nothing, | ||
clear: _nothing | ||
}; | ||
} | ||
Storage.prototype._data = {}; | ||
Storage.prototype.setItem = function (id, val) { | ||
return this._data[id] = String(val); | ||
}; | ||
Storage.prototype.getItem = function (id) { | ||
return this._data.hasOwnProperty(id) ? this._data[id] : undefined; | ||
}; | ||
Storage.prototype.removeItem = function (id) { | ||
return delete this._data[id]; | ||
}; | ||
Storage.prototype.clear = function () { | ||
return this._data = {}; | ||
}; | ||
storage = Storage; | ||
} finally { | ||
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY); | ||
} | ||
return storage; | ||
} | ||
|
||
// deal QuotaExceededError if user use incognito mode in browser | ||
storage = dealIncognito(storage); | ||
var storage = dealIncognito(); | ||
function Store() { | ||
if (!(this instanceof Store)) { | ||
return new Store(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/**! | ||
* storejs v2.0.2 | ||
* storejs v2.0.3 | ||
* Local storage localstorage package provides a simple API | ||
* | ||
* Copyright (c) 2023 kenny wang <[email protected]> | ||
|
@@ -8,7 +8,6 @@ | |
* Licensed under the MIT license. | ||
*/ | ||
|
||
var storage = window.localStorage; | ||
function isJSON(obj) { | ||
obj = JSON.stringify(obj); | ||
if (!/^\{[\s\S]*\}$/.test(obj)) { | ||
|
@@ -37,29 +36,36 @@ function isArray(value) { | |
} | ||
// https://github.com/jaywcjlove/store.js/pull/8 | ||
// Error: QuotaExceededError | ||
function dealIncognito(storage) { | ||
function dealIncognito() { | ||
var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.localStorage; | ||
var _KEY = '_Is_Incognit', | ||
_VALUE = 'yes'; | ||
try { | ||
storage.setItem(_KEY, _VALUE); | ||
storage.removeItem(_KEY); | ||
} catch (e) { | ||
if (e.name === 'QuotaExceededError') { | ||
var _nothing = function _nothing() {}; | ||
storage.__proto__ = { | ||
setItem: _nothing, | ||
getItem: _nothing, | ||
removeItem: _nothing, | ||
clear: _nothing | ||
}; | ||
} | ||
Storage.prototype._data = {}; | ||
Storage.prototype.setItem = function (id, val) { | ||
return this._data[id] = String(val); | ||
}; | ||
Storage.prototype.getItem = function (id) { | ||
return this._data.hasOwnProperty(id) ? this._data[id] : undefined; | ||
}; | ||
Storage.prototype.removeItem = function (id) { | ||
return delete this._data[id]; | ||
}; | ||
Storage.prototype.clear = function () { | ||
return this._data = {}; | ||
}; | ||
storage = Storage; | ||
} finally { | ||
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY); | ||
} | ||
return storage; | ||
} | ||
|
||
// deal QuotaExceededError if user use incognito mode in browser | ||
storage = dealIncognito(storage); | ||
var storage = dealIncognito(); | ||
function Store() { | ||
if (!(this instanceof Store)) { | ||
return new Store(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/**! | ||
* storejs v2.0.2 | ||
* storejs v2.0.3 | ||
* Local storage localstorage package provides a simple API | ||
* | ||
* Copyright (c) 2023 kenny wang <[email protected]> | ||
|
@@ -14,7 +14,6 @@ | |
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.store = factory()); | ||
})(this, (function () { 'use strict'; | ||
|
||
var storage = window.localStorage; | ||
function isJSON(obj) { | ||
obj = JSON.stringify(obj); | ||
if (!/^\{[\s\S]*\}$/.test(obj)) { | ||
|
@@ -43,29 +42,36 @@ | |
} | ||
// https://github.com/jaywcjlove/store.js/pull/8 | ||
// Error: QuotaExceededError | ||
function dealIncognito(storage) { | ||
function dealIncognito() { | ||
var storage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.localStorage; | ||
var _KEY = '_Is_Incognit', | ||
_VALUE = 'yes'; | ||
try { | ||
storage.setItem(_KEY, _VALUE); | ||
storage.removeItem(_KEY); | ||
} catch (e) { | ||
if (e.name === 'QuotaExceededError') { | ||
var _nothing = function _nothing() {}; | ||
storage.__proto__ = { | ||
setItem: _nothing, | ||
getItem: _nothing, | ||
removeItem: _nothing, | ||
clear: _nothing | ||
}; | ||
} | ||
Storage.prototype._data = {}; | ||
Storage.prototype.setItem = function (id, val) { | ||
return this._data[id] = String(val); | ||
}; | ||
Storage.prototype.getItem = function (id) { | ||
return this._data.hasOwnProperty(id) ? this._data[id] : undefined; | ||
}; | ||
Storage.prototype.removeItem = function (id) { | ||
return delete this._data[id]; | ||
}; | ||
Storage.prototype.clear = function () { | ||
return this._data = {}; | ||
}; | ||
storage = Storage; | ||
} finally { | ||
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY); | ||
} | ||
return storage; | ||
} | ||
|
||
// deal QuotaExceededError if user use incognito mode in browser | ||
storage = dealIncognito(storage); | ||
var storage = dealIncognito(); | ||
function Store() { | ||
if (!(this instanceof Store)) { | ||
return new Store(); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "storejs", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Local storage localstorage package provides a simple API", | ||
"homepage": "https://jaywcjlove.github.io/store.js/", | ||
"author": "kenny wang <[email protected]>", | ||
|
@@ -32,12 +32,6 @@ | |
"dist/*.js", | ||
"types/index.d.ts" | ||
], | ||
"markdown-to-html": { | ||
"reurls": { | ||
"./README-zh.md": "index.zh.html", | ||
"./README.md": "index.html" | ||
} | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.21.0", | ||
"@babel/core": "^7.21.0", | ||
|