JSPM

@electrovir/local-storage-client

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 373
  • Score
    100M100P100Q100821F
  • License (MIT or CC0 1.0)

An interface for storing JSON values into the LocalStorage API with type safety.

Package Exports

  • @electrovir/local-storage-client
  • @electrovir/local-storage-client/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 (@electrovir/local-storage-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@electrovir/local-storage-client

An interface for storing values into the LocalStorage API with type safety. Note that only JSON compatible data can be stored.

Note that some browsers aggressively clear LocalStorage so this should only be used for ephemeral data storage. If you need more permanent storage, use local-db-client instead.

Reference docs: https://electrovir.github.io/local-storage-client

Instal

npm i @electrovir/local-storage-client

Usage

import {defineShape} from 'object-shape-tester';
import {LocalStorageClient} from '@electrovir/local-storage-client';

const myClient = new LocalStorageClient({
    stringValue: defineShape(''),
    numberValue: defineShape(-1),
    booleanValue: defineShape(false),
    objectValue: defineShape({
        name: '',
        age: 0,
        location: '',
    }),
});

/** Set values with type safety. */
myClient.set.objectValue({
    age: 10,
    location: 'Earth',
    name: 'Example User',
});
myClient.set.booleanValue(true);

/** Delete a stored value. */
myClient.delete.booleanValue();

/** Get a stored value. If the stored value is not valid, `undefined` is returned. */
myClient.get.objectValue();