Function: getCookie() โ
getCookie(
cookieSpec
):Promise
<ExportedCookie
[]>
Defined in: src/core/cookies/getCookie.ts:31
Retrieves browser cookies that match the specified cookie name and domain criteria. This function provides a way to search and filter cookies based on given specifications.
Parameters โ
cookieSpec โ
The cookie specification containing search criteria
domain โ
string
= CookieDomainSchema
(optional) The domain to filter cookies by
name โ
string
= CookieNameSchema
The name of the cookie to search for
Returns โ
Promise
<ExportedCookie
[]>
An array of ExportedCookie objects that match the specification
Throws โ
Will catch and handle any errors during cookie querying, logging a warning to the console without throwing to the caller
Example โ
typescript
import { getCookie } from "@mherod/get-cookie";
// Get all cookies named "sessionId"
const cookies = await getCookie({ name: "sessionId" });
// Returns: [{ name: "sessionId", value: "abc123", domain: ".example.com", ... }]
// Get cookies named "userPref" from specific domain
const domainCookies = await getCookie({
name: "userPref",
domain: "example.com"
});
// Returns: [{ name: "userPref", value: "darkMode", domain: "example.com", ... }]