Function setToLocalStorage

  • Stores a value in the local storage with an optional expiration date.

    Parameters

    • key: string

      The key under which the value will be stored.

    • Optionalvalue: string

      The value to be stored. If not provided, an empty string will be stored.

    • Optionaloptions: { expiration: Date }

      Optional settings for the storage.

      • expiration: Date

        The expiration date for the stored value. If provided, an additional key with the expiration date will be stored.

    Returns void

    // Store a value without expiration
    setToLocalStorage('username', 'john_doe');
    // Store a value with expiration
    const expirationDate = new Date();
    expirationDate.setDate(expirationDate.getDate() + 7); // 7 days from now
    setToLocalStorage('session_token', 'abc123', { expiration: expirationDate });