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

    Function setCookie

    • Sets a cookie with the specified name, value, and options. If value is an object, it will be automatically JSON-encoded.

      Parameters

      • name: string

        The name of the cookie

      • value: string | object

        The value of the cookie (string or object)

      • options: SetCookieOptions = {}

        Optional configuration for the cookie

      Returns void

      // Simple cookie
      setCookie('user', 'john');

      // Cookie with object value
      setCookie('userData', { id: 123, name: 'John' });

      // Cookie with expiration
      const expiryDate = new Date();
      expiryDate.setDate(expiryDate.getDate() + 7); // 7 days from now
      setCookie('token', 'abc123', { expiresDate: expiryDate, secure: true });

      // Cookie with all options
      const sessionExpiry = new Date();
      sessionExpiry.setDate(sessionExpiry.getDate() + 1); // 1 day from now
      setCookie('session', 'xyz', {
      expiresDate: sessionExpiry,
      path: '/',
      domain: 'example.com',
      secure: true,
      sameSite: 'Strict'
      });