UNPKG

one

Version:

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

34 lines (31 loc) • 966 B
import { invalidKey, invalidValue } from "./validate.mjs"; const prefix = "One.Storage."; function getItem(key) { if (typeof key !== "string" || key === "") invalidKey("Storage.getItem"); return localStorage.getItem(prefix + key); } function setItem(key, value) { if (typeof key !== "string" || key === "") invalidKey("Storage.setItem"); if (typeof value !== "string") invalidValue("Storage.setItem"); localStorage.setItem(prefix + key, value); } function removeItem(key) { if (typeof key !== "string" || key === "") 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 }); export { Storage }; //# sourceMappingURL=index.mjs.map