
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
universal-webstorage
Advanced tools
A universal, lightweight utility for managing web storage (localStorage, sessionStorage, etc.) with support for JSON operations, TTL, bulk actions, and React hooks.
universal-webstorage is a lightweight, universal utility for managing web storage based on the MDN Web Storage API specification. It provides a consistent API for core storage operations, bulk actions, JSON handling, and TTL (time-to-live) support. The library works with localStorage, sessionStorage, or any custom storage-like interface.
Note: For React-specific hooks and functionality, please see the separate
@aivron/sync-storagepackage.
localStorage, sessionStorage, or any storage-like interface.Install via npm:
npm install universal-webstorage
Or via yarn:
yarn add universal-webstorage
You can import individual functions or use the main entry point to access all utilities.
// Import specific functions:
import { setStorageItem, getStorageItem } from 'universal-webstorage';
// Or import the entire module:
import * as webstorage from 'universal-webstorage';
import { setStorageItem } from 'universal-webstorage';
setStorageItem("userToken", "abc123");
import { getStorageItem } from 'universal-webstorage';
const token = getStorageItem("userToken");
console.log(token); // Output: "abc123"
import { updateStorageItem } from 'universal-webstorage';
updateStorageItem("userToken", (current) =>
current ? current + "_v2" : "defaultToken"
);
import { removeStorageItem } from 'universal-webstorage';
removeStorageItem("userToken");
For example, retrieve all keys that start with "app:":
import { getStorageItems } from 'universal-webstorage';
const appItems = getStorageItems((key) => key.startsWith("app:"));
console.log(appItems);
import { updateStorageItems } from 'universal-webstorage';
updateStorageItems(
(key) => key.startsWith("app:"),
(current) => (current ? current.toUpperCase() : "")
);
import { removeStorageKeys } from 'universal-webstorage';
removeStorageKeys((key) => key.includes("temp"));
import { setJSONItem } from 'universal-webstorage';
setJSONItem("userData", { name: "Alice", age: 30 });
import { getJSONItem } from 'universal-webstorage';
const userData = getJSONItem<{ name: string; age: number }>("userData");
console.log(userData);
import { updateJSONItem } from 'universal-webstorage';
updateJSONItem<{ name: string; age: number }>("userData", (current) => ({
...current,
age: (current?.age || 0) + 1,
}));
Store an item that expires in 1 hour:
import { setStorageItemWithTTL } from 'universal-webstorage';
setStorageItemWithTTL("sessionData", "sessionValue", 3600 * 1000);
import { getStorageItemWithTTL } from 'universal-webstorage';
const sessionValue = getStorageItemWithTTL("sessionData");
console.log(sessionValue);
This library follows the MDN Web Storage API specification. For detailed information on how the Web Storage API works, refer to the MDN documentation.
For detailed API documentation, please refer to the documentation website or review the source code in the repository.
Contributions, issues, and feature requests are welcome! Please check the issues page if you want to contribute.
This project is licensed under the MIT License. See the LICENSE file for details.
Enjoy using universal-webstorage for all your web storage needs! If you have any questions or need further assistance, feel free to reach out.
FAQs
A universal, lightweight utility for managing web storage (localStorage, sessionStorage, etc.) with support for JSON operations, TTL, bulk actions, and React hooks.
We found that universal-webstorage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.