@fastnear/wallet-adapter
Version:
Wallet adapter implementations for Meteor Wallet and Near Mobile
44 lines • 1.66 kB
JavaScript
/* ⋈ 🏃🏻💨 FastNear Wallet Adapters - ESM (@fastnear/wallet-adapter version 1.2.0) */
/* https://www.npmjs.com/package/@fastnear/wallet-adapter/v/1.2.0 */
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const isStorageAvailable = /* @__PURE__ */ __name(() => {
return typeof window !== "undefined" && window.localStorage != null;
}, "isStorageAvailable");
const createDefaultStorage = /* @__PURE__ */ __name(() => {
if (!isStorageAvailable()) {
const mem = /* @__PURE__ */ new Map();
return {
get: /* @__PURE__ */ __name((key) => mem.get(key) ?? null, "get"),
set: /* @__PURE__ */ __name((key, value) => {
mem.set(key, value);
}, "set"),
remove: /* @__PURE__ */ __name((key) => {
mem.delete(key);
}, "remove")
};
}
return {
get: /* @__PURE__ */ __name((key) => window.localStorage.getItem(key), "get"),
set: /* @__PURE__ */ __name((key, value) => window.localStorage.setItem(key, value), "set"),
remove: /* @__PURE__ */ __name((key) => window.localStorage.removeItem(key), "remove")
};
}, "createDefaultStorage");
const readJson = /* @__PURE__ */ __name(async (storage, key, fallback) => {
try {
const raw = await storage.get(key);
if (raw == null) return fallback;
return JSON.parse(raw);
} catch {
return fallback;
}
}, "readJson");
const writeJson = /* @__PURE__ */ __name(async (storage, key, value) => {
await storage.set(key, JSON.stringify(value));
}, "writeJson");
export {
createDefaultStorage,
readJson,
writeJson
};
//# sourceMappingURL=storage.js.map