Home / File/ runtime.ts — astro Source File

runtime.ts — astro Source File

Architecture documentation for runtime.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.

File typescript CoreAstro CoreMiddleware 3 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  d9525c93_ef37_466a_289a_043691fd3f8a["runtime.ts"]
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  d9525c93_ef37_466a_289a_043691fd3f8a --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  fc634da7_3e72_de83_7395_a46311dd837e["html-escaper"]
  d9525c93_ef37_466a_289a_043691fd3f8a --> fc634da7_3e72_de83_7395_a46311dd837e
  10250468_0e83_bd69_43e9_3bcef2294a91["piccolore"]
  d9525c93_ef37_466a_289a_043691fd3f8a --> 10250468_0e83_bd69_43e9_3bcef2294a91
  style d9525c93_ef37_466a_289a_043691fd3f8a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { escape } from 'html-escaper';
import colors from 'piccolore';
import { AstroErrorData, type ErrorWithMetadata } from '../index.js';

/**
 * The docs has kebab-case urls for errors, so we need to convert the error name
 * @param errorName
 */
function getKebabErrorName(errorName: string): string {
	return errorName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
export function getDocsForError(err: ErrorWithMetadata): string | undefined {
	if (err.name !== 'UnknownError' && err.name in AstroErrorData) {
		return `https://docs.astro.build/en/reference/errors/${getKebabErrorName(err.name)}/`;
	}
	return undefined;
}

const linkRegex = /\[([^[]+)\]\((.*)\)/g;
const boldRegex = /\*\*(.+)\*\*/g;
const urlRegex = / ((?:https?|ftp):\/\/[-\w+&@#\\/%?=~|!:,.;]*[-\w+&@#\\/%=~|])/gi;
const codeRegex = /`([^`]+)`/g;

/**
 * Render a subset of Markdown to HTML or a CLI output
 */
export function renderErrorMarkdown(markdown: string, target: 'html' | 'cli') {
	if (target === 'html') {
		return escape(markdown)
			.replace(linkRegex, `<a href="$2" target="_blank">$1</a>`)
			.replace(boldRegex, '<b>$1</b>')
			.replace(urlRegex, ' <a href="$1" target="_blank">$1</a>')
			.replace(codeRegex, '<code>$1</code>');
	} else {
		return markdown
			.replace(linkRegex, (_, m1, m2) => `${colors.bold(m1)} ${colors.underline(m2)}`)
			.replace(urlRegex, (fullMatch) => ` ${colors.underline(fullMatch.trim())}`)
			.replace(boldRegex, (_, m1) => `${colors.bold(m1)}`);
	}
}

Domain

Subdomains

Dependencies

  • ../core/errors/index.js
  • html-escaper
  • piccolore

Frequently Asked Questions

What does runtime.ts do?
runtime.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in runtime.ts?
runtime.ts defines 3 function(s): getDocsForError, getKebabErrorName, renderErrorMarkdown.
What does runtime.ts depend on?
runtime.ts imports 3 module(s): ../core/errors/index.js, html-escaper, piccolore.
Where is runtime.ts in the architecture?
runtime.ts is located at packages/astro/src/core/errors/dev/runtime.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/astro/src/core/errors/dev).

Analyze Your Own Codebase

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

Try Supermodel Free