CSRF-X Auth Library - v1.0.3
    Preparing search index...

    Function parseSetCookie

    • Parses a raw Set-Cookie header string into its name and value.

      Parameters

      • cookieStr: string

        The raw Set-Cookie header string (e.g., "sessionId=abc123; HttpOnly; Path=/").

      Returns { name: string; value: string } | null

      An object with name and value properties, or null if
      the string does not contain a valid name‑value pair.

      This function extracts the first name=value pair before the first
      semicolon (if any). It does not parse additional attributes
      (e.g., HttpOnly, Secure, Path, Max-Age, Expires). Those are ignored.

      The extraction algorithm:

      1. Find the first semicolon (;) – everything before it is the name=value part.
      2. Split that part at the first equals sign (=) to get name and value.
      3. Trim whitespace from name and value.
      4. Return null if the name is empty after trimming.
      const parsed = parseSetCookie('sessionId=abc123; HttpOnly; Path=/');
      console.log(parsed); // { name: "sessionId", value: "abc123" }
      parseSetCookie('invalid-cookie'); // null
      
      parseSetCookie('   name   =   value   ; extra'); // { name: "name", value: "value" }
      

      0.1.1