MCPcopy Index your code
hub / github.com/formatjs/formatjs / decodeJSXAttributeValue

Function decodeJSXAttributeValue

packages/unplugin/transform.ts:47–69  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

45}
46
47function decodeJSXAttributeValue(value: string): string {
48 return value.replace(
49 /&(#(?:x[0-9a-fA-F]+|\d+)|[a-zA-Z][\w.-]*);/g,
50 (match, entity: string) => {
51 if (entity[0] === '#') {
52 const radix = entity[1]?.toLowerCase() === 'x' ? 16 : 10
53 const digits = radix === 16 ? entity.slice(2) : entity.slice(1)
54 const codePoint = Number.parseInt(digits, radix)
55 if (
56 !Number.isFinite(codePoint) ||
57 codePoint <= 0 ||
58 codePoint > 0x10ffff
59 ) {
60 return match
61 }
62 return String.fromCodePoint(codePoint)
63 }
64
65 const decoded = decodeNamedCharacterReference(entity)
66 return decoded === false ? match : decoded
67 }
68 )
69}
70
71export function transform(
72 code: string,

Callers 1

extractJSXDescriptorFunction · 0.85

Calls 1

isFiniteMethod · 0.80

Tested by

no test coverage detected