remotePatternToRegex() — astro Function Reference
Architecture documentation for the remotePatternToRegex() function in index.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD a41e64d4_8e99_aca4_7b01_4ee87210faea["remotePatternToRegex()"] 01c2fa75_d554_caf7_1c43_205032b5e695["index.ts"] a41e64d4_8e99_aca4_7b01_4ee87210faea -->|defined in| 01c2fa75_d554_caf7_1c43_205032b5e695 242ad5a4_662b_3ad6_2c84_c29d228d0286["remoteImagesFromAstroConfig()"] 242ad5a4_662b_3ad6_2c84_c29d228d0286 -->|calls| a41e64d4_8e99_aca4_7b01_4ee87210faea style a41e64d4_8e99_aca4_7b01_4ee87210faea fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/integrations/netlify/src/index.ts lines 38–107
export function remotePatternToRegex(
pattern: RemotePattern,
logger: AstroIntegrationLogger,
): string | undefined {
let { protocol, hostname, port, pathname } = pattern;
let regexStr = '';
if (protocol) {
regexStr += `${protocol}://`;
} else {
// Default to matching any protocol
regexStr += '[a-z]+://';
}
if (hostname) {
if (hostname.startsWith('**.')) {
// match any number of subdomains
regexStr += '([a-z0-9-]+\\.)*';
hostname = hostname.substring(3);
} else if (hostname.startsWith('*.')) {
// match one subdomain
regexStr += '([a-z0-9-]+\\.)?';
hostname = hostname.substring(2); // Remove '*.' from the beginning
}
// Escape dots in the hostname
regexStr += hostname.replace(/\./g, '\\.');
} else {
regexStr += '[a-z0-9.-]+';
}
if (port) {
regexStr += `:${port}`;
} else {
// Default to matching any port
regexStr += '(:[0-9]+)?';
}
if (pathname) {
if (pathname.endsWith('/**')) {
// Match any path.
regexStr += `(\\${pathname.replace('/**', '')}.*)`;
}
if (pathname.endsWith('/*')) {
// Match one level of path
regexStr += `(\\${pathname.replace('/*', '')}\/[^/?#]+)\/?`;
} else {
// Exact match
regexStr += `(\\${pathname})`;
}
} else {
// Default to matching any path
regexStr += '(\\/[^?#]*)?';
}
if (!regexStr.endsWith('.*)')) {
// Match query, but only if it's not already matched by the pathname
regexStr += '([?][^#]*)?';
}
try {
new RegExp(regexStr);
} catch {
logger.warn(
`Could not generate a valid regex from the remotePattern "${JSON.stringify(
pattern,
)}". Please check the syntax.`,
);
return undefined;
}
return regexStr;
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does remotePatternToRegex() do?
remotePatternToRegex() is a function in the astro codebase, defined in packages/integrations/netlify/src/index.ts.
Where is remotePatternToRegex() defined?
remotePatternToRegex() is defined in packages/integrations/netlify/src/index.ts at line 38.
What calls remotePatternToRegex()?
remotePatternToRegex() is called by 1 function(s): remoteImagesFromAstroConfig.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free