Home / Function/ coerce() — astro Function Reference

coerce() — astro Function Reference

Architecture documentation for the coerce() function in index.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  a75431aa_3e09_8b35_dd84_a632bf7e7b96["coerce()"]
  942f8bed_424f_0805_6c0b_154ed0869816["index.ts"]
  a75431aa_3e09_8b35_dd84_a632bf7e7b96 -->|defined in| 942f8bed_424f_0805_6c0b_154ed0869816
  style a75431aa_3e09_8b35_dd84_a632bf7e7b96 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/preferences/index.ts lines 64–81

export function coerce(key: string, value: unknown) {
	const type = typeof dget(DEFAULT_PREFERENCES, key);
	// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
	switch (type) {
		case 'string':
			return value;
		case 'number':
			return Number(value);
		case 'boolean': {
			if (value === 'true' || value === 1) return true;
			if (value === 'false' || value === 0) return false;
			break;
		}
		default:
			throw new Error(`Incorrect value for ${key}`);
	}
	return value as any;
}

Domain

Subdomains

Frequently Asked Questions

What does coerce() do?
coerce() is a function in the astro codebase, defined in packages/astro/src/preferences/index.ts.
Where is coerce() defined?
coerce() is defined in packages/astro/src/preferences/index.ts at line 64.

Analyze Your Own Codebase

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

Try Supermodel Free