@varasto/web-storage

Varasto storage that uses browser storage as it's backend

Usage no npm install needed!

<script type="module">
  import varastoWebStorage from 'https://cdn.skypack.dev/@varasto/web-storage';
</script>

README

@varasto/web-storage

Implementation of an Varasto storage which stores values in browser's local storage or session storage.

Installation

$ npm install --save @varasto/web-storage

Usage

The package provides an function called createWebStorage which takes an Storage object as an argument.

import { createWebStorage } from '@varasto/web-storage';

const storage = createWebStorage(window.sessionStorage);

Custom serializers

By default, JSON.stringify is used for serializing data passed to the Web storage and JSON.parse is used for deserializing data retrieved from the Web storage. However, you can also use your own custom serialization functions by passing them as options to the createWebStorage function.

import { createWebStorage } from '@varasto/web-storage';
import { JsonObject } from 'type-fest';

const storage = createWebStorage(window.sessionStorage, {
  serialize: (data: string): JsonObject => {},
  deserialize: (data: JsonObject): string => "",
});