forked from jaywcjlove/store.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.min.js
2 lines (2 loc) · 2.57 KB
/
store.min.js
1
2
/*! storejs v2.0.3 | MIT (c) 2023 kenny wang <[email protected]> | https://jaywcjlove.github.io/store.js/ */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).store=e()}(this,(function(){"use strict";function t(t){return t=JSON.stringify(t),!!/^\{[\s\S]*\}$/.test(t)}function e(t){if("string"==typeof t)try{return JSON.parse(t)}catch(e){return t}}function r(t){return"[object Function]"==={}.toString.call(t)}var n=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.localStorage,e="_Is_Incognit";try{t.setItem(e,"yes"),t.removeItem(e)}catch(e){Storage.prototype._data={},Storage.prototype.setItem=function(t,e){return this._data[t]=String(e)},Storage.prototype.getItem=function(t){return this._data.hasOwnProperty(t)?this._data[t]:void 0},Storage.prototype.removeItem=function(t){return delete this._data[t]},Storage.prototype.clear=function(){return this._data={}},t=Storage}finally{"yes"===t.getItem(e)&&t.removeItem(e)}return t}();function o(){if(!(this instanceof o))return new o}o.prototype={set:function(e,r){if(e&&!t(e))n.setItem(e,function(t){return void 0===t||"function"==typeof t?t+"":JSON.stringify(t)}(r));else if(t(e))for(var o in e)this.set(o,e[o]);return this},get:function(t){if(!t){var r={};return this.forEach((function(t,e){return r[t]=e})),r}if("?"===t.charAt(0))return this.has(t.substr(1));var o=arguments;if(o.length>1){for(var i={},f=0,u=o.length;f<u;f++){var s=e(n.getItem(o[f]));this.has(o[f])&&(i[o[f]]=s)}return i}return e(n.getItem(t))},clear:function(){return n.clear(),this},remove:function(t){var e=this.get(t);return n.removeItem(t),e},has:function(t){return{}.hasOwnProperty.call(this.get(),t)},keys:function(){var t=[];return this.forEach((function(e){t.push(e)})),t},forEach:function(t){for(var e=0,r=n.length;e<r;e++){var o=n.key(e);t(o,this.get(o))}return this},search:function(t){for(var e=this.keys(),r={},n=0,o=e.length;n<o;n++)e[n].indexOf(t)>-1&&(r[e[n]]=this.get(e[n]));return r}};var i=null;function f(e,n){var u,s=arguments,a=null;if(i||(i=o()),0===s.length)return i.get();if(1===s.length){if("string"==typeof e)return i.get(e);if(t(e))return i.set(e)}if(2===s.length&&"string"==typeof e){if(!n)return i.remove(e);if(n&&"string"==typeof n)return i.set(e,n);n&&r(n)&&(a=null,a=n(e,i.get(e)),f.set(e,a))}if(2===s.length&&(u=e,"[object Array]"===Object.prototype.toString.call(u))&&r(n))for(var c=0,h=e.length;c<h;c++)a=n(e[c],i.get(e[c])),f.set(e[c],a);return f}for(var u in o.prototype)f[u]=o.prototype[u];return f}));