pattern.ts — astro Source File
Architecture documentation for pattern.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 341b1026_6b09_5d29_5fc3_f56443492092["pattern.ts"] c32d12e2_d85e_28c0_eea7_9b29629857e0["../types/public/config.js"] 341b1026_6b09_5d29_5fc3_f56443492092 --> c32d12e2_d85e_28c0_eea7_9b29629857e0 10d4e39f_edb6_3e34_aa93_ae1211e7da05["../types/public/internal.js"] 341b1026_6b09_5d29_5fc3_f56443492092 --> 10d4e39f_edb6_3e34_aa93_ae1211e7da05 style 341b1026_6b09_5d29_5fc3_f56443492092 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { AstroConfig } from '../../../types/public/config.js';
import type { RoutePart } from '../../../types/public/internal.js';
export function getPattern(
segments: RoutePart[][],
base: AstroConfig['base'],
addTrailingSlash: AstroConfig['trailingSlash'],
) {
const pathname = segments
.map((segment) => {
if (segment.length === 1 && segment[0].spread) {
return '(?:\\/(.*?))?';
} else {
return (
'\\/' +
segment
.map((part) => {
if (part.spread) {
return '(.*?)';
} else if (part.dynamic) {
return '([^/]+?)';
} else {
return part.content
.normalize()
.replace(/\?/g, '%3F')
.replace(/#/g, '%23')
.replace(/%5B/g, '[')
.replace(/%5D/g, ']')
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
})
.join('')
);
}
})
.join('');
const trailing =
addTrailingSlash && segments.length ? getTrailingSlashPattern(addTrailingSlash) : '$';
let initial = '\\/';
if (addTrailingSlash === 'never' && base !== '/') {
initial = '';
}
return new RegExp(`^${pathname || initial}${trailing}`);
}
function getTrailingSlashPattern(addTrailingSlash: AstroConfig['trailingSlash']): string {
if (addTrailingSlash === 'always') {
return '\\/$';
}
if (addTrailingSlash === 'never') {
return '$';
}
return '\\/?$';
}
Domain
Subdomains
Functions
Dependencies
- ../types/public/config.js
- ../types/public/internal.js
Source
Frequently Asked Questions
What does pattern.ts do?
pattern.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 pattern.ts?
pattern.ts defines 2 function(s): getPattern, getTrailingSlashPattern.
What does pattern.ts depend on?
pattern.ts imports 2 module(s): ../types/public/config.js, ../types/public/internal.js.
Where is pattern.ts in the architecture?
pattern.ts is located at packages/astro/src/core/routing/manifest/pattern.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