UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

53 lines (52 loc) • 1.89 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var storage_exports = {}; __export(storage_exports, { Storage: () => Storage }); module.exports = __toCommonJS(storage_exports); var import_validate = require("./validate.cjs"); const prefix = "One.Storage."; function getItem(key) { if (typeof key !== "string" || key === "") (0, import_validate.invalidKey)("Storage.getItem"); return localStorage.getItem(prefix + key); } function setItem(key, value) { if (typeof key !== "string" || key === "") (0, import_validate.invalidKey)("Storage.setItem"); if (typeof value !== "string") (0, import_validate.invalidValue)("Storage.setItem"); localStorage.setItem(prefix + key, value); } function removeItem(key) { if (typeof key !== "string" || key === "") (0, import_validate.invalidKey)("Storage.removeItem"); localStorage.removeItem(prefix + key); } function getAllKeys() { const keys = []; for (let index = 0; index < localStorage.length; index++) { const key = localStorage.key(index); if (key?.startsWith(prefix)) keys.push(key.slice(prefix.length)); } return keys; } const Storage = Object.freeze({ getItem, setItem, removeItem, getAllKeys });