UNPKG

whstorage

Version:

whSotorage is a way to encrypt localSotage

3 lines 1.14 kB
var $jscomp$this=this;"use strict";if("undefined"===typeof sjcl)throw Error("SJCL Encrypter lib is required!!! Download at: http://bitwiseshiftleft.github.io/sjcl/sjcl.js"); var whStorage={options:{key:"",prefix:""},set:function(a,b){var c=whStorage.encrypte(whStorage.getOptions().key,JSON.stringify(b));return localStorage.setItem(whStorage.defineSection(a),c)},defineSection:function(a){return whStorage.getOptions().prefix.concat(a)},get:function(a){return JSON.parse(whStorage.decrypte(whStorage.getOptions().key,localStorage.getItem(whStorage.defineSection(a))))},claer:function(){return localStorage.clear()},init:function(a){$jscomp$this.key=a.key;$jscomp$this.prefix= a.prefix;if(void 0===$jscomp$this.key)throw Error("whStorageErr: Crypting key not found!");void 0!==a.key&&(whStorage.options.key=$jscomp$this.key);void 0!==a.prefix&&(whStorage.options.prefix=$jscomp$this.prefix)},getOptions:function(){return void 0!==whStorage.options.prefix||null!==whStorage.options.prefix?whStorage.options:whStorage.options.key},encrypte:function(a,b){if(void 0!==a)return sjcl.encrypt(a,b)},decrypte:function(a,b){return sjcl.decrypt(a,b)}};