3.0.0 • Published 7 months ago

@varasto/web-storage v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@varasto/web-storage

npm

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 WebStorage constructor.

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

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