MCPcopy Create free account
hub / github.com/denoland/std / encodeEntities

Function encodeEntities

xml/_entities.ts:165–169  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

163 * @returns The text with special characters encoded as entities.
164 */
165export function encodeEntities(text: string): string {
166 // Fast path: no special characters means nothing to encode
167 if (!/[<>&'"]/.test(text)) return text;
168 return text.replace(SPECIAL_CHARS_REGEXP, (c) => ENTITY_MAP[c]!);
169}
170
171/**
172 * Encodes special characters for use in XML attribute values.

Callers 2

serializeNodeFunction · 0.90
_entities_test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected