localstorage-slim icon indicating copy to clipboard operation
localstorage-slim copied to clipboard

Support sessionStorage?

Open mmkal opened this issue 2 years ago • 1 comments

Not a bug, a feature request.

Expected Behavior

It'd be nice to be able to use sessionStorage instead of localStorage in certain cases. Obviously localStorage should remain the default, but some way to configure this module would be useful.

Current Behavior

localStorage is always used.

Possible Solution

ls.config.storage = sessionStorage

ls.get('...') // use as normal, but will now read/write from `sessionStorage` instead

The nice thing about this is it'd allow for setting storage to other values with the same interface too - which could be useful for testing or for writing a low-level wrapper for localStorage or sessionStorage.

Context

Not having this means we get lots of nice features for using localStorage like better type-safety, rich object storage, and encyrption (also ttl/expiry, although obviously that's less of a concern for sessionStorage), but we have to use the raw API or find a similar library for sessionStorage. Given the tiny change that would be needed in this library to support sessionStorage, it seems worth doing.

mmkal avatar May 22 '22 21:05 mmkal

Hello @mmkal , Thank you for your suggestion. The library being called localstorage-slim is expected to support localStorage alone. As of now, we have no plans to include sessionStorage immediately but we will try to include it in the next major release. Thanks!

niketpathak avatar May 25 '22 08:05 niketpathak