-
Notifications
You must be signed in to change notification settings - Fork 0
/
persistme.min.js
6 lines (6 loc) · 8.78 KB
/
persistme.min.js
1
2
3
4
5
6
/*!
* Copyright (c) Emad Alam https://emad.in
* https://github.com/mesmerised/persistme
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("persistme",[],t):"object"==typeof exports?exports.persistme=t():e.persistme=t()}(window,function(){return function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},r.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([function(e,t,r){var o,n=function(){var e=String.fromCharCode,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",o={};function n(e,t){if(!o[e]){o[e]={};for(var r=0;r<e.length;r++)o[e][e.charAt(r)]=r}return o[e][t]}var i={compressToBase64:function(e){if(null==e)return"";var r=i._compress(e,6,function(e){return t.charAt(e)});switch(r.length%4){default:case 0:return r;case 1:return r+"===";case 2:return r+"==";case 3:return r+"="}},decompressFromBase64:function(e){return null==e?"":""==e?null:i._decompress(e.length,32,function(r){return n(t,e.charAt(r))})},compressToUTF16:function(t){return null==t?"":i._compress(t,15,function(t){return e(t+32)})+" "},decompressFromUTF16:function(e){return null==e?"":""==e?null:i._decompress(e.length,16384,function(t){return e.charCodeAt(t)-32})},compressToUint8Array:function(e){for(var t=i.compress(e),r=new Uint8Array(2*t.length),o=0,n=t.length;o<n;o++){var u=t.charCodeAt(o);r[2*o]=u>>>8,r[2*o+1]=u%256}return r},decompressFromUint8Array:function(t){if(null===t||void 0===t)return i.decompress(t);for(var r=new Array(t.length/2),o=0,n=r.length;o<n;o++)r[o]=256*t[2*o]+t[2*o+1];var u=[];return r.forEach(function(t){u.push(e(t))}),i.decompress(u.join(""))},compressToEncodedURIComponent:function(e){return null==e?"":i._compress(e,6,function(e){return r.charAt(e)})},decompressFromEncodedURIComponent:function(e){return null==e?"":""==e?null:(e=e.replace(/ /g,"+"),i._decompress(e.length,32,function(t){return n(r,e.charAt(t))}))},compress:function(t){return i._compress(t,16,function(t){return e(t)})},_compress:function(e,t,r){if(null==e)return"";var o,n,i,u={},a={},s="",c="",f="",l=2,p=3,d=2,h=[],v=0,y=0;for(i=0;i<e.length;i+=1)if(s=e.charAt(i),Object.prototype.hasOwnProperty.call(u,s)||(u[s]=p++,a[s]=!0),c=f+s,Object.prototype.hasOwnProperty.call(u,c))f=c;else{if(Object.prototype.hasOwnProperty.call(a,f)){if(f.charCodeAt(0)<256){for(o=0;o<d;o++)v<<=1,y==t-1?(y=0,h.push(r(v)),v=0):y++;for(n=f.charCodeAt(0),o=0;o<8;o++)v=v<<1|1&n,y==t-1?(y=0,h.push(r(v)),v=0):y++,n>>=1}else{for(n=1,o=0;o<d;o++)v=v<<1|n,y==t-1?(y=0,h.push(r(v)),v=0):y++,n=0;for(n=f.charCodeAt(0),o=0;o<16;o++)v=v<<1|1&n,y==t-1?(y=0,h.push(r(v)),v=0):y++,n>>=1}0==--l&&(l=Math.pow(2,d),d++),delete a[f]}else for(n=u[f],o=0;o<d;o++)v=v<<1|1&n,y==t-1?(y=0,h.push(r(v)),v=0):y++,n>>=1;0==--l&&(l=Math.pow(2,d),d++),u[c]=p++,f=String(s)}if(""!==f){if(Object.prototype.hasOwnProperty.call(a,f)){if(f.charCodeAt(0)<256){for(o=0;o<d;o++)v<<=1,y==t-1?(y=0,h.push(r(v)),v=0):y++;for(n=f.charCodeAt(0),o=0;o<8;o++)v=v<<1|1&n,y==t-1?(y=0,h.push(r(v)),v=0):y++,n>>=1}else{for(n=1,o=0;o<d;o++)v=v<<1|n,y==t-1?(y=0,h.push(r(v)),v=0):y++,n=0;for(n=f.charCodeAt(0),o=0;o<16;o++)v=v<<1|1&n,y==t-1?(y=0,h.push(r(v)),v=0):y++,n>>=1}0==--l&&(l=Math.pow(2,d),d++),delete a[f]}else for(n=u[f],o=0;o<d;o++)v=v<<1|1&n,y==t-1?(y=0,h.push(r(v)),v=0):y++,n>>=1;0==--l&&(l=Math.pow(2,d),d++)}for(n=2,o=0;o<d;o++)v=v<<1|1&n,y==t-1?(y=0,h.push(r(v)),v=0):y++,n>>=1;for(;;){if(v<<=1,y==t-1){h.push(r(v));break}y++}return h.join("")},decompress:function(e){return null==e?"":""==e?null:i._decompress(e.length,32768,function(t){return e.charCodeAt(t)})},_decompress:function(t,r,o){var n,i,u,a,s,c,f,l=[],p=4,d=4,h=3,v="",y=[],m={val:o(0),position:r,index:1};for(n=0;n<3;n+=1)l[n]=n;for(u=0,s=Math.pow(2,2),c=1;c!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=o(m.index++)),u|=(a>0?1:0)*c,c<<=1;switch(u){case 0:for(u=0,s=Math.pow(2,8),c=1;c!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=o(m.index++)),u|=(a>0?1:0)*c,c<<=1;f=e(u);break;case 1:for(u=0,s=Math.pow(2,16),c=1;c!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=o(m.index++)),u|=(a>0?1:0)*c,c<<=1;f=e(u);break;case 2:return""}for(l[3]=f,i=f,y.push(f);;){if(m.index>t)return"";for(u=0,s=Math.pow(2,h),c=1;c!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=o(m.index++)),u|=(a>0?1:0)*c,c<<=1;switch(f=u){case 0:for(u=0,s=Math.pow(2,8),c=1;c!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=o(m.index++)),u|=(a>0?1:0)*c,c<<=1;l[d++]=e(u),f=d-1,p--;break;case 1:for(u=0,s=Math.pow(2,16),c=1;c!=s;)a=m.val&m.position,m.position>>=1,0==m.position&&(m.position=r,m.val=o(m.index++)),u|=(a>0?1:0)*c,c<<=1;l[d++]=e(u),f=d-1,p--;break;case 2:return y.join("")}if(0==p&&(p=Math.pow(2,h),h++),l[f])v=l[f];else{if(f!==d)return null;v=i+i.charAt(0)}y.push(v),l[d++]=i+v.charAt(0),i=v,0==--p&&(p=Math.pow(2,h),h++)}}};return i}();void 0===(o=function(){return n}.call(t,r,t,e))||(e.exports=o)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.isValid=function(e){return void 0!==e&&null!==e}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o,n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}(),a=r(0),s=(o=a)&&o.__esModule?o:{default:o},c=r(1);function f(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var l=s.default.compress,p=s.default.decompress,d=new WeakMap,h=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),d.set(this,t)}return u(e,[{key:"getKey",value:function(e){return d.get(this).appName+"."+e}},{key:"set",value:function(e,t){var r=this.getKey(e);try{var o=JSON.stringify(t);void 0!==o&&localStorage.setItem(r,l(o))}catch(t){console.warn("something went wrong while trying to store value for "+e+".",t)}}},{key:"get",value:function(e){var t=this.getKey(e),r=localStorage.getItem(t);if(!(0,c.isValid)(r)){var o=d.get(this).defaults;return(void 0===o?{}:o)[e]}var n=p(r),i=void 0;try{i=JSON.parse(n)}catch(e){i=n}return i}},{key:"update",value:function(e,t){var r=this.get(e);(0,c.isValid)(r)?Array.isArray(r)&&Array.isArray(t)?this.set(e,[].concat(f(r),f(t))):"object"===(void 0===r?"undefined":i(r))&&"object"===(void 0===t?"undefined":i(t))?this.set(e,n({},r,t)):this.set(e,t):this.set(e,t)}},{key:"remove",value:function(e){var t=this;Array.isArray(e)||(e=[e]),e.forEach(function(e){return localStorage.removeItem(t.getKey(e))})}}]),e}();t.default=h},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.storage,r=void 0===t?{}:t,n=e.defaults,i=void 0===n?{}:n,u=e.configs,a=void 0===u?{}:u;if("function"!=typeof r.get||"function"!=typeof r.set)throw new TypeError("storage object should implement `get` and `set` methods.");return new Proxy({},{get:function(e,t){return function(e,t,r,n){var i=e.get(r[t]||t);if(!(0,o.isValid)(i))return n[t];return i}(r,t,a,i)},set:function(e,t,o){return function(e,t,r,o){e.set(o[t]||t,r)}(r,t,o,a),!0}})};var o=r(1)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.LZString=t.createSetting=void 0,t.createStorage=function(e,t){if(void 0===e)throw new TypeError("`appName` is required to initialize the storage");if("string"!=typeof e)throw new TypeError("`appName` should be a string");return new i.default({appName:e,defaults:t})};var o=r(3);Object.defineProperty(t,"createSetting",{enumerable:!0,get:function(){return u(o).default}});var n=r(0);Object.defineProperty(t,"LZString",{enumerable:!0,get:function(){return u(n).default}});var i=u(r(2));function u(e){return e&&e.__esModule?e:{default:e}}}])});
//# sourceMappingURL=persistme.min.js.map