UNPKG

@belloai/ls

Version:
8 lines (7 loc) 1.7 kB
import e from"@babel/runtime/helpers/classCallCheck";import t from"@babel/runtime/helpers/createClass";import r from"@babel/runtime/helpers/defineProperty";import a from"store";import{decode as s,encode as n}from"js-base64";var o=function(){function o(t){e(this,o),r(this,"notClearKeys",[]),r(this,"passLocalStorageB64Key","passLocalStorageB64"),r(this,"isBase64",!0);var a=t||{},s=a.notClearKeys,n=a.isBase64,i=void 0===n||n;this.notClearKeys=s||[],this.isBase64=i}return t(o,[{key:"get",value:function(e){return this.b64ToUtf8(a.get(e))}},{key:"remove",value:function(e){a.remove(e)}},{key:"set",value:function(e,t){return a.set(e,this.utf8ToB64(t))}},{key:"clear",value:function(){a.clearAll()}},{key:"getKeys",value:function(){var e=[];return a.each((function(t,r){e.push(r)})),e}},{key:"clearAllExcept",value:function(e){var t=[];"string"==typeof e?t.push({key:e,val:a.get(e)}):Array.isArray(e)?e.forEach((function(e){t.push({key:e,val:a.get(e)})})):this.notClearKeys.forEach((function(e){t.push({key:e,val:a.get(e)})})),a.clearAll(),t.forEach((function(e){e.val&&a.set(e.key,e.val)}))}},{key:"b64ToUtf8",value:function(e){var t=e;try{t=decodeURIComponent(escape(s(e)))}catch(e){}try{return JSON.parse(t)}catch(e){}return t}},{key:"utf8ToB64",value:function(e){if(!this.isPass())try{return n(unescape(encodeURIComponent(JSON.stringify(e))))}catch(e){}return e}},{key:"isPass",value:function(){return!!a.get(this.passLocalStorageB64Key)||!this.isBase64}}]),o}();export{o as default};"undefined"!=typeof window&&(window.pgk__belloai_ls_version="0.0.1") /*! * @belloai/ls v0.0.1 * (c) 2021 thomas-ballo <liurongliang@balloai.com> * @license MIT */; //# sourceMappingURL=index.esm.js.map