@varasto/web-storage
v3.0.0
Published
Varasto storage that uses browser storage as it's backend
Maintainers
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-storageUsage
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 => "",
});