Skip to content

Options to auto-manage special objects like Date, Map and Set #137

Closed
@cyrilletuzi

Description

@cyrilletuzi

As stated in the serialization guide:

In most cases, this library uses indexedDB storage, which allows any value type. But in special cases (like in Firefox / IE private mode, see the browser support guide for details), the library will fall back to localStorage, where JSON serialization will happen.

Everything can be serialized (JSON.stringify()), but when you unserialize (JSON.parse()), you'll only get a JSON, ie. a primitive type, an array or a literal object.

So if you store an instance of a specific class in localStorage, like Date, Map, Set or Blob, what you'll get then with .setItem() won't be a Map, Set or Blob, but just a literal object.

So, it's safer to stick to JSON-compatible values.

The library could add options to manage Date, Map or Set automatically.

It requires:

  1. API design,
  2. time: I don't have time currently to implement new features, so sponsoring or community PRs are welcomed (after having agreed on the API design)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions