segment.ts — astro Source File
Architecture documentation for segment.ts, a typescript file in the astro codebase.
Entity Profile
Relationship Graph
Source Code
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`);
}
}
function countOccurrences(needle: string, haystack: string) {
let count = 0;
for (const hay of haystack) {
if (hay === needle) count += 1;
}
return count;
}
Domain
Subdomains
Functions
Source
Frequently Asked Questions
What does segment.ts do?
segment.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in segment.ts?
segment.ts defines 2 function(s): countOccurrences, validateSegment.
Where is segment.ts in the architecture?
segment.ts is located at packages/astro/src/core/routing/manifest/segment.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/routing/manifest).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free