UNPKG

biruni

Version:

(Al-Biruni) Unified All-in-One Storage Utilities

1 lines 8.98 kB
!function(t,e){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}var s=n(e);var i,r=(t,e,n)=>new Promise(((s,i)=>{var r=t=>{try{o(n.next(t))}catch(t){i(t)}},a=t=>{try{o(n.throw(t))}catch(t){i(t)}},o=t=>t.done?s(t.value):Promise.resolve(t.value).then(r,a);o((n=n.apply(t,e)).next())})),a=class{constructor(){this.preprocess=t=>r(this,null,(function*(){return t})),this.postprocess=t=>r(this,null,(function*(){return t}))}get namespace(){return this._namespace}set namespace(t){this._namespace=t}},o=(t,e,n)=>new Promise(((s,i)=>{var r=t=>{try{o(n.next(t))}catch(t){i(t)}},a=t=>{try{o(n.throw(t))}catch(t){i(t)}},o=t=>t.done?s(t.value):Promise.resolve(t.value).then(r,a);o((n=n.apply(t,e)).next())})),c=(t,e)=>o(void 0,null,(function*(){let n=t;for(const t of e)"persister"===t.type&&(n=yield t.preprocess(n));for(const t of e)"parser"===t.type&&(n=yield t.preprocess(n));for(const t of e)"validator"===t.type&&(n=yield t.preprocess(n));for(const t of e)"synchronizer"===t.type&&(n=yield t.preprocess(n));return n})),l=(t,e)=>o(void 0,null,(function*(){let n=t;for(const t of e)"validator"===t.type&&(n=yield t.postprocess(n));for(const t of e)"synchronizer"===t.type&&(n=yield t.postprocess(n));for(const t of e)"parser"===t.type&&(n=yield t.postprocess(n));for(const t of e)"persister"===t.type&&(n=yield t.postprocess(n));return n})),h=(t,e,n)=>{if(!e.has(t))throw TypeError("Cannot "+n)},u=(t,e,n)=>(h(t,e,"read from private field"),n?n.call(t):e.get(t)),p=class extends a{constructor(){var t,e,n;super(),((t,e,n)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,void 0)})(this,i),this.type="synchronizer",this.name="built-in/event-emitter",this.addListener=(t,e)=>{u(this,i).addListener(t,e)},this.removeListener=(t,e)=>{u(this,i).removeListener(t,e)},this.postprocess=t=>{return e=this,null,n=function*(){return u(this,i).emit("change",function(t,e){let n={},s=[];for(const i in e){const r=null==t?void 0:t[i],a=e[i];r!==a&&(n=Object.assign({},n,{[i]:{source:r,target:a}}),s=s.concat(i))}return{source:t,target:e,keys:s,diff:n}}({},t)),t},new Promise(((t,s)=>{var i=t=>{try{a(n.next(t))}catch(t){s(t)}},r=t=>{try{a(n.throw(t))}catch(t){s(t)}},a=e=>e.done?t(e.value):Promise.resolve(e.value).then(i,r);a((n=n.apply(e,null)).next())}));var e,n},t=this,e=i,n=new s.default,h(t,e,"write to private field"),e.set(t,n)}};i=new WeakMap,t.event=()=>new p;var f=(t,e,n)=>new Promise(((s,i)=>{var r=t=>{try{o(n.next(t))}catch(t){i(t)}},a=t=>{try{o(n.throw(t))}catch(t){i(t)}},o=t=>t.done?s(t.value):Promise.resolve(t.value).then(r,a);o((n=n.apply(t,e)).next())})),d=class extends a{constructor(){super(),this.type="parser",this.name="built-in/json",this.preprocess=t=>f(this,null,(function*(){return t?JSON.parse(t):t})),this.postprocess=t=>f(this,null,(function*(){return JSON.stringify(null!=t?t:{})}))}};t.json=()=>new d;var y=(t,e,n)=>new Promise(((s,i)=>{var r=t=>{try{o(n.next(t))}catch(t){i(t)}},a=t=>{try{o(n.throw(t))}catch(t){i(t)}},o=t=>t.done?s(t.value):Promise.resolve(t.value).then(r,a);o((n=n.apply(t,e)).next())})),v=class extends a{constructor(){super(),this.type="persister",this.name="built-in/localStorage",this.preprocess=()=>y(this,null,(function*(){return localStorage.getItem(this.namespace)})),this.postprocess=t=>y(this,null,(function*(){if("string"!=typeof t)throw"Error: <postprocess> in <built-in/localStorage>"+this.namespace;return localStorage.setItem(this.namespace,t),t}))}};t.localstorage=()=>new v;var g=t=>Object.assign({},JSON.parse(JSON.stringify({cloned:t})).cloned),m=t=>Array.from(Object.keys(t)),S=t=>!("object"!=typeof t||null===t||t instanceof Array&&!1!==Array.isArray(t)),w=(...t)=>Object.assign({},...t),b=Object.hasOwn;function k(t,e){const n=w(t),s=w(e);let i=w(n);const r=m(i),a=m(s);return 0===a.length||(r.forEach((t=>{if(!1===b(s,t))delete i[t],i=w(i);else if(S(i[t])){const e=s[t];i=S(e)?w(i,{[t]:k(i[t],e)}):w(i,{[t]:e})}else{const e=s[t];i=S(e)?w(i,{[t]:e}):w(i,{[t]:i[t]})}})),a.forEach((t=>{!0!==b(i,t)&&(i=w(i,{[t]:s[t]}))}))),i}var B;var O=(t,e,n)=>{if(!e.has(t))throw TypeError("Cannot "+n)},j=(t,e,n)=>new Promise(((s,i)=>{var r=t=>{try{o(n.next(t))}catch(t){i(t)}},a=t=>{try{o(n.throw(t))}catch(t){i(t)}},o=t=>t.done?s(t.value):Promise.resolve(t.value).then(r,a);o((n=n.apply(t,e)).next())}));function P(e){return new t.Biruni(e)}t.Store=class{constructor(t,e){this.pluginStack=e,((t,e,n)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,void 0)})(this,B),this.has=t=>{var e,n,s,i,r;return!!(null==(e=Object.prototype.hasOwnProperty)?void 0:e.call(this.data,t))||!!(null==(n=Object.hasOwnProperty)?void 0:n.call(this.data,t))||-1!=(null==(i=null==(s=Object.keys)?void 0:s.call(Object,this.data))?void 0:i.indexOf(t))||!!(null==(r=Object.hasOwn)?void 0:r.call(Object,this.data,t))||t in this.data},this.get=(t,e)=>j(this,null,(function*(){if(null==(n=t)||!1===Boolean(n))return this.getByEntire();var n,s;if((t=>"string"==typeof t)(t)){if((t=>"function"==typeof t)(e))return this.getByKeyMapper(t,e);if((t=>null==t||!1===Boolean(t))(e))return this.getByKey(t);throw"Store.get not match to any overloads (+6)"}if((t=>"function"==typeof t)(t))return this.getByMapper(t);if("object"==typeof(s=t)&&null!==s&&(s instanceof Array||Array.isArray(s)))return this.getByKeys(t);if((t=>"object"==typeof t&&null!==t)(t))return this.getByTruthy(t);throw"Store.get not match to any overlaods (+6)"})),this.getByEntire=()=>j(this,null,(function*(){return this.data=yield c(this.data,this.pluginStack),function(t){return g(t)}(this.data)})),this.getByKey=t=>j(this,null,(function*(){return this.data=yield c(this.data,this.pluginStack),function(t,e){return t[e]}(this.data,t)})),this.getByKeyMapper=(t,e)=>j(this,null,(function*(){return this.data=yield c(this.data,this.pluginStack),function(t,e,n){return n(t[e])}(this.data,t,e)})),this.getByKeys=t=>j(this,null,(function*(){return this.data=yield c(this.data,this.pluginStack),function(t,e){return e.reduce(((e,n)=>Object.assign({},e,{[n]:t[n]})),{})}(this.data,t)})),this.getByMapper=t=>j(this,null,(function*(){return this.data=yield c(this.data,this.pluginStack),function(t,e){return e(t)}(this.data,t)})),this.getByTruthy=t=>j(this,null,(function*(){return this.data=yield c(this.data,this.pluginStack),function(t,e){let n={};for(const s in e)!0===e[s]&&(n=Object.assign({},n,{[s]:t[string&s]}));return n}(this.data,t)})),this.set=(t,e)=>j(this,null,(function*(){if(!(t=>"string"==typeof t)(t)){if("function"==typeof t)return this.setBySetter(t);if((t=>"object"==typeof t&&null!==t)(t))return this.setByPair(t);throw"Store.set not match to any overlaods (+4)"}return(t=>"function"==typeof t)(e)?this.setByKeySetter(t,e):this.setByKeyValue(t,e)})),this.setByKeySetter=(t,e)=>j(this,null,(function*(){this.data=function(t,e,n){const s=g(t),i=s[e];return Object.assign({},s,{[e]:n(i)})}(this.data,t,e),yield l(this.data,this.pluginStack)})),this.setByKeyValue=(t,e)=>j(this,null,(function*(){this.data=function(t,e,n){const s=g(t);return Object.assign({},s,{[e]:n})}(this.data,t,e),yield l(this.data,this.pluginStack)})),this.setByPair=t=>j(this,null,(function*(){this.data=function(t,e){const n=g(t),s=g(e);return Object.assign({},n,s)}(this.data,t),yield l(this.data,this.pluginStack)})),this.setBySetter=t=>j(this,null,(function*(){this.data=function(t,e){const n=g(t);return Object.assign({},n,e(n))}(this.data,t),yield l(this.data,this.pluginStack)})),this.setByEntire=t=>j(this,null,(function*(){this.data=t,yield l(this.data,this.pluginStack)})),this.addListener=(t,e)=>{for(const n of this.pluginStack)"addListener"in n&&"function"==typeof n.addListener&&n.addListener.call(this,t,e)},this.on=(t,e)=>{for(const n of this.pluginStack)"addListener"in n&&"function"==typeof n.addListener&&n.addListener.call(this,t,e)},this.removeListener=(t,e)=>{for(const n of this.pluginStack)"removeListener"in n&&"function"==typeof n.removeListener&&n.removeListener.call(this,t,e)},this.off=(t,e)=>{for(const n of this.pluginStack)"removeListener"in n&&"function"==typeof n.removeListener&&n.removeListener.call(this,t,e)},this.get().then((e=>{const n=k(e,t());this.setByEntire(n)}))}get data(){return g((O(this,t=B,"read from private field"),t.get(this)));var t}set data(t){var e,n;n=t,O(this,e=B,"write to private field"),e.set(this,n)}},B=new WeakMap,t.Biruni=class e{constructor(t,n){this.namespace=t,this.pluginStack=n,this.plug=t=>{let n=t;return"object"!=typeof t||null===t||t instanceof Array&&!1!==Array.isArray(t)||(n=[t]),n=n.map((t=>(t.namespace=this.namespace,t))),new e(this.namespace,this.pluginStack.concat(n))},this.pluginStack=[].concat(null!=n?n:[])}init(e){return new t.Store(e,this.pluginStack)}},t.EventEmitterPlugin=t.event,t.JsonPlugin=t.json,t.LocalStoragePlugin=t.localstorage,t.biruni=P,t.default=P,t.defineBiruni=P,Object.defineProperty(t,"__esModule",{value:!0})}({},r2);//# sourceMappingURL=mod.global.js.map