interface Storage {
    del(key: string | string[]): void;
    get(key: string): undefined | string;
    getAsArray(key: string): undefined | StorageValue[];
    getAsBoolean(key: string): undefined | boolean;
    getAsNumber(key: string): undefined | number;
    getAsObject<T extends Record<string, unknown>>(
        key: string,
        typeCheck?: (o: Record<string, unknown>) => boolean,
    ): undefined | T;
    getAsRecord(key: string): undefined | Record<string, unknown>;
    getAsString(key: string): undefined | string;
    isEmpty(): boolean;
    set(key: string, value: StorageValue | StorageValue[]): void;
    set(keyValueMap: { [index: string]: StorageValue | StorageValue[] }): void;
    size(): number;
}

Methods

  • Deletes the given key(s) from the storage.

    Parameters

    • key: string | string[]

      the key of the value to delete.

    Returns void

  • Similar to getAsString

    Parameters

    • key: string

      the key of the value to access.

    Returns undefined | string

    the value if existing or undefined otherwise.

  • Uses same logic as getAsObject.

    Parameters

    • key: string

      the key of the value to access.

    Returns undefined | StorageValue[]

    the StorageValue[] if the stored value is readable as StorageValue[], otherwise undefined.

  • Returns the value for the given key as boolean. Tries to parse the value at the given key as boolean.

    Parameters

    • key: string

      the key of the value to access.

    Returns undefined | boolean

    the value as boolean if existing or readable as boolean. Otherwise undefined!

  • Returns the value for the given key as number. Tries to parse the value at the given key as number.

    Parameters

    • key: string

      the key of the value to access.

    Returns undefined | number

    the value as number if existing or readable as number. Otherwise undefined!

  • Returns the value for the given key as T. Uses JSON.parse for parsing and casts it to T.

    Type Parameters

    • T extends Record<string, unknown>

    Parameters

    • key: string

      the key of the value to access.

    • OptionaltypeCheck: (o: Record<string, unknown>) => boolean

      a optional function which verifies the retrieved object, if the function returns false, undefined is returned

    Returns undefined | T

    the object if JSON.parse is able to read it, otherwise undefined.

  • Returns the value for the given key as object. Uses JSON.parse for parsing.

    Parameters

    • key: string

      the key of the value to access.

    Returns undefined | Record<string, unknown>

    the object if JSON.parse is able to read it, otherwise undefined.

  • Returns the value for the given key as string. This method will always return a value if the key exists, because all values are saved as string!

    Parameters

    • key: string

      the key of the value to access.

    Returns undefined | string

    the value if existing or undefined otherwise.

  • Returns boolean

    true if this storage is empty, otherwise false. Only keys matching the prefix are considered.

  • Sets the given value with the given key into the storage. Objects are serialized with JSON.stringify.

    Parameters

    Returns void

  • Sets the given key value pairs into the storage. This is considered as single transaction, in stores with transactions.

    Parameters

    • keyValueMap: { [index: string]: StorageValue | StorageValue[] }

      a object with multiple key value pairs to write into the storage.

    Returns void

  • Returns number

    the size of this storage. Only keys matching the prefix are considered.