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