# Decode numeric HTML entities

Turn &#233; and &#xE9; style references into characters.

Canonical: https://1loc.dev/string/decode-html-entities/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function decodeNumericEntities(text) { return text.replace(/&#(x[0-9a-f]+|\d+);/gi, (entity, code) => { const point = code[0].toLowerCase() === 'x' ? parseInt(code.slice(1), 16) : Number(code); return point <= 0x10ffff ? String.fromCodePoint(point) : entity; }); }
```

## Input

```json
"Caf&#233; &#x1F600;"
```

## Expected output

```json
"Café 😀"
```

## Edge case

Input:
```json
"&#1114112;"
```
Output:
```json
"&#1114112;"
```

## Limits

- Numeric references only; named ones such as &eacute; need an HTML parser. The original regex mishandled hexadecimal references.
- Out-of-range code points are left unchanged.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/decode-html-entities.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Rewritten for decimal and hexadecimal numeric references with a code-point range check; the original regex mishandled hexadecimal references. Original MDX retained as inert source evidence.
