-
-
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.
chore(deps): update devDependencies rollup to ^3.17.3
- Loading branch information
1 parent
2b4ad9e
commit d4a5525
Showing
7 changed files
with
52 additions
and
161 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,63 +1,52 @@ | ||
/**! | ||
* storejs v2.0.0 | ||
* storejs v2.0.1 | ||
* Local storage localstorage package provides a simple API | ||
* | ||
* Copyright (c) 2021 kenny wang <[email protected]> | ||
* https://github.com/jaywcjlove/store.js | ||
* Copyright (c) 2023 kenny wang <[email protected]> | ||
* https://jaywcjlove.github.io/store.js/ | ||
* | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var storage = window.localStorage; | ||
|
||
function isJSON(obj) { | ||
obj = JSON.stringify(obj); | ||
|
||
if (!/^\{[\s\S]*\}$/.test(obj)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
function stringify(val) { | ||
return val === undefined || typeof val === "function" ? val + '' : JSON.stringify(val); | ||
} | ||
|
||
function deserialize(value) { | ||
if (typeof value !== 'string') { | ||
return undefined; | ||
} | ||
|
||
try { | ||
return JSON.parse(value); | ||
} catch (e) { | ||
return value; | ||
} | ||
} | ||
|
||
function isFunction(value) { | ||
return {}.toString.call(value) === "[object Function]"; | ||
} | ||
|
||
function isArray(value) { | ||
return Object.prototype.toString.call(value) === "[object Array]"; | ||
} // https://github.com/jaywcjlove/store.js/pull/8 | ||
} | ||
// https://github.com/jaywcjlove/store.js/pull/8 | ||
// Error: QuotaExceededError | ||
|
||
|
||
function dealIncognito(storage) { | ||
var _KEY = '_Is_Incognit', | ||
_VALUE = 'yes'; | ||
|
||
_VALUE = 'yes'; | ||
try { | ||
storage.setItem(_KEY, _VALUE); | ||
} catch (e) { | ||
if (e.name === 'QuotaExceededError') { | ||
var _nothing = function _nothing() {}; | ||
|
||
storage.__proto__ = { | ||
setItem: _nothing, | ||
getItem: _nothing, | ||
|
@@ -68,29 +57,23 @@ function dealIncognito(storage) { | |
} finally { | ||
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY); | ||
} | ||
|
||
return storage; | ||
} // deal QuotaExceededError if user use incognito mode in browser | ||
|
||
} | ||
|
||
// deal QuotaExceededError if user use incognito mode in browser | ||
storage = dealIncognito(storage); | ||
|
||
function Store() { | ||
if (!(this instanceof Store)) { | ||
return new Store(); | ||
} | ||
} | ||
|
||
Store.prototype = { | ||
set: function set(key, val) { | ||
if (key && !isJSON(key)) { | ||
storage.setItem(key, stringify(val)); | ||
} else if (isJSON(key)) { | ||
for (var a in key) { | ||
this.set(a, key[a]); | ||
} | ||
for (var a in key) this.set(a, key[a]); | ||
} | ||
|
||
return this; | ||
}, | ||
get: function get(key) { | ||
|
@@ -101,27 +84,20 @@ Store.prototype = { | |
}); | ||
return ret; | ||
} | ||
|
||
if (key.charAt(0) === '?') { | ||
return this.has(key.substr(1)); | ||
} | ||
|
||
var args = arguments; | ||
|
||
if (args.length > 1) { | ||
var dt = {}; | ||
|
||
for (var i = 0, len = args.length; i < len; i++) { | ||
var value = deserialize(storage.getItem(args[i])); | ||
|
||
if (this.has(args[i])) { | ||
dt[args[i]] = value; | ||
} | ||
} | ||
|
||
return dt; | ||
} | ||
|
||
return deserialize(storage.getItem(key)); | ||
}, | ||
clear: function clear() { | ||
|
@@ -148,56 +124,44 @@ Store.prototype = { | |
var key = storage.key(i); | ||
callback(key, this.get(key)); | ||
} | ||
|
||
return this; | ||
}, | ||
search: function search(str) { | ||
var arr = this.keys(), | ||
dt = {}; | ||
|
||
dt = {}; | ||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i].indexOf(str) > -1) dt[arr[i]] = this.get(arr[i]); | ||
} | ||
|
||
return dt; | ||
} | ||
}; | ||
var _Store = null; | ||
|
||
function store(key, data) { | ||
var argm = arguments; | ||
var dt = null; | ||
if (!_Store) _Store = Store(); | ||
if (argm.length === 0) return _Store.get(); | ||
|
||
if (argm.length === 1) { | ||
if (typeof key === "string") return _Store.get(key); | ||
if (isJSON(key)) return _Store.set(key); | ||
} | ||
|
||
if (argm.length === 2 && typeof key === "string") { | ||
if (!data) return _Store.remove(key); | ||
if (data && typeof data === "string") return _Store.set(key, data); | ||
|
||
if (data && isFunction(data)) { | ||
dt = null; | ||
dt = data(key, _Store.get(key)); | ||
store.set(key, dt); | ||
} | ||
} | ||
|
||
if (argm.length === 2 && isArray(key) && isFunction(data)) { | ||
for (var i = 0, len = key.length; i < len; i++) { | ||
dt = data(key[i], _Store.get(key[i])); | ||
store.set(key[i], dt); | ||
} | ||
} | ||
|
||
return store; | ||
} | ||
|
||
for (var a in Store.prototype) { | ||
store[a] = Store.prototype[a]; | ||
} | ||
for (var a in Store.prototype) store[a] = Store.prototype[a]; | ||
|
||
module.exports = 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,61 +1,50 @@ | ||
/**! | ||
* storejs v2.0.0 | ||
* storejs v2.0.1 | ||
* Local storage localstorage package provides a simple API | ||
* | ||
* Copyright (c) 2021 kenny wang <[email protected]> | ||
* https://github.com/jaywcjlove/store.js | ||
* Copyright (c) 2023 kenny wang <[email protected]> | ||
* https://jaywcjlove.github.io/store.js/ | ||
* | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
var storage = window.localStorage; | ||
|
||
function isJSON(obj) { | ||
obj = JSON.stringify(obj); | ||
|
||
if (!/^\{[\s\S]*\}$/.test(obj)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
function stringify(val) { | ||
return val === undefined || typeof val === "function" ? val + '' : JSON.stringify(val); | ||
} | ||
|
||
function deserialize(value) { | ||
if (typeof value !== 'string') { | ||
return undefined; | ||
} | ||
|
||
try { | ||
return JSON.parse(value); | ||
} catch (e) { | ||
return value; | ||
} | ||
} | ||
|
||
function isFunction(value) { | ||
return {}.toString.call(value) === "[object Function]"; | ||
} | ||
|
||
function isArray(value) { | ||
return Object.prototype.toString.call(value) === "[object Array]"; | ||
} // https://github.com/jaywcjlove/store.js/pull/8 | ||
} | ||
// https://github.com/jaywcjlove/store.js/pull/8 | ||
// Error: QuotaExceededError | ||
|
||
|
||
function dealIncognito(storage) { | ||
var _KEY = '_Is_Incognit', | ||
_VALUE = 'yes'; | ||
|
||
_VALUE = 'yes'; | ||
try { | ||
storage.setItem(_KEY, _VALUE); | ||
} catch (e) { | ||
if (e.name === 'QuotaExceededError') { | ||
var _nothing = function _nothing() {}; | ||
|
||
storage.__proto__ = { | ||
setItem: _nothing, | ||
getItem: _nothing, | ||
|
@@ -66,29 +55,23 @@ function dealIncognito(storage) { | |
} finally { | ||
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY); | ||
} | ||
|
||
return storage; | ||
} // deal QuotaExceededError if user use incognito mode in browser | ||
|
||
} | ||
|
||
// deal QuotaExceededError if user use incognito mode in browser | ||
storage = dealIncognito(storage); | ||
|
||
function Store() { | ||
if (!(this instanceof Store)) { | ||
return new Store(); | ||
} | ||
} | ||
|
||
Store.prototype = { | ||
set: function set(key, val) { | ||
if (key && !isJSON(key)) { | ||
storage.setItem(key, stringify(val)); | ||
} else if (isJSON(key)) { | ||
for (var a in key) { | ||
this.set(a, key[a]); | ||
} | ||
for (var a in key) this.set(a, key[a]); | ||
} | ||
|
||
return this; | ||
}, | ||
get: function get(key) { | ||
|
@@ -99,27 +82,20 @@ Store.prototype = { | |
}); | ||
return ret; | ||
} | ||
|
||
if (key.charAt(0) === '?') { | ||
return this.has(key.substr(1)); | ||
} | ||
|
||
var args = arguments; | ||
|
||
if (args.length > 1) { | ||
var dt = {}; | ||
|
||
for (var i = 0, len = args.length; i < len; i++) { | ||
var value = deserialize(storage.getItem(args[i])); | ||
|
||
if (this.has(args[i])) { | ||
dt[args[i]] = value; | ||
} | ||
} | ||
|
||
return dt; | ||
} | ||
|
||
return deserialize(storage.getItem(key)); | ||
}, | ||
clear: function clear() { | ||
|
@@ -146,56 +122,44 @@ Store.prototype = { | |
var key = storage.key(i); | ||
callback(key, this.get(key)); | ||
} | ||
|
||
return this; | ||
}, | ||
search: function search(str) { | ||
var arr = this.keys(), | ||
dt = {}; | ||
|
||
dt = {}; | ||
for (var i = 0, len = arr.length; i < len; i++) { | ||
if (arr[i].indexOf(str) > -1) dt[arr[i]] = this.get(arr[i]); | ||
} | ||
|
||
return dt; | ||
} | ||
}; | ||
var _Store = null; | ||
|
||
function store(key, data) { | ||
var argm = arguments; | ||
var dt = null; | ||
if (!_Store) _Store = Store(); | ||
if (argm.length === 0) return _Store.get(); | ||
|
||
if (argm.length === 1) { | ||
if (typeof key === "string") return _Store.get(key); | ||
if (isJSON(key)) return _Store.set(key); | ||
} | ||
|
||
if (argm.length === 2 && typeof key === "string") { | ||
if (!data) return _Store.remove(key); | ||
if (data && typeof data === "string") return _Store.set(key, data); | ||
|
||
if (data && isFunction(data)) { | ||
dt = null; | ||
dt = data(key, _Store.get(key)); | ||
store.set(key, dt); | ||
} | ||
} | ||
|
||
if (argm.length === 2 && isArray(key) && isFunction(data)) { | ||
for (var i = 0, len = key.length; i < len; i++) { | ||
dt = data(key[i], _Store.get(key[i])); | ||
store.set(key[i], dt); | ||
} | ||
} | ||
|
||
return store; | ||
} | ||
|
||
for (var a in Store.prototype) { | ||
store[a] = Store.prototype[a]; | ||
} | ||
for (var a in Store.prototype) store[a] = Store.prototype[a]; | ||
|
||
export { store as default }; |
Oops, something went wrong.