Home / Function/ get() — astro Function Reference

get() — astro Function Reference

Architecture documentation for the get() function in cookies.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  f12348cf_2aaf_fe08_4139_53f1735dea1d["get()"]
  28935751_f2b1_4797_d41a_fc616c40e0a8["AstroCookies"]
  f12348cf_2aaf_fe08_4139_53f1735dea1d -->|defined in| 28935751_f2b1_4797_d41a_fc616c40e0a8
  0c4f30da_9c0f_13fa_b899_f09c97c9c0cc["has()"]
  0c4f30da_9c0f_13fa_b899_f09c97c9c0cc -->|calls| f12348cf_2aaf_fe08_4139_53f1735dea1d
  7c061eb4_0dde_43f8_b6d4_36db2f10255b["raw()"]
  7c061eb4_0dde_43f8_b6d4_36db2f10255b -->|calls| f12348cf_2aaf_fe08_4139_53f1735dea1d
  0c4f30da_9c0f_13fa_b899_f09c97c9c0cc["has()"]
  f12348cf_2aaf_fe08_4139_53f1735dea1d -->|calls| 0c4f30da_9c0f_13fa_b899_f09c97c9c0cc
  style f12348cf_2aaf_fe08_4139_53f1735dea1d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/cookies/cookies.ts lines 116–147

	get(
		key: string,
		options: AstroCookieGetOptions | undefined = undefined,
	): AstroCookie | undefined {
		// Check for outgoing Set-Cookie values first
		if (this.#outgoing?.has(key)) {
			let [serializedValue, , isSetValue] = this.#outgoing.get(key)!;
			if (isSetValue) {
				return new AstroCookie(serializedValue);
			} else {
				return undefined;
			}
		}
		// decodeURIComponent is the default decode function for cookies
		const decode = options?.decode ?? decodeURIComponent;

		const values = this.#ensureParsed();
		if (key in values) {
			const value = values[key];
			if (value) {
				let decodedValue: string;
				try {
					decodedValue = decode(value);
				} catch (_error) {
					// If decoding fails (e.g., invalid URI sequences), use the original value
					// This aligns with the behavior of the `cookie` package
					decodedValue = value;
				}
				return new AstroCookie(decodedValue);
			}
		}
	}

Domain

Subdomains

Calls

Called By

Frequently Asked Questions

What does get() do?
get() is a function in the astro codebase, defined in packages/astro/src/core/cookies/cookies.ts.
Where is get() defined?
get() is defined in packages/astro/src/core/cookies/cookies.ts at line 116.
What does get() call?
get() calls 1 function(s): has.
What calls get()?
get() is called by 2 function(s): has, raw.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free