Home / File/ escaping.js — svelte Source File

escaping.js — svelte Source File

Architecture documentation for escaping.js, a javascript file in the svelte codebase. 0 imports, 6 dependents.

File javascript SharedInternal BitFlags 6 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  cb064307_faf7_de99_b8a6_9523086a7c01["escaping.js"]
  c3ec4c82_ce35_6219_c232_12ebeea91443["template.js"]
  c3ec4c82_ce35_6219_c232_12ebeea91443 --> cb064307_faf7_de99_b8a6_9523086a7c01
  7880f852_1b7b_9ea3_4e22_732f4a684bbe["element.js"]
  7880f852_1b7b_9ea3_4e22_732f4a684bbe --> cb064307_faf7_de99_b8a6_9523086a7c01
  b25fbb61_695c_e699_cbac_73059624d603["element.js"]
  b25fbb61_695c_e699_cbac_73059624d603 --> cb064307_faf7_de99_b8a6_9523086a7c01
  74eddc85_a390_2aab_af5a_ef32b77d5430["utils.js"]
  74eddc85_a390_2aab_af5a_ef32b77d5430 --> cb064307_faf7_de99_b8a6_9523086a7c01
  1c4bc493_24af_177e_7307_a999997aceac["index.js"]
  1c4bc493_24af_177e_7307_a999997aceac --> cb064307_faf7_de99_b8a6_9523086a7c01
  22eadd41_615a_90cd_7963_26c9a3fc58cb["attributes.js"]
  22eadd41_615a_90cd_7963_26c9a3fc58cb --> cb064307_faf7_de99_b8a6_9523086a7c01
  style cb064307_faf7_de99_b8a6_9523086a7c01 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

const ATTR_REGEX = /[&"<]/g;
const CONTENT_REGEX = /[&<]/g;

/**
 * @template V
 * @param {V} value
 * @param {boolean} [is_attr]
 */
export function escape_html(value, is_attr) {
	const str = String(value ?? '');

	const pattern = is_attr ? ATTR_REGEX : CONTENT_REGEX;
	pattern.lastIndex = 0;

	let escaped = '';
	let last = 0;

	while (pattern.test(str)) {
		const i = pattern.lastIndex - 1;
		const ch = str[i];
		escaped += str.substring(last, i) + (ch === '&' ? '&amp;' : ch === '"' ? '&quot;' : '&lt;');
		last = i + 1;
	}

	return escaped + str.substring(last);
}

Subdomains

Functions

Frequently Asked Questions

What does escaping.js do?
escaping.js is a source file in the svelte codebase, written in javascript. It belongs to the SharedInternal domain, BitFlags subdomain.
What functions are defined in escaping.js?
escaping.js defines 1 function(s): escape_html.
What files import escaping.js?
escaping.js is imported by 6 file(s): attributes.js, element.js, element.js, index.js, template.js, utils.js.
Where is escaping.js in the architecture?
escaping.js is located at packages/svelte/src/escaping.js (domain: SharedInternal, subdomain: BitFlags, directory: packages/svelte/src).

Analyze Your Own Codebase

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

Try Supermodel Free