@belloai/ls
Version:
base64 的Local Storage
8 lines (7 loc) • 1.92 kB
JavaScript
;var e=require("@babel/runtime/helpers/classCallCheck"),t=require("@babel/runtime/helpers/createClass"),a=require("@babel/runtime/helpers/defineProperty"),r=require("store"),u=require("js-base64");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(e),l=n(t),i=n(a),o=n(r),f=function(){function e(t){s.default(this,e),i.default(this,"notClearKeys",[]),i.default(this,"passLocalStorageB64Key","passLocalStorageB64"),i.default(this,"isBase64",!0);var a=t||{},r=a.notClearKeys,u=a.isBase64,n=void 0===u||u;this.notClearKeys=r||[],this.isBase64=n}return l.default(e,[{key:"get",value:function(e){return this.b64ToUtf8(o.default.get(e))}},{key:"remove",value:function(e){o.default.remove(e)}},{key:"set",value:function(e,t){return o.default.set(e,this.utf8ToB64(t))}},{key:"clear",value:function(){o.default.clearAll()}},{key:"getKeys",value:function(){var e=[];return o.default.each((function(t,a){e.push(a)})),e}},{key:"clearAllExcept",value:function(e){var t=[];"string"==typeof e?t.push({key:e,val:o.default.get(e)}):Array.isArray(e)?e.forEach((function(e){t.push({key:e,val:o.default.get(e)})})):this.notClearKeys.forEach((function(e){t.push({key:e,val:o.default.get(e)})})),o.default.clearAll(),t.forEach((function(e){e.val&&o.default.set(e.key,e.val)}))}},{key:"b64ToUtf8",value:function(e){var t=e;try{t=decodeURIComponent(escape(u.decode(e)))}catch(e){}try{return JSON.parse(t)}catch(e){}return t}},{key:"utf8ToB64",value:function(e){if(!this.isPass())try{return u.encode(unescape(encodeURIComponent(JSON.stringify(e))))}catch(e){}return e}},{key:"isPass",value:function(){return!!o.default.get(this.passLocalStorageB64Key)||!this.isBase64}}]),e}();module.exports=f,"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.common.js.map