util.ts — astro Source File
Architecture documentation for util.ts, a typescript file in the astro codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR a3824e79_205c_305b_a44f_edee1ef5faa4["util.ts"] e9b74c5a_8d34_34a7_e196_5e41b87214aa["../types/astro.js"] a3824e79_205c_305b_a44f_edee1ef5faa4 --> e9b74c5a_8d34_34a7_e196_5e41b87214aa c32d12e2_d85e_28c0_eea7_9b29629857e0["../types/public/config.js"] a3824e79_205c_305b_a44f_edee1ef5faa4 --> c32d12e2_d85e_28c0_eea7_9b29629857e0 10d4e39f_edb6_3e34_aa93_ae1211e7da05["../types/public/internal.js"] a3824e79_205c_305b_a44f_edee1ef5faa4 --> 10d4e39f_edb6_3e34_aa93_ae1211e7da05 87530382_6d99_2339_182d_074e3de33bc8["../vite-plugin-utils/index.js"] a3824e79_205c_305b_a44f_edee1ef5faa4 --> 87530382_6d99_2339_182d_074e3de33bc8 7216d952_4e4a_2d18_a85b_74b4ace79e2b["../core/constants.js"] a3824e79_205c_305b_a44f_edee1ef5faa4 --> 7216d952_4e4a_2d18_a85b_74b4ace79e2b 7e4494c0_5563_4329_1bff_a84be66e1bc2["../core/path.js"] a3824e79_205c_305b_a44f_edee1ef5faa4 --> 7e4494c0_5563_4329_1bff_a84be66e1bc2 e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"] a3824e79_205c_305b_a44f_edee1ef5faa4 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415 c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] a3824e79_205c_305b_a44f_edee1ef5faa4 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"] a3824e79_205c_305b_a44f_edee1ef5faa4 --> d9a92db9_c95e_9165_13ac_24b3d859d946 style a3824e79_205c_305b_a44f_edee1ef5faa4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import type { AstroSettings } from '../types/astro.js';
import type { AstroConfig } from '../types/public/config.js';
import type { RouteData } from '../types/public/internal.js';
import { hasSpecialQueries } from '../vite-plugin-utils/index.js';
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js';
import { removeQueryString, removeTrailingForwardSlash, slash } from './path.js';
/** Returns true if argument is an object of any prototype/class (but not null). */
export function isObject(value: unknown): value is Record<string, any> {
return typeof value === 'object' && value != null;
}
/** Cross-realm compatible URL */
export function isURL(value: unknown): value is URL {
return Object.prototype.toString.call(value) === '[object URL]';
}
/** Check if a file is a markdown file based on its extension */
export function isMarkdownFile(fileId: string, option?: { suffix?: string }): boolean {
if (hasSpecialQueries(fileId)) {
return false;
}
const id = removeQueryString(fileId);
const _suffix = option?.suffix ?? '';
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
if (id.endsWith(`${markdownFileExtension}${_suffix}`)) return true;
}
return false;
}
/** Wraps an object in an array. If an array is passed, ignore it. */
export function arraify<T>(target: T | T[]): T[] {
return Array.isArray(target) ? target : [target];
}
export function padMultilineString(source: string, n = 2) {
const lines = source.split(/\r?\n/);
return lines.map((l) => ` `.repeat(n) + l).join(`\n`);
}
const STATUS_CODE_PAGES = new Set(['/404', '/500']);
/**
* Get the correct output filename for a route, based on your config.
* Handles both "/foo" and "foo" `name` formats.
* Handles `/404` and `/` correctly.
*/
export function getOutputFilename(
buildFormat: NonNullable<AstroConfig['build']>['format'],
name: string,
routeData: RouteData,
) {
if (routeData.type === 'endpoint') {
return name;
}
if (name === '/' || name === '') {
return path.posix.join(name, 'index.html');
// ... (142 more lines)
Domain
Subdomains
Functions
Dependencies
- ../core/constants.js
- ../core/path.js
- ../types/astro.js
- ../types/public/config.js
- ../types/public/internal.js
- ../vite-plugin-utils/index.js
- node:fs
- node:path
- node:url
Source
Frequently Asked Questions
What does util.ts do?
util.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 util.ts?
util.ts defines 19 function(s): arraify, endsWithPageExt, ensureProcessNodeEnv, getOutputFilename, isEndpoint, isInPagesDir, isInjectedRoute, isMarkdownFile, isObject, isPage, and 9 more.
What does util.ts depend on?
util.ts imports 9 module(s): ../core/constants.js, ../core/path.js, ../types/astro.js, ../types/public/config.js, ../types/public/internal.js, ../vite-plugin-utils/index.js, node:fs, node:path, and 1 more.
Where is util.ts in the architecture?
util.ts is located at packages/astro/src/core/util.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free