UNPKG

questro

Version:

A lightweight, modular gamification library for React with unique visual components. Features combo meters, daily challenges, achievement toasts, and progress rings. Add points, badges, quests, leaderboards, levels/XP, streaks, and notifications with zero

2 lines 2.8 kB
var o=class{constructor(r="questro"){this.prefix=r;}getKey(r){return `${this.prefix}:${r}`}async get(r){try{let e=localStorage.getItem(this.getKey(r));return e?JSON.parse(e):null}catch(e){return console.error(`Error reading from localStorage: ${String(e)}`),null}}async set(r,e){try{localStorage.setItem(this.getKey(r),JSON.stringify(e));}catch(t){console.error(`Error writing to localStorage: ${String(t)}`);}}async remove(r){try{localStorage.removeItem(this.getKey(r));}catch(e){console.error(`Error removing from localStorage: ${String(e)}`);}}async clear(){try{Object.keys(localStorage).filter(t=>t.startsWith(`${this.prefix}:`)).forEach(t=>localStorage.removeItem(t));}catch(r){console.error(`Error clearing localStorage: ${String(r)}`);}}},i=class{constructor(r="questro"){this.prefix=r;}getKey(r){return `${this.prefix}:${r}`}async get(r){try{let e=sessionStorage.getItem(this.getKey(r));return e?JSON.parse(e):null}catch(e){return console.error(`Error reading from sessionStorage: ${String(e)}`),null}}async set(r,e){try{sessionStorage.setItem(this.getKey(r),JSON.stringify(e));}catch(t){console.error(`Error writing to sessionStorage: ${String(t)}`);}}async remove(r){try{sessionStorage.removeItem(this.getKey(r));}catch(e){console.error(`Error removing from sessionStorage: ${String(e)}`);}}async clear(){try{Object.keys(sessionStorage).filter(t=>t.startsWith(`${this.prefix}:`)).forEach(t=>sessionStorage.removeItem(t));}catch(r){console.error(`Error clearing sessionStorage: ${String(r)}`);}}},n=class{constructor(){this.storage=new Map;}async get(r){return this.storage.get(r)??null}async set(r,e){this.storage.set(r,e);}async remove(r){this.storage.delete(r);}async clear(){this.storage.clear();}},a=class{constructor(r,e="questro"){this.asyncStorage=r;this.prefix=e;}getKey(r){return `${this.prefix}:${r}`}async get(r){try{let e=await this.asyncStorage.getItem(this.getKey(r));return e?JSON.parse(e):null}catch(e){return console.error(`Error reading from AsyncStorage: ${String(e)}`),null}}async set(r,e){try{await this.asyncStorage.setItem(this.getKey(r),JSON.stringify(e));}catch(t){console.error(`Error writing to AsyncStorage: ${String(t)}`);}}async remove(r){try{await this.asyncStorage.removeItem(this.getKey(r));}catch(e){console.error(`Error removing from AsyncStorage: ${String(e)}`);}}async clear(){try{if(this.asyncStorage.getAllKeys&&this.asyncStorage.multiRemove){let e=(await this.asyncStorage.getAllKeys()).filter(t=>t.startsWith(`${this.prefix}:`));e.length>0&&await this.asyncStorage.multiRemove(e);}else console.warn("AsyncStorage.getAllKeys or multiRemove not available");}catch(r){console.error(`Error clearing AsyncStorage: ${String(r)}`);}}};export{o as a,i as b,n as c,a as d};//# sourceMappingURL=chunk-R2GD7YTX.mjs.map //# sourceMappingURL=chunk-R2GD7YTX.mjs.map