storage.min.js 1.3 KB

12345
  1. /**
  2. * good-storage v1.1.1
  3. * (c) 2020 ustbhuangyi
  4. */
  5. !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Storage=e()}(this,function(){"use strict";var t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t},e="undefined"==typeof window,r={version:"1.1.1",storage:e?null:window.localStorage,session:{storage:e?null:window.sessionStorage}},i={set:function(t,e){var r;if(!this.disabled)return void 0===e?this.remove(t):(this.storage.setItem(t,(r=e,JSON.stringify(r))),e)},get:function(t,e){if(this.disabled)return e;var r=function(e){if("string"!=typeof e)return;try{return JSON.parse(e)}catch(t){return e||void 0}}(this.storage.getItem(t));return void 0===r?e:r},has:function(t){return void 0!==this.get(t)},remove:function(t){this.disabled||this.storage.removeItem(t)},clear:function(){this.disabled||this.storage.clear()},getAll:function(){if(this.disabled)return null;var r={};return this.forEach(function(t,e){r[t]=e}),r},forEach:function(t){if(!this.disabled)for(var e=0;e<this.storage.length;e++){var r=this.storage.key(e);t(r,this.get(r))}}};t(r,i),t(r.session,i);try{var n="__storejs__";r.set(n,n),r.get(n)!==n&&(r.disabled=!0),r.remove(n)}catch(t){r.disabled=!0}return r});