Home / Function/ parseSvg() — astro Function Reference

parseSvg() — astro Function Reference

Architecture documentation for the parseSvg() function in svg.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  30531c69_d9d9_32a9_8455_19b8a0d409d3["parseSvg()"]
  d53c456b_ca45_596d_c3fb_0f448cc565ec["svg.ts"]
  30531c69_d9d9_32a9_8455_19b8a0d409d3 -->|defined in| d53c456b_ca45_596d_c3fb_0f448cc565ec
  c986786a_12cf_f805_aa49_25878b232b2f["makeSvgComponent()"]
  c986786a_12cf_f805_aa49_25878b232b2f -->|calls| 30531c69_d9d9_32a9_8455_19b8a0d409d3
  style 30531c69_d9d9_32a9_8455_19b8a0d409d3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/assets/utils/svg.ts lines 9–45

function parseSvg({
	path,
	contents,
	svgoConfig,
}: {
	path: string;
	contents: string;
	svgoConfig: AstroConfig['experimental']['svgo'];
}) {
	let processedContents = contents;
	if (svgoConfig) {
		try {
			const config = typeof svgoConfig === 'boolean' ? undefined : svgoConfig;
			const result = optimize(contents, config);
			processedContents = result.data;
		} catch (cause) {
			throw new AstroError(
				{
					...AstroErrorData.CannotOptimizeSvg,
					message: AstroErrorData.CannotOptimizeSvg.message(path),
				},
				{ cause },
			);
		}
	}
	const root = parse(processedContents);
	const svgNode = root.children.find(
		({ name, type }: { name: string; type: number }) => type === 1 /* Element */ && name === 'svg',
	);
	if (!svgNode) {
		throw new Error('SVG file does not contain an <svg> element');
	}
	const { attributes, children } = svgNode;
	const body = renderSync({ ...root, children });

	return { attributes, body };
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does parseSvg() do?
parseSvg() is a function in the astro codebase, defined in packages/astro/src/assets/utils/svg.ts.
Where is parseSvg() defined?
parseSvg() is defined in packages/astro/src/assets/utils/svg.ts at line 9.
What calls parseSvg()?
parseSvg() is called by 1 function(s): makeSvgComponent.

Analyze Your Own Codebase

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

Try Supermodel Free