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

unify-storag

v1.0.6

Published

A unified storage layer for Next.js that works on both server and client without crashes.

Readme

unify-storage 🚀

A unified storage layer for Next.js that works on both server and client without crashes.

Features ✨

  • 🔄 Dual Storage: Automatically stores data in both localStorage and cookies
  • 🛡️ Safe Fallbacks: Gracefully handles server-side rendering (returns null on server)
  • 📦 Lightweight: No dependencies, minimal footprint
  • 🔒 Type-Safe: Full TypeScript support
  • Server Safe: Can be imported in Server Components without crashing

Installation

npm install unify-storage

Usage

⚠️ Important: Server vs Client Components

This package is safe to import in Server Components, but storage operations only work in the browser.

| Environment | get() | set() / remove() | |-------------|---------|----------------------| | Client (Browser) | Returns value | Works as expected | | Server (Node.js) | Returns null | Operation skipped (no-op) |

Correct Usage in Next.js

To actually store or retrieve data, you must use this in a Client Component (using "use client") or inside a useEffect.

Option 1: Client Component (Recommended)

"use client"; // <--- Required for interactivity

import { smartStorage } from "unify-storage";

const MyComponent = () => {
    const saveToken = () => {
        smartStorage.set("token", "12345");
        console.log("Saved!");
    };

    return <button onClick={saveToken}>Save Token</button>;
}

export default MyComponent;

Option 2: Using useEffect

"use client";

import { useEffect, useState } from "react";
import { smartStorage } from "unify-storage";

const Profile = () => {
    const [token, setToken] = useState<string | null>(null);

    useEffect(() => {
        // Only runs in the browser
        const stored = smartStorage.get("token");
        setToken(stored);
    }, []);

    return <div>Token: {token}</div>;
}

What happens in a Server Component?

If you use it in a Server Component without "use client", it will not crash, but it will not save anything.

// ❌ This is a Server Component
import { smartStorage } from "unify-storage";

const ServerComponent = () => {
    // ⚠️ This runs on the server!
    // Result: Operation skipped, nothing is saved.
    smartStorage.set("token", "12345"); 

    return <div>Check console logs</div>;
}

API Reference

smartStorage.get(key: string): string | null

Retrieves a value from storage. Checks localStorage first, then falls back to cookies. Returns null if called on the server.

const token = smartStorage.get("token");

smartStorage.set(key: string, value: string): void

Stores a value in both localStorage and cookies (30 days expiry by default). Skips operation if called on the server.

smartStorage.set("user", "john_doe");

smartStorage.remove(key: string): void

Removes a value from both localStorage and cookies. Skips operation if called on the server.

smartStorage.remove("token");

smartStorage.has(key: string): boolean

Checks if a key exists in storage.

if (smartStorage.has("token")) {
    // Token exists
}

smartStorage.clear(): void

Clears all items from localStorage (cookies are not affected).

smartStorage.clear();

How It Works

  1. Environment Detection: The package checks typeof window !== "undefined" to determine if it's running in the browser.
  2. Client-Side: Uses localStorage as primary storage with cookies as backup.
  3. Server-Side: Safely returns null or skips operations to prevent hydration mismatches or crashes.
  4. Cookies: Automatically set with SameSite=Lax and 30-day expiry.