Home / Function/ replaceAttribute() — astro Function Reference

replaceAttribute() — astro Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

packages/astro/src/vite-plugin-html/transform/utils.ts lines 6–24

export function replaceAttribute(s: MagicString, node: Element, key: string, newValue: string) {
	splitAttrsTokenizer.lastIndex = 0;
	const text = s.original
		.slice(node.position?.start.offset ?? 0, node.position?.end.offset ?? 0)
		.toString();
	const offset = text.indexOf(key);
	if (offset === -1) return;
	const start = node.position!.start.offset! + offset;
	const tokens = text.slice(offset).split(splitAttrsTokenizer);
	const token = tokens[0].replace(/([^>])>[\s\S]*$/gm, '$1');
	if (token.trim() === key) {
		const end = start + key.length;
		return s.overwrite(start, end, newValue, { contentOnly: true });
	} else {
		const length = token.length;
		const end = start + length;
		return s.overwrite(start, end, newValue, { contentOnly: true });
	}
}

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free