@consumidor-positivo/ts-utils - v1.16.0
    Preparing search index...

    Function getCookie

    • Gets the value of a cookie by name. If the value is a valid JSON string, it will be automatically parsed.

      Type Parameters

      • T = string

      Parameters

      • name: string

        The name of the cookie to retrieve

      Returns null | T

      The cookie value (parsed if JSON), or null if the cookie doesn't exist

      // Get string cookie
      const userToken = getCookie<string>('token');
      if (userToken) {
      console.log('Token:', userToken);
      }

      // Get object cookie
      const userData = getCookie<{ id: number; name: string }>('userData');
      if (userData) {
      console.log('User:', userData.name);
      }