JSPM

local-db-client

0.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 219
  • Score
    100M100P100Q86203F
  • License MIT

Package Exports

    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 = await LocalDbClient.createClient({
        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();
    
    /** Load a stored value. If the stored value is not valid, `undefined` is returned. */
    console.info(myClient.value);
    
    /** Force a value to reload. */
    await myClient.load.objectValue();