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-smart-storage

v1.3.0

Published

A lightweight React library to simplify localStorage and sessionStorage operations using TypeScript.

Downloads

39

Readme

📦 react-smart-storage

react-smart-storage is a lightweight, type-safe utility library for simplifying the usage of localStorage and sessionStorage in React applications using TypeScript. It also supports optional AES encryption for securely storing sensitive data.

🚀 Clean APIs, ✨ Type-safe, 🔐 Optional encryption, 💡 Beginner-friendly


📥 Installation

You can install the package using npm or yarn:

npm i react-smart-storage

🔧 Getting Started

  1. Import the helpers (ts)
import { setItem, getItem, removeItem, clearStorage } from 'react-smart-storage';
  1. Store a value in localStorage (without encryption) (ts)
setItem('user', { name: 'Deviprasad', role: 'admin' });
  1. Retrieve the value (no encryption) (ts)
const user = getItem<{ name: string; role: string }>('user');
console.log(user?.name); // Output: Deviprasad
  1. Store a value with expiration (no encryption) (ts)
setItem('guest', { name: 'Visitor' }, {
  expiresIn: 60, // expires in 60 seconds
});
  1. Store an encrypted value (ts)
const secretKey = 'my-super-secret-key';

setItem('secureUser', { name: 'Deviprasad', role: 'admin' }, {
  type: 'local',
  encrypt: true,
  hashKey: secretKey
});
  1. Retrieve the encrypted value (ts)
const secretKey = 'my-super-secret-key';

const secureUser = getItem<{ name: string; role: string }>('secureUser', {
  encrypt: true,
  hashKey: secretKey
});
console.log(secureUser?.role); // Output: admin
  1. Use sessionStorage instead of localStorage (ts)
setItem('sessionId', 'abc123', { type: 'session' });
const sessionId = getItem<string>('sessionId', { type: 'session' });
  1. Remove a specific item (ts)
removeItem('user');
  1. Remove multiple keys at once (ts)
removeItems(['user', 'sessionId', 'preferences']); // Removes multiple keys
  1. Clear all storage (ts)
clearStorage(); // Defaults to localStorage
clearStorage('session'); // Clears sessionStorage
  1. Get Storage Usage Details (ts)
const usage = getStorageUsage(); 
console.log(usage);
// { usedBytes: 1234, freeBytes: 5241646, maxBytes: 5242880, usedMB: "0.00", freeMB: "4.99", maxMB: "5.00" }
  1. Get Storage Usage Summary (ts)
const summary = getStorageUsageSummary();
console.log(summary);
// Output: "Used 0.12MB of 5.00MB (2.4%)"

💡 React Example

import React, { useEffect } from 'react';
import { setItem, getItem, removeItem, clearStorage, removeItems, getStorageUsageSummary, getStorageUsage } from 'react-smart-storage';

export default function Storage() {

    const hashKey = '3c7e8e1b4b32f5b7a19cb06b2e67d2ea6bd4fe6aeb9c9c352c8cd7ecff59b6b1';

    useEffect(() => {
        setItem('user', { name: 'Deviprasad', role: 'admin', password: 'sample@123' });
        setItem('role', { isAdmin: true, loggedIn: 1 });
    }, []);

    const setData = () => {
        setItem('encryption', { isAdmin: true, loggedIn: 1 }, {
            type: 'local', // local is default, replace with "session" for session storage
            encrypt: true,
            hashKey: hashKey,
            expiresIn: 20
        });
        console.log('Encrypted data set');
    };

    const getData = () => {
        const encryptedData = getItem('encryption', { type: 'local', encrypt: true, hashKey: hashKey });
        const nonEncryptedData = getItem('user');
        console.log('Decrypted Data:', encryptedData);
        console.log('Decrypted Data:', nonEncryptedData);
    };

    const removeMultipleKeys = () => {
        // local is default, replace with "session" for session storage
        removeItems(['role', 'user'], 'local');
    }

    const getUsageData = () => {
        // Gives the storage usage assuming 5MB limit (commonly browser default, but varies)
        const storageSummary = getStorageUsageSummary();
        const storageUsage = getStorageUsage();
        console.log("Summaay = ", storageSummary);
        console.log("Usage Details = ", storageUsage);
    }

    return (
        <>
            <h2>Smart storage</h2>
            <div
                style={{
                    display: 'flex',
                    alignItems: 'center',
                    justifyContent: "center",
                    flexWrap: 'wrap',
                    gap: '0.4rem'
                }}>
                <button onClick={setData}>Set encrypted data</button>
                <button onClick={getData}>Get encrypted data</button>
                <button onClick={removeMultipleKeys}>Remove Multiple keys</button>
                <button onClick={() => removeItem('user')}>Remove User</button>
                <button onClick={() => clearStorage()}>Clear data</button>
                <button onClick={getUsageData}>Get Usage</button>
            </div>
        </>
    );
}

✅ Why use this?

🧠 Simple and intuitive API

🔒 Optional AES encryption support

⏳ Built-in expiration support for auto-cleanup

📊 Detailed storage usage info — Know exactly how much space you’re using and what's free.

✨ Fully TypeScript supported

🚀 Fast and lightweight

📦 Works out of the box

💻 Supports both localStorage and sessionStorage


🧑‍💻 Contributing

We welcome contributions! Please read our CONTRIBUTING.md for guidelines on how to help improve the project.

📄 License MIT © Deviprasad