@biruni/capacitor-preferences
Version:
(Al-Biruni) @capacitor/preferences utility
7 lines (6 loc) • 13.1 kB
JavaScript
!function(e){"use strict";var t,n,r,i,s,o,a,l,c,u,d,p,f,h,m,g,v,w,y=Object.defineProperty,b=Object.getOwnPropertyNames,P=(e,t)=>function(){return e&&(t=(0,e[b(e)[0]])(e=0)),t},E=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},x=(e,t,n)=>new Promise(((r,i)=>{var s=e=>{try{a(n.next(e))}catch(e){i(e)}},o=e=>{try{a(n.throw(e))}catch(e){i(e)}},a=e=>e.done?r(e.value):Promise.resolve(e.value).then(s,o);a((n=n.apply(e,t)).next())})),L=P({"node_modules/.pnpm/@capacitor+core@6.0.0/node_modules/@capacitor/core/dist/index.js"(){var e;t=e=>{const t=new Map;t.set("web",{name:"web"});const n=e.CapacitorPlatforms||{currentPlatform:{name:"web"},platforms:t};return n.addPlatform=(e,t)=>{n.platforms.set(e,t)},n.setPlatform=e=>{n.platforms.has(e)&&(n.currentPlatform=n.platforms.get(e))},n},(n=(e=>e.CapacitorPlatforms=t(e))("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{})).addPlatform,n.setPlatform,(e=r||(r={})).Unimplemented="UNIMPLEMENTED",e.Unavailable="UNAVAILABLE",i=class extends Error{constructor(e,t,n){super(e),this.message=e,this.code=t,this.data=n}},s=e=>{var t,n;return(null==e?void 0:e.androidBridge)?"android":(null===(n=null===(t=null==e?void 0:e.webkit)||void 0===t?void 0:t.messageHandlers)||void 0===n?void 0:n.bridge)?"ios":"web"},o=e=>{var t,n,o,a,l;const c=e.CapacitorCustomPlatform||null,u=e.Capacitor||{},d=u.Plugins=u.Plugins||{},p=e.CapacitorPlatforms,f=(null===(t=null==p?void 0:p.currentPlatform)||void 0===t?void 0:t.getPlatform)||(()=>null!==c?c.name:s(e)),h=(null===(n=null==p?void 0:p.currentPlatform)||void 0===n?void 0:n.isNativePlatform)||(()=>"web"!==f()),m=(null===(o=null==p?void 0:p.currentPlatform)||void 0===o?void 0:o.isPluginAvailable)||(e=>{const t=v.get(e);return!!(null==t?void 0:t.platforms.has(f()))||!!g(e)}),g=(null===(a=null==p?void 0:p.currentPlatform)||void 0===a?void 0:a.getPluginHeader)||(e=>{var t;return null===(t=u.PluginHeaders)||void 0===t?void 0:t.find((t=>t.name===e))}),v=new Map,w=(null===(l=null==p?void 0:p.currentPlatform)||void 0===l?void 0:l.registerPlugin)||((e,t={})=>{const n=v.get(e);if(n)return console.warn(`Capacitor plugin "${e}" already registered. Cannot register plugins twice.`),n.proxy;const s=f(),o=g(e);let a;const l=n=>{let l;const d=(...d)=>{const p=x(void 0,null,(function*(){return!a&&s in t?a=a="function"==typeof t[s]?yield t[s]():t[s]:null!==c&&!a&&"web"in t&&(a=a="function"==typeof t.web?yield t.web():t.web),a})).then((t=>{const a=((t,n)=>{var a,l;if(!o){if(t)return null===(l=t[n])||void 0===l?void 0:l.bind(t);throw new i(`"${e}" plugin is not implemented on ${s}`,r.Unimplemented)}{const r=null==o?void 0:o.methods.find((e=>n===e.name));if(r)return"promise"===r.rtype?t=>u.nativePromise(e,n.toString(),t):(t,r)=>u.nativeCallback(e,n.toString(),t,r);if(t)return null===(a=t[n])||void 0===a?void 0:a.bind(t)}})(t,n);if(a){const e=a(...d);return l=null==e?void 0:e.remove,e}throw new i(`"${e}.${n}()" is not implemented on ${s}`,r.Unimplemented)}));return"addListener"===n&&(p.remove=()=>x(void 0,null,(function*(){return l()}))),p};return d.toString=()=>`${n.toString()}() { [capacitor code] }`,Object.defineProperty(d,"name",{value:n,writable:!1,configurable:!1}),d},p=l("addListener"),h=l("removeListener"),m=(e,t)=>{const n=p({eventName:e},t),r=()=>x(void 0,null,(function*(){const r=yield n;h({eventName:e,callbackId:r},t)})),i=new Promise((e=>n.then((()=>e({remove:r})))));return i.remove=()=>x(void 0,null,(function*(){console.warn("Using addListener() without 'await' is deprecated."),yield r()})),i},w=new Proxy({},{get(e,t){switch(t){case"$$typeof":return;case"toJSON":return()=>({});case"addListener":return o?m:p;case"removeListener":return h;default:return l(t)}}});return d[e]=w,v.set(e,{name:e,proxy:w,platforms:new Set([...Object.keys(t),...o?[s]:[]])}),w});return u.convertFileSrc||(u.convertFileSrc=e=>e),u.getPlatform=f,u.handleError=t=>e.console.error(t),u.isNativePlatform=h,u.isPluginAvailable=m,u.pluginMethodNoop=(e,t,n)=>Promise.reject(`${n} does not have an implementation of "${t}".`),u.registerPlugin=w,u.Exception=i,u.DEBUG=!!u.DEBUG,u.isLoggingEnabled=!!u.isLoggingEnabled,u.platform=u.getPlatform(),u.isNative=u.isNativePlatform(),u},a=(e=>e.Capacitor=o(e))("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}),l=a.registerPlugin,a.Plugins,c=class{constructor(e){this.listeners={},this.retainedEventArguments={},this.windowListeners={},e&&(console.warn(`Capacitor WebPlugin "${e.name}" config object was deprecated in v3 and will be removed in v4.`),this.config=e)}addListener(e,t){let n=!1;this.listeners[e]||(this.listeners[e]=[],n=!0),this.listeners[e].push(t);const r=this.windowListeners[e];r&&!r.registered&&this.addWindowListener(r),n&&this.sendRetainedArgumentsForEvent(e);return Promise.resolve({remove:()=>x(this,null,(function*(){return this.removeListener(e,t)}))})}removeAllListeners(){return x(this,null,(function*(){this.listeners={};for(const e in this.windowListeners)this.removeWindowListener(this.windowListeners[e]);this.windowListeners={}}))}notifyListeners(e,t,n){const r=this.listeners[e];if(r)r.forEach((e=>e(t)));else if(n){let n=this.retainedEventArguments[e];n||(n=[]),n.push(t),this.retainedEventArguments[e]=n}}hasListeners(e){return!!this.listeners[e].length}registerWindowListener(e,t){this.windowListeners[t]={registered:!1,windowEventName:e,pluginEventName:t,handler:e=>{this.notifyListeners(t,e)}}}unimplemented(e="not implemented"){return new a.Exception(e,r.Unimplemented)}unavailable(e="not available"){return new a.Exception(e,r.Unavailable)}removeListener(e,t){return x(this,null,(function*(){const n=this.listeners[e];if(!n)return;const r=n.indexOf(t);this.listeners[e].splice(r,1),this.listeners[e].length||this.removeWindowListener(this.windowListeners[e])}))}addWindowListener(e){window.addEventListener(e.windowEventName,e.handler),e.registered=!0}removeWindowListener(e){e&&(window.removeEventListener(e.windowEventName,e.handler),e.registered=!1)}sendRetainedArgumentsForEvent(e){const t=this.retainedEventArguments[e];t&&(delete this.retainedEventArguments[e],t.forEach((t=>{this.notifyListeners(e,t)})))}},u=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),d=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent),p=class extends c{getCookies(){return x(this,null,(function*(){const e=document.cookie,t={};return e.split(";").forEach((e=>{if(e.length<=0)return;let[n,r]=e.replace(/=/,"CAP_COOKIE").split("CAP_COOKIE");n=d(n).trim(),r=d(r).trim(),t[n]=r})),t}))}setCookie(e){return x(this,null,(function*(){try{const t=u(e.key),n=u(e.value),r=`; expires=${(e.expires||"").replace("expires=","")}`,i=(e.path||"/").replace("path=",""),s=null!=e.url&&e.url.length>0?`domain=${e.url}`:"";document.cookie=`${t}=${n||""}${r}; path=${i}; ${s};`}catch(e){return Promise.reject(e)}}))}deleteCookie(e){return x(this,null,(function*(){try{document.cookie=`${e.key}=; Max-Age=0`}catch(e){return Promise.reject(e)}}))}clearCookies(){return x(this,null,(function*(){try{const e=document.cookie.split(";")||[];for(const t of e)document.cookie=t.replace(/^ +/,"").replace(/=.*/,`=;expires=${(new Date).toUTCString()};path=/`)}catch(e){return Promise.reject(e)}}))}clearAllCookies(){return x(this,null,(function*(){try{yield this.clearCookies()}catch(e){return Promise.reject(e)}}))}},l("CapacitorCookies",{web:()=>new p}),f=e=>x(void 0,null,(function*(){return new Promise(((t,n)=>{const r=new FileReader;r.onload=()=>{const e=r.result;t(e.indexOf(",")>=0?e.split(",")[1]:e)},r.onerror=e=>n(e),r.readAsDataURL(e)}))})),h=(e={})=>{const t=Object.keys(e);return Object.keys(e).map((e=>e.toLocaleLowerCase())).reduce(((n,r,i)=>(n[r]=e[t[i]],n)),{})},m=(e,t=!0)=>{if(!e)return null;return Object.entries(e).reduce(((e,n)=>{const[r,i]=n;let s,o;return Array.isArray(i)?(o="",i.forEach((e=>{s=t?encodeURIComponent(e):e,o+=`${r}=${s}&`})),o.slice(0,-1)):(s=t?encodeURIComponent(i):i,o=`${r}=${s}`),`${e}&${o}`}),"").substr(1)},g=(e,t={})=>{const n=Object.assign({method:e.method||"GET",headers:e.headers},t),r=h(e.headers)["content-type"]||"";if("string"==typeof e.data)n.body=e.data;else if(r.includes("application/x-www-form-urlencoded")){const t=new URLSearchParams;for(const[n,r]of Object.entries(e.data||{}))t.set(n,r);n.body=t.toString()}else if(r.includes("multipart/form-data")||e.data instanceof FormData){const t=new FormData;if(e.data instanceof FormData)e.data.forEach(((e,n)=>{t.append(n,e)}));else for(const n of Object.keys(e.data))t.append(n,e.data[n]);n.body=t;const r=new Headers(n.headers);r.delete("content-type"),n.headers=r}else(r.includes("application/json")||"object"==typeof e.data)&&(n.body=JSON.stringify(e.data));return n},v=class extends c{request(e){return x(this,null,(function*(){const t=g(e,e.webFetchExtra),n=m(e.params,e.shouldEncodeUrlParams),r=n?`${e.url}?${n}`:e.url,i=yield fetch(r,t),s=i.headers.get("content-type")||"";let o,a,{responseType:l="text"}=i.ok?e:{};switch(s.includes("application/json")&&(l="json"),l){case"arraybuffer":case"blob":a=yield i.blob(),o=yield f(a);break;case"json":o=yield i.json();break;default:o=yield i.text()}const c={};return i.headers.forEach(((e,t)=>{c[t]=e})),{data:o,headers:c,status:i.status,url:i.url}}))}get(e){return x(this,null,(function*(){return this.request(Object.assign(Object.assign({},e),{method:"GET"}))}))}post(e){return x(this,null,(function*(){return this.request(Object.assign(Object.assign({},e),{method:"POST"}))}))}put(e){return x(this,null,(function*(){return this.request(Object.assign(Object.assign({},e),{method:"PUT"}))}))}patch(e){return x(this,null,(function*(){return this.request(Object.assign(Object.assign({},e),{method:"PATCH"}))}))}delete(e){return x(this,null,(function*(){return this.request(Object.assign(Object.assign({},e),{method:"DELETE"}))}))}},l("CapacitorHttp",{web:()=>new v})}}),j={};((e,t)=>{for(var n in t)y(e,n,{get:t[n],enumerable:!0})})(j,{PreferencesWeb:()=>w});var k=P({"node_modules/.pnpm/@capacitor+preferences@6.0.0_@capacitor+core@6.0.0/node_modules/@capacitor/preferences/dist/esm/web.js"(){L(),w=class extends c{constructor(){super(...arguments),this.group="CapacitorStorage"}configure(e){return x(this,arguments,(function*({group:e}){"string"==typeof e&&(this.group=e)}))}get(e){return x(this,null,(function*(){return{value:this.impl.getItem(this.applyPrefix(e.key))}}))}set(e){return x(this,null,(function*(){this.impl.setItem(this.applyPrefix(e.key),e.value)}))}remove(e){return x(this,null,(function*(){this.impl.removeItem(this.applyPrefix(e.key))}))}keys(){return x(this,null,(function*(){return{keys:this.rawKeys().map((e=>e.substring(this.prefix.length)))}}))}clear(){return x(this,null,(function*(){for(const e of this.rawKeys())this.impl.removeItem(e)}))}migrate(){return x(this,null,(function*(){var e;const t=[],n=[],r="_cap_",i=Object.keys(this.impl).filter((e=>0===e.indexOf(r)));for(const r of i){const i=r.substring(5),s=null!==(e=this.impl.getItem(r))&&void 0!==e?e:"",{value:o}=yield this.get({key:i});"string"==typeof o?n.push(i):(yield this.set({key:i,value:s}),t.push(i))}return{migrated:t,existing:n}}))}removeOld(){return x(this,null,(function*(){const e=Object.keys(this.impl).filter((e=>0===e.indexOf("_cap_")));for(const t of e)this.impl.removeItem(t)}))}get impl(){return window.localStorage}get prefix(){return"NativeStorage"===this.group?"":`${this.group}.`}rawKeys(){return Object.keys(this.impl).filter((e=>0===e.indexOf(this.prefix)))}applyPrefix(e){return this.prefix+e}}}}),O=(e,t,n)=>new Promise(((r,i)=>{var s=e=>{try{a(n.next(e))}catch(e){i(e)}},o=e=>{try{a(n.throw(e))}catch(e){i(e)}},a=e=>e.done?r(e.value):Promise.resolve(e.value).then(s,o);a((n=n.apply(e,t)).next())})),C=class{constructor(){this.preprocess=e=>O(this,null,(function*(){return e})),this.postprocess=e=>O(this,null,(function*(){return e}))}get namespace(){return this._namespace}set namespace(e){this._namespace=e}};L();var $,A=l("Preferences",{web:()=>Promise.resolve().then((()=>(k(),j))).then((e=>new e.PreferencesWeb))}),U=class extends C{constructor(e){var t,n,r,i;super(),this.type="persister",this.name="capacitor/preferences",((e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)})(this,$,void 0),this.preprocess=()=>x(this,null,(function*(){return(yield A.get({key:this.namespace})).value})),this.postprocess=e=>x(this,null,(function*(){return yield A.set({key:this.name,value:e}),e})),r=A,E(t=this,n=$,"write to private field"),i?i.call(t,r):n.set(t,r),e&&((e,t,n)=>(E(e,t,"read from private field"),n?n.call(e):t.get(e)))(this,$).configure(e)}};$=new WeakMap,e.preferences=e=>new U(e),e.default=e.preferences,
/*! Bundled license information:
@capacitor/core/dist/index.js:
(*! Capacitor: https://capacitorjs.com/ - MIT License *)
*/
e.PreferencesPlugin=e.preferences,Object.defineProperty(e,"__esModule",{value:!0})}({});//# sourceMappingURL=mod.global.js.map