
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.
lc-storage
Advanced tools
A lightweight and type-safe utility for interacting with **localStorage** in modern JavaScript & TypeScript applications
lc-storage is a lightweight and type-safe utility for interacting with localStorage in modern JavaScript & TypeScript applications.
✔ Read data from localStorage
✔ Write data to localStorage
✔ Delete specific keys from localStorage
✔ Clear all data from localStorage
✔ Supports automatic expiration (exp)
✔ Type-safe retrieval (get<T>())
Install via npm:
npm i lc-storage --save
import storage from "lc-storage";
const data = [1, 2, 3, 4];
storage.set("data", data);
const myData = storage.get("data");
console.log(myData); // [1, 2, 3, 4]
storage.remove("data");
storage.clear();
💾 set() Method – Store Data with Expiration & Nullable Options
The set() method allows you to store data in localStorage with optional settings.
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.
interface SetOption {
exp?: number; // Expiration time in seconds
nullable?: boolean; // If true, allows setting null values (default: false)
}
// 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.
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.
// 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.
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.
storage.clear(); // Clears everything from localStorage
| 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 |
| 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() |
✔ 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!
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. 🚀😊
This project is licensed under the MIT License.
FAQs
A lightweight and type-safe utility for interacting with **localStorage** in modern JavaScript & TypeScript applications
The npm package lc-storage receives a total of 9 weekly downloads. As such, lc-storage popularity was classified as not popular.
We found that lc-storage 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.