JSPM

@varasto/web-storage

3.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q23396F
  • License MIT

Varasto storage that uses browser storage as it's backend

Package Exports

  • @varasto/web-storage
  • @varasto/web-storage/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@varasto/web-storage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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