# Core API

# StorageModule()

Create a storage module.

# Type

new StorageModule<T>(key: string, storageType: StorageType, noUniqueVerify?: boolean): StorageModule<T>;

# Parameters

  • key: string

    Key of storage module.

  • storageType: StorageType

    enum StorageType {
      LOCAL = 'local',
      SESSION = 'session',
    }
    
  • noUniqueVerify?: boolean = false

    If set to true, the StorageModule will not verify the uniqueness of the key.

# Return Value

A new StorageModule instance.

# Example

const storageModule = new StorageModule('user_info', StorageType.LOCAL);

# storageModule.getItem()

Get value of an storage item from storage module.

# Type

StorageModule<T>.getItem<K extends keyof T>(key: K): T[K] | undefined;

# Parameters

  • key: K

    Key of storage module.

# Return Value

The value of storage item.

# Example

const token = storageModule.getItem('token');

# storageModule.setItem()

Set value for an storage item in storage module.

# Type

StorageModule<T>.setItem<K extends keyof T>(key: K, value: T[K]): void;

# Parameters

  • key: K

    Key of storage module.

  • value: T[K]

    New Value.

# Example

storageModule.setItem('token', 'xxx');

# storageModule.removeItem()

Delete key and its value from storage module.

# Type

StorageModule<T>.removeItem<K extends keyof T>(key: K): void;

# Parameters

  • key: K

    Key of storage module.

# Example

storageModule.removeItem('token');

# storageModule.clear()

Delete all keys and their values from storage module.

# Type

StorageModule<T>.clear(): void;

# Example

storageModule.clear();

# storageModule.contains()

Get whether the key exists in the storage module.

# Type

StorageModule<T>.contains(key: string): boolean

# Parameters

  • key: K

    Key of storage module.

# Return Value

Whether the key exists in the storage module.

# Example

storageModule.contains('token');

# storageModule.size()

Get the number of storage items in the storage module.

# Type

StorageModule<T>.size(): number;

# Return Value

The number of storage items in the storage module.

# Example

const size = storageModule.size();

# storageModule.getHelper()

Get IStorageModuleHelper instance for storage module.

# Type

StorageModule<T>.getHelper(): IStorageModuleHelper<T>;

# Return Value

A IStorageModuleHelper instance for storage module:

interface IStorageModuleHelper<T> {
  getModule(): T;
  setModule(root: T): void;
  clearModule(): void;
  getStorageKey(): string;
  getStorageType(): StorageType;
  getExistence(): boolean;
  protect(): void;
  cancelProtect(): void;
}

# Example

const helper = storageModule.getHelper();

# helper.getModule()

Get the value of the storage module as a JSON object.

# Type

IStorageModuleHelper<T>.getModule(): T;

# Return Value

All key-value pairs in storage module.

# Example

const valueDict = helper.getModule();

# helper.setModule()

Set a JSON object as the value of the storage module. Overlay Update

# Type

IStorageModuleHelper<T>.setModule(root: T): void;

# Parameters

  • root: T

    A JSON object, which will be the value of storage module.

# Example

helper.setModule({ token: 'xxx', hasSigned: true });

# helper.clearModule()

Clear storage module.

# Type

IStorageModuleHelper<T>.clearModule(): void;

# Example

helper.clearModule();

# helper.getStorageKey()

Get the key of storage module.

# Type

IStorageModuleHelper<T>.getStorageKey(): string;

# Return Value

Storage module key.

# Example

const storageModuleKey = helper.getStorageKey();

# helper.getStorageType()

Get the type of storage module.

# Type

IStorageModuleHelper<T>.getStorageType(): StorageType;

# Return Value

enum StorageType {
  LOCAL = 'local',
  SESSION = 'session',
}

# Example

const storageType = helper.getStorageType();

# helper.getExistence()

Determine whether the storage module exists.

# Type

IStorageModuleHelper<T>.getExistence(): boolean;

# Return Value

Whether the storage module exists.

# Example

const exist = helper.getExistence();

# helper.protect()

Enable storage module protect.

# Type

IStorageModuleHelper<T>.protect(): void;

# Example

helper.protect();

# helper.cancelProtect()

Disable storage module protect.

# Type

IStorageModuleHelper<T>.cancelProtect(): void;

# Example

helper.cancelProtect();