Provides the TRL web storage store API.

interface WebStorage {
    entries<T>(regex?: RegExp): IterableIterator<[string, Writable<T>], any, any>;
    getItem(key: string, defaultValue?: any): unknown;
    getStore<T>(key: string, defaultValue?: T, storageStores?: StorageStores): Writable<T>;
    hasStore(key: string): boolean;
    keys(regex?: RegExp): IterableIterator<string, any, any>;
    setItem(key: string, value: any): void;
    stores<T>(regex?: RegExp): IterableIterator<Writable<T>, any, any>;
    swapItemBoolean(key: string, defaultValue?: boolean): boolean;
}
Implemented by

Methods

  • Type Parameters

    • T

      Returns an iterable for the session storage keys and stores.

    Parameters

    • Optionalregex: RegExp

      Optional regular expression to filter by storage keys.

    Returns IterableIterator<[string, Writable<T>], any, any>

    Iterable iterator of keys and stores.

  • Get value from the storage API.

    Parameters

    • key: string

      Key to lookup in storage API.

    • OptionaldefaultValue: any

      A default value to return if key not present in session storage.

    Returns unknown

    Value from session storage or if not defined any default value provided.

  • Returns the backing Svelte store for the given key; potentially sets a default value if the key is not already set.

    Type Parameters

    • T

    Parameters

    • key: string

      Key to lookup in storage API.

    • OptionaldefaultValue: T

      A default value to return if key not present in session storage.

    • OptionalstorageStores: StorageStores

      Additional store creation options.

    Returns Writable<T>

    The Svelte store for this key.

  • Returns whether a store has already been created for the given key.

    Parameters

    • key: string

      Key to lookup in storage API.

    Returns boolean

  • Returns an iterable for the session storage keys from existing stores.

    Parameters

    • Optionalregex: RegExp

      Optional regular expression to filter by storage keys.

    Returns IterableIterator<string, any, any>

    Iterable iterator of session storage keys.

  • Sets the value for the given key in storage API.

    Parameters

    • key: string

      Key to lookup in storage API.

    • value: any

      A value to set for this key.

    Returns void

  • Type Parameters

    • T

      Returns an iterable for the session storage stores.

    Parameters

    • Optionalregex: RegExp

      Optional regular expression to filter by storage keys.

    Returns IterableIterator<Writable<T>, any, any>

    Iterable iterator of stores.

  • Convenience method to swap a boolean value stored in storage API updating the associated store value.

    Parameters

    • key: string

      Key to lookup in storage API.

    • OptionaldefaultValue: boolean

      A default value to return if key not present in session storage.

    Returns boolean

    The boolean swap for the given key.