Home / Function/ validateSegment() — astro Function Reference

validateSegment() — astro Function Reference

Architecture documentation for the validateSegment() function in segment.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  558914a8_7fcc_6dc1_63b1_b932026681fb["validateSegment()"]
  ee14400b_0632_5530_5739_3620df74d56f["segment.ts"]
  558914a8_7fcc_6dc1_63b1_b932026681fb -->|defined in| ee14400b_0632_5530_5739_3620df74d56f
  97157675_b53c_744a_172b_6e8e37401fee["countOccurrences()"]
  558914a8_7fcc_6dc1_63b1_b932026681fb -->|calls| 97157675_b53c_744a_172b_6e8e37401fee
  style 558914a8_7fcc_6dc1_63b1_b932026681fb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/routing/manifest/segment.ts lines 1–16

export function validateSegment(segment: string, file = '') {
	if (!file) file = segment;

	if (segment.includes('][')) {
		throw new Error(`Invalid route ${file} \u2014 parameters must be separated`);
	}
	if (countOccurrences('[', segment) !== countOccurrences(']', segment)) {
		throw new Error(`Invalid route ${file} \u2014 brackets are unbalanced`);
	}
	if (
		(/.+\[\.\.\.[^\]]+\]/.test(segment) || /\[\.\.\.[^\]]+\].+/.test(segment)) &&
		file.endsWith('.astro')
	) {
		throw new Error(`Invalid route ${file} \u2014 rest parameter must be a standalone segment`);
	}
}

Domain

Subdomains

Frequently Asked Questions

What does validateSegment() do?
validateSegment() is a function in the astro codebase, defined in packages/astro/src/core/routing/manifest/segment.ts.
Where is validateSegment() defined?
validateSegment() is defined in packages/astro/src/core/routing/manifest/segment.ts at line 1.
What does validateSegment() call?
validateSegment() calls 1 function(s): countOccurrences.

Analyze Your Own Codebase

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

Try Supermodel Free