Home / Function/ attr() — svelte Function Reference

attr() — svelte Function Reference

Architecture documentation for the attr() function in attributes.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  c5706cd2_ff56_80ba_e35d_9c5a0c2b6647["attr()"]
  22eadd41_615a_90cd_7963_26c9a3fc58cb["attributes.js"]
  c5706cd2_ff56_80ba_e35d_9c5a0c2b6647 -->|defined in| 22eadd41_615a_90cd_7963_26c9a3fc58cb
  30cd611d_dc10_8cb7_0b6a_cde40be8727a["attributes()"]
  30cd611d_dc10_8cb7_0b6a_cde40be8727a -->|calls| c5706cd2_ff56_80ba_e35d_9c5a0c2b6647
  d6dfd043_7103_f2c7_aab3_9660fb0a5f75["escape_html()"]
  c5706cd2_ff56_80ba_e35d_9c5a0c2b6647 -->|calls| d6dfd043_7103_f2c7_aab3_9660fb0a5f75
  style c5706cd2_ff56_80ba_e35d_9c5a0c2b6647 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/shared/attributes.js lines 24–33

export function attr(name, value, is_boolean = false) {
	// attribute hidden for values other than "until-found" behaves like a boolean attribute
	if (name === 'hidden' && value !== 'until-found') {
		is_boolean = true;
	}
	if (value == null || (!value && is_boolean)) return '';
	const normalized = (name in replacements && replacements[name].get(value)) || value;
	const assignment = is_boolean ? '' : `="${escape_html(normalized, true)}"`;
	return ` ${name}${assignment}`;
}

Subdomains

Called By

Frequently Asked Questions

What does attr() do?
attr() is a function in the svelte codebase, defined in packages/svelte/src/internal/shared/attributes.js.
Where is attr() defined?
attr() is defined in packages/svelte/src/internal/shared/attributes.js at line 24.
What does attr() call?
attr() calls 1 function(s): escape_html.
What calls attr()?
attr() is called by 1 function(s): attributes.

Analyze Your Own Codebase

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

Try Supermodel Free