StorageUtils: {
    clearCookies(options?): void;
    clearLocal(options?): void;
    clearSession(options?): void;
    decrypt(value, key?): Promise<string>;
    encrypt(value, key?): Promise<string>;
    getAllCookies(options?): Promise<Record<string, string>>;
    getCookie(name, options?): Promise<null | string>;
    getLocal<T>(key, options?): Promise<null | T>;
    getSession<T>(key, options?): Promise<null | T>;
    getStorageQuota(): Promise<null | {
        quota: number;
        usage: number;
        remaining: number;
    }>;
    getStorageSize(value): number;
    getTotalStorageSize(type): number;
    isStorageAvailable(type): boolean;
    removeCookie(name, options?): void;
    removeLocal(key): void;
    removeSession(key): void;
    setCookie(name, value, options?): Promise<void>;
    setLocal(key, value, options?): Promise<void>;
    setSession(key, value, options?): Promise<void>;
} = ...

Type declaration

  • clearCookies:function
    • Clears all cookies.

      Parameters

      • options: {
            exclude?: string[];
            path?: string;
            domain?: string;
        } = {}

        Clear options

        • Optional exclude?: string[]

          Cookie names to exclude from clearing

        • Optional path?: string

          Cookie path

        • Optional domain?: string

          Cookie domain

      Returns void

      Example

      // Clear all cookies
      StorageUtils.clearCookies();

      // Clear cookies except 'session'
      StorageUtils.clearCookies({ exclude: ['session'] });
  • clearLocal:function
    • Clears all values from localStorage.

      Parameters

      • options: {
            exclude?: string[];
        } = {}

        Clear options

        • Optional exclude?: string[]

          Keys to exclude from clearing

      Returns void

      Example

      // Clear all localStorage
      StorageUtils.clearLocal();

      // Clear localStorage except 'settings'
      StorageUtils.clearLocal({ exclude: ['settings'] });
  • clearSession:function
    • Clears all values from sessionStorage.

      Parameters

      • options: {
            exclude?: string[];
        } = {}

        Clear options

        • Optional exclude?: string[]

          Keys to exclude from clearing

      Returns void

      Example

      // Clear all sessionStorage
      StorageUtils.clearSession();

      // Clear sessionStorage except 'temp'
      StorageUtils.clearSession({ exclude: ['temp'] });
  • decrypt:function
    • Decrypts an encrypted string value.

      Parameters

      • value: string

        Value to decrypt

      • Optional key: string

        Optional encryption key (defaults to a secure key)

      Returns Promise<string>

      Promise resolving to decrypted value

      Throws

      Error if decryption fails

      Example

      const decrypted = await StorageUtils.decrypt(encryptedValue);
      
  • encrypt:function
    • Encrypts a string value.

      Parameters

      • value: string

        Value to encrypt

      • Optional key: string

        Optional encryption key (defaults to a secure key)

      Returns Promise<string>

      Promise resolving to encrypted value

      Throws

      Error if encryption fails

      Example

      const encrypted = await StorageUtils.encrypt('sensitive-data');
      
  • getAllCookies:function
    • Gets all cookies.

      Parameters

      • options: {
            decrypt?: boolean;
        } = {}

        Cookie options

        • Optional decrypt?: boolean

          Whether to decrypt the values

      Returns Promise<Record<string, string>>

      Object containing all cookies

      Example

      // Get all cookies
      const cookies = StorageUtils.getAllCookies();

      // Get all cookies with decryption
      const decryptedCookies = await StorageUtils.getAllCookies({ decrypt: true });
  • getCookie:function
    • Gets a cookie value.

      Parameters

      • name: string

        Cookie name

      • options: {
            decrypt?: boolean;
        } = {}

        Cookie options

        • Optional decrypt?: boolean

          Whether to decrypt the value

      Returns Promise<null | string>

      Cookie value or null if not found

      Example

      // Get a cookie
      const value = StorageUtils.getCookie('theme');

      // Get and decrypt a cookie
      const decryptedValue = await StorageUtils.getCookie('token', { decrypt: true });
  • getLocal:function
    • Gets a value from localStorage.

      Type Parameters

      • T

      Parameters

      • key: string

        Storage key

      • options: {
            decrypt?: boolean;
            defaultValue?: T;
        } = {}

        Storage options

        • Optional decrypt?: boolean

          Whether to decrypt the value

        • Optional defaultValue?: T

          Default value if not found/expired

      Returns Promise<null | T>

      Stored value or null if not found/expired

      Example

      // Get a value
      const value = StorageUtils.getLocal<string>('name');

      // Get and decrypt a value with default
      const decryptedValue = await StorageUtils.getLocal<string>('token', {
      decrypt: true,
      defaultValue: 'default-token'
      });
  • getSession:function
    • Gets a value from sessionStorage.

      Type Parameters

      • T

      Parameters

      • key: string

        Storage key

      • options: {
            decrypt?: boolean;
            defaultValue?: T;
        } = {}

        Storage options

        • Optional decrypt?: boolean

          Whether to decrypt the value

        • Optional defaultValue?: T

          Default value if not found/expired

      Returns Promise<null | T>

      Stored value or null if not found/expired

      Example

      // Get a value
      const value = StorageUtils.getSession<string>('temp');

      // Get and decrypt a value with default
      const decryptedValue = await StorageUtils.getSession<string>('token', {
      decrypt: true,
      defaultValue: 'default-token'
      });
  • getStorageQuota:function
    • Gets the storage quota and usage.

      Returns Promise<null | {
          quota: number;
          usage: number;
          remaining: number;
      }>

      Promise resolving to object containing quota and usage information

      Example

      const quota = await StorageUtils.getStorageQuota();
      console.log(`Usage: ${quota?.usage} / ${quota?.quota}`);
  • getStorageSize:function
    • Gets the size of a stored value.

      Parameters

      • value: unknown

        Value to measure

      Returns number

      Size in bytes

      Example

      const size = StorageUtils.getStorageSize({ data: 'large' });
      console.log(`Size: ${size} bytes`);
  • getTotalStorageSize:function
    • Gets the total size of all stored values.

      Parameters

      • type: "localStorage" | "sessionStorage"

        Storage type ('localStorage' or 'sessionStorage')

      Returns number

      Total size in bytes

      Example

      const totalSize = StorageUtils.getTotalStorageSize('localStorage');
      console.log(`Total size: ${totalSize} bytes`);
  • isStorageAvailable:function
    • Checks if storage is available.

      Parameters

      • type: "localStorage" | "sessionStorage" | "cookie"

        Storage type ('localStorage', 'sessionStorage', or 'cookie')

      Returns boolean

      True if storage is available

      Example

      if (StorageUtils.isStorageAvailable('localStorage')) {
      // Use localStorage
      }
  • removeCookie:function
    • Removes a cookie.

      Parameters

      • name: string

        Cookie name

      • options: {
            path?: string;
            domain?: string;
        } = {}

        Cookie options

        • Optional path?: string

          Cookie path

        • Optional domain?: string

          Cookie domain

      Returns void

      Example

      StorageUtils.removeCookie('session');
      
  • removeLocal:function
    • Removes a value from localStorage.

      Parameters

      • key: string

        Storage key

      Returns void

      Example

      StorageUtils.removeLocal('user');
      
  • removeSession:function
    • Removes a value from sessionStorage.

      Parameters

      • key: string

        Storage key

      Returns void

      Example

      StorageUtils.removeSession('temp');
      
  • setCookie:function
    • Sets a cookie.

      Parameters

      • name: string

        Cookie name

      • value: string

        Cookie value

      • options: {
            expires?: number | Date;
            path?: string;
            domain?: string;
            secure?: boolean;
            sameSite?: "Strict" | "Lax" | "None";
            encrypt?: boolean;
        } = {}

        Cookie options

        • Optional expires?: number | Date

          Expiration time in milliseconds or Date

        • Optional path?: string

          Cookie path

        • Optional domain?: string

          Cookie domain

        • Optional secure?: boolean

          Whether the cookie requires HTTPS

        • Optional sameSite?: "Strict" | "Lax" | "None"

          SameSite attribute

        • Optional encrypt?: boolean

          Whether to encrypt the value

      Returns Promise<void>

      Example

      // Set a basic cookie
      StorageUtils.setCookie('theme', 'dark');

      // Set a secure cookie with expiration
      StorageUtils.setCookie('token', 'secret', {
      expires: 86400000,
      secure: true,
      sameSite: 'Strict'
      });
  • setLocal:function
    • Sets a value in localStorage.

      Parameters

      • key: string

        Storage key

      • value: unknown

        Value to store

      • options: {
            expires?: number;
            encrypt?: boolean;
        } = {}

        Storage options

        • Optional expires?: number

          Expiration time in milliseconds

        • Optional encrypt?: boolean

          Whether to encrypt the value

      Returns Promise<void>

      Example

      // Set a basic value
      StorageUtils.setLocal('user', { id: 1, name: 'John' });

      // Set an encrypted value with expiration
      StorageUtils.setLocal('token', 'secret', {
      expires: 3600000,
      encrypt: true
      });
  • setSession:function
    • Sets a value in sessionStorage.

      Parameters

      • key: string

        Storage key

      • value: unknown

        Value to store

      • options: {
            expires?: number;
            encrypt?: boolean;
        } = {}

        Storage options

        • Optional expires?: number

          Expiration time in milliseconds

        • Optional encrypt?: boolean

          Whether to encrypt the value

      Returns Promise<void>

      Example

      // Set a basic value
      StorageUtils.setSession('temp', { id: 1 });

      // Set an encrypted value with expiration
      StorageUtils.setSession('token', 'secret', {
      expires: 3600000,
      encrypt: true
      });