Skip to content
kushal.st

I Built a Wrapper to Fix the Two Biggest Problems with localStorage

1 min read localStorage, TypeScript, npm, Web development

Originally published on Medium - read it there ↗

localStorage is the workhorse of client-side persistence, but it ships with two long-standing gaps: values never expire, and everything sits in plain, readable JSON for anyone poking around DevTools. This article walks through how I addressed both with @kushalst/local-storage-expiry, a vanilla TypeScript wrapper with zero runtime dependencies. It adds per-key TTL (time-to-live) so entries self-destruct on read once expired, and a lightweight, Unicode-safe XOR + Base64 obfuscation layer so values are not stored as bare JSON. All keys are namespaced under an lse_ prefix, so clear() and flushExpired() only ever touch the library’s own entries - never the rest of your app’s storage - and tampered or malformed entries are automatically removed and returned as null.

Read the full article on Medium →