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 🙏

© 2025 – Pkg Stats / Ryan Hefner

lc-storage

v3.1.2

Published

A lightweight and type-safe utility for interacting with **localStorage** in modern JavaScript & TypeScript applications

Downloads

420

Readme

LC-STORAGE 🗄️

lc-storage is a lightweight and type-safe utility for interacting with localStorage in modern JavaScript & TypeScript applications.

🚀 Features

Read data from localStorageWrite data to localStorageDelete specific keys from localStorageClear all data from localStorageSupports automatic expiration (exp)Type-safe retrieval (get<T>())


📦 Installation

Install via npm:

npm i lc-storage --save

🛠 Usage

📌 Import storage

import storage from "lc-storage";

🔥 Storing and Retrieving Data

✅ Save Data to localStorage
const data = [1, 2, 3, 4];
storage.set("data", data);
✅ Retrieve Data from localStorage
const myData = storage.get("data");
console.log(myData); // [1, 2, 3, 4]
✅ Delete Data from localStorage
storage.remove("data");
✅ Clear All Data from localStorage
storage.clear();

📌 Advanced Usage

💾 set() Method – Store Data with Expiration & Nullable Options

The set() method allows you to store data in localStorage with optional settings.

📌 Method Signature
storage.set<T>(key: string, value: T, setOption?: SetOption): T | null;

Parameter Type Required Description key string ✅ Unique identifier for the stored data. value T (generic) ✅ The value to be stored (objects, arrays, primitives). setOption SetOption ❌ Configuration for expiration & nullability.

📌 SetOption Interface
interface SetOption {
  exp?: number;  // Expiration time in seconds
  nullable?: boolean; // If true, allows setting null values (default: false)
}
✅ Example: Store Data with Expiration
// Store data with a 60-second expiration
storage.set("sessionData", { user: "JohnDoe" }, { exp: 60 });

// Before 60 seconds, you can retrieve the value:
console.log(storage.get("sessionData")); // { user: "JohnDoe" }

// After 60 seconds, the value automatically expires and returns `null`
setTimeout(() => {
  console.log(storage.get("sessionData")); // null
}, 60 * 1000);

📌 get<T>() Method – Retrieve Data with Type Safety

The get() method allows type-safe retrieval of stored values.

📌 Method Signature
storage.get<T>(key: string): T | null;

Parameter Type Required Description key string ✅ The key identifier of the stored data.

Returns T (the stored value) or null if the key does not exist.

✅ Example: Retrieve Data with Type Safety
// Store user info
storage.set("user", { name: "Alice", age: 25 });

// Retrieve with correct type
const user = storage.get<{ name: string; age: number }>("user");

console.log(user?.name); // "Alice"
console.log(user?.age);  // 25

📌 remove() Method – Delete a Key

The remove() method deletes a specific key-value pair from localStorage.

✅ Example
storage.remove("user"); // Removes "user" from storage
console.log(storage.get("user")); // null

📌 clear() Method – Clear All Data

The clear() method removes all stored data from localStorage.

✅ Example
storage.clear(); // Clears everything from localStorage

⚠️ Edge Case Handling

| Scenario | Behavior | ----------------------------------------|---------------------------------------- | Key does not exist in get() | Returns null | | Expired data | Automatically removed & returns null | | Setting null without nullable: true | Prevents storage | | Browser without localStorage support | Logs warnings, but prevents crashes |

📌 Summary Table

| Method | Description | Example | |--------------------------------|----------------------------|-----------------| | storage.set(key, value, options?) | Stores data with optional expiration | storage.set("token", "abc123", { exp: 3600 }) | | storage.get(key) | Retrieves data (type-safe) | const user = storage.get<{ name: string }>("user") | | storage.remove(key) | Deletes a specific key | storage.remove("user") storage.clear() | Clears all stored data | storage.clear() |

🔥 Why Use lc-storage?

✔ Supports exp (expiration time) to automatically remove stale data ✔ Type-safe with generics for better TypeScript support ✔ Safer handling of missing or expired data ✔ Prevents crashes if localStorage is unavailable ✔ Small & fast – No dependencies!

🚀 Future Enhancements

Would you like to see: • 🔒 Encryption support for storing sensitive data? • 📂 Support for sessionStorage? • 📌 Automatic data sync with IndexedDB for large storage?

📌 Contributions are welcome! If you find a bug or have an idea for improvement, feel free to open a pull request or issue. 🚀😊

📜 License

This project is licensed under the MIT License.