JSPM

local-db-client

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

Type safe IndexedDB access.

Package Exports

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

Readme

local-db-client

An interface for storing values into IndexedDB with type safety. This uses localforage under-the-hood.

For a synchronous, but more ephemeral, API using LocalStorage, see @electrovir/local-storage-client

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

Instal

npm i local-db-client

Usage

import {defineShape} from 'object-shape-tester';
import {LocalDbClient} from 'local-db-client';

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

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

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

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