MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / decodeEntities

Function decodeEntities

packages/core/sdk/src/artifact-preview.ts:265–277  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

263 * anything that looks like markup stays inert on the way back out.
264 */
265const decodeEntities = (value: string): string =>
266 value.replace(/&(#x?[0-9a-f]+|[a-z]+);/gi, (match, body: string) => {
267 if (body.startsWith("#")) {
268 const code =
269 body.startsWith("#x") || body.startsWith("#X")
270 ? Number.parseInt(body.slice(2), 16)
271 : Number.parseInt(body.slice(1), 10);
272 return Number.isFinite(code) && code > 0 && code <= 0x10_ff_ff
273 ? String.fromCodePoint(code)
274 : match;
275 }
276 return NAMED_ENTITIES[body.toLowerCase()] ?? match;
277 });
278
279const escapeText = (value: string): string =>
280 decodeEntities(value).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");

Callers 2

escapeTextFunction · 0.85
sanitizeAttributesFunction · 0.85

Calls 1

replaceMethod · 0.65

Tested by

no test coverage detected