npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@react-solutions/vault

v1.1.0

Published

A storage library for react

Readme

@react-solutions/vault

npm version npm downloads bundle size

A powerful, lightweight React & Next.js library providing secure, encrypted storage utilities for localStorage, sessionStorage, Cache API, and Cookies. It features AES-GCM encryption, automatic serialization, and full TypeScript support.

📦 Installation

npm install @react-solutions/vault

🚀 Features

  • 🔒 Multi-Layer Encryption - AES-GCM encryption for all storage types.
  • 🍪 Cookie Support - Comprehensive cookie management with security options.
  • 📂 Cache API Integration - Store large datasets securely using the browser's Cache API.
  • 🔄 Atomic Updates - Support for functional updates and partial merges.
  • 🌍 SSR Compatible - Works seamlessly with Next.js (graceful fallbacks for server-side).
  • 🗝️ Custom Keys - Configure passphrase, salt, and namespace per call.
  • Ultra Lightweight - No dependencies and tree-shakable.

📚 API Reference

1. Local Storage API

Persistent storage that stays even after the browser is closed.

| Method | Description | | :-------------------------------------- | :------------------------------------------------------------------ | | setItem(key, value, options?) | Encrypts and saves data to localStorage. | | getItem<T>(key, options?) | Retrieves and decrypts data from localStorage. | | updateItem<T>(key, updater, options?) | Updates existing data (merges objects or uses an updater function). | | removeItem(key) | Deletes a specific item from localStorage. | | hasItem(key) | Checks if a key exists in localStorage. | | clear() | Clears all localStorage data. |

Usage:

import { setItem, getItem, updateItem } from "@react-solutions/vault";

setItem("user", { name: "Alice" });
const user = getItem<{ name: string }>("user");
updateItem("user", { age: 25 }); // Merges with existing data

2. Session Storage API

Storage that persists only for the duration of the page session (tab).

| Method | Description | | :----------------------------------------- | :----------------------------------------------- | | setSession(key, value, options?) | Encrypts and saves data to sessionStorage. | | getSession<T>(key, options?) | Retrieves and decrypts data from sessionStorage. | | updateSession<T>(key, updater, options?) | Updates existing session data. | | removeSession(key) | Deletes a specific item from sessionStorage. | | hasSession(key) | Checks if a key exists in sessionStorage. | | clearSession() | Clears all sessionStorage data. |

Usage:

import { setSession, getSession } from "@react-solutions/vault";

setSession("temp_data", { id: 123 });

3. Cache API

Ideal for larger datasets or offline storage.

| Method | Description | | :--------------------------------------- | :------------------------------------------------ | | setCache(key, value, options?) | Stores encrypted data in the browser's Cache API. | | getCache<T>(key, options?) | Retrieves and decrypts data from the Cache API. | | updateCache<T>(key, updater, options?) | Updates existing cached data. | | removeCache(key, options?) | Removes a specific resource from the cache. | | hasCache(key, options?) | Checks if a resource exists in the cache. | | clearCache(options?) | Deletes an entire cache bucket. |

Usage:

import { setCache, getCache } from "@react-solutions/vault";

await setCache("api_response", { data: [...] });
const response = await getCache("api_response");

4. Cookie API

Manage cookies with encryption and security attributes.

| Method | Description | | :---------------------------------------- | :-------------------------------------------------------------- | | setCookie(key, value, options?) | Sets an encrypted cookie with expires, path, secure, etc. | | getCookie<T>(key, options?) | Retrieves and decrypts a cookie value. | | updateCookie<T>(key, updater, options?) | Updates a cookie via merge or updater function. | | removeCookie(key, options?) | Deletes a cookie. | | hasCookie(key) | Checks if a cookie exists. | | clearCookies() | Clears all accessible cookies. |

Usage:

import { setCookie, getCookie } from "@react-solutions/vault";

setCookie("theme", "dark", { expires: 30, secure: true });
const theme = getCookie("theme");

5. Crypto Utilities

Low-level encryption and key generation tools.

| Method | Description | | :--------------------------------- | :----------------------------------------------------------- | | encrypt(data, options?) | Encrypts any JSON-serializable data into a secure string. | | decrypt<T>(ciphertext, options?) | Decrypts a vault-encrypted string back to its original type. | | getCryptoKey(length?) | Generates a cryptographically secure SHA-256 hex string. |

Usage:

import { encrypt, decrypt, getCryptoKey } from "@react-solutions/vault";

// Generate a 32-character secure key
const key = getCryptoKey(32);

// Encrypt data manually
const secretData = encrypt({ pin: 1234 }, { secretKey: key });

// Decrypt data manually
const original = decrypt<{ pin: number }>(secretData, { secretKey: key });

🔑 Custom Encryption Settings

You can provide custom encryption settings (passphrase, salt, namespace) in the options object for any of the methods.

setItem("sensitive", { token: "123" }, { passphrase: "my-secret-key", salt: "custom-salt" });

📝 Next.js (SSR) Usage

This package is safe to use in Next.js. Methods called on the server will return null or false without throwing errors, ensuring your build and server-side rendering remain stable.

// This is safe even in a Server Component or during SSR
const data = getItem("data");

⚡ Example: Using Types

type User = { id: string; name: string };
const user = await getItem<User>("user");

📝 TypeScript Support

This package is written in TypeScript and includes full type definitions. All exported functions and hooks are fully typed.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT


Made with ❤️ for React & Next.js developers