@varasto/web-storage
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

@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 => "",
});

Package Sidebar

Install

npm i @varasto/web-storage

Weekly Downloads

1

Version

3.0.0

License

MIT

Unpacked Size

12 kB

Total Files

10

Last publish

Collaborators

  • rauli