Home / Function/ escapeTemplateLiteralCharacters() — astro Function Reference

escapeTemplateLiteralCharacters() — astro Function Reference

Architecture documentation for the escapeTemplateLiteralCharacters() function in utils.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  51653c43_a257_2da0_a36e_ebbdeefe2f96["escapeTemplateLiteralCharacters()"]
  b7d87f1f_ca8d_8b9e_5f88_274f48fab2cf["utils.ts"]
  51653c43_a257_2da0_a36e_ebbdeefe2f96 -->|defined in| b7d87f1f_ca8d_8b9e_5f88_274f48fab2cf
  style 51653c43_a257_2da0_a36e_ebbdeefe2f96 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/vite-plugin-html/transform/utils.ts lines 36–60

export function escapeTemplateLiteralCharacters(value: string) {
	// Reset the RegExp's global state
	NEEDS_ESCAPE_RE.lastIndex = 0;

	let char: string | undefined;
	let startIndex = 0;
	let segment = '';
	let text = '';

	// Rather than a naive `String.replace()`, we have to iterate through
	// the raw contents to properly handle existing backslashes
	while (([char] = NEEDS_ESCAPE_RE.exec(value) ?? [])) {
		// Final loop when char === undefined, append trailing content
		if (!char) {
			text += value.slice(startIndex);
			break;
		}
		const endIndex = NEEDS_ESCAPE_RE.lastIndex - char.length;
		const prefix = segment === '\\' ? '' : '\\';
		segment = prefix + char;
		text += value.slice(startIndex, endIndex) + segment;
		startIndex = NEEDS_ESCAPE_RE.lastIndex;
	}
	return text;
}

Domain

Subdomains

Frequently Asked Questions

What does escapeTemplateLiteralCharacters() do?
escapeTemplateLiteralCharacters() is a function in the astro codebase, defined in packages/astro/src/vite-plugin-html/transform/utils.ts.
Where is escapeTemplateLiteralCharacters() defined?
escapeTemplateLiteralCharacters() is defined in packages/astro/src/vite-plugin-html/transform/utils.ts at line 36.

Analyze Your Own Codebase

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

Try Supermodel Free