Registry / search / character-entities-html4

character-entities-html4

JSON →
library2.1.0jsnpmunverified

A map of named character references from HTML 4 (e.g., &amp; → &, &lt; → <) to their corresponding characters. Current stable version is 2.1.0. This package is ESM-only, fully typed with TypeScript, and has zero dependencies. It provides a case-sensitive mapping of 252 named entities as per the HTML 4 specification. Unlike the larger 'character-entities' package, this one only includes HTML 4 entities and excludes HTML 5 additions.

npm install character-entities-html4
INSTALL
IMPORT
SIG · CHARACTER-ENTITIES
C
character-entities-html4
searchjavascriptv2.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

characterEntitiesHtml4
import { characterEntitiesHtml4 } from 'character-entities-html4'
const characterEntitiesHtml4 = require('character-entities-html4')
ESM-only package; CommonJS require() will fail.

Demonstrates importing and using the entity map, including case sensitivity and a simple decode function.

import { characterEntitiesHtml4 } from 'character-entities-html4' // Access entities by name (case-sensitive) console.log(characterEntitiesHtml4.AElig) // 'Æ' console.log(characterEntitiesHtml4.amp) // '&' // Unknown entities return undefined console.log(characterEntitiesHtml4.apos) // undefined // Use in a simple decode function function decodeHtml4Entities(text: string): string { return text.replace(/&(\w+);/g, (match, name) => { return (characterEntitiesHtml4 as Record<string, string>)[name] ?? match }) } console.log(decodeHtml4Entities('&lt;div&gt;')) // <div>
Debug
Known issues
breakingPackage is ESM-only since v2.0.0. CommonJS require() will throw an error.
fix
Use import syntax (ESM) or switch to CommonJS-compatible version 1.x.
affects: >=2.0.0
deprecatedThe 'apos' (apostrophe) entity is not defined in HTML 4; it returns undefined.
fix
Use characterEntitiesHtml4.apos !== undefined check before using it.
affects: all
gotchaEntity names are case-sensitive. For example, 'AElig' is valid but 'aElig' is undefined.
fix
Always match the exact case as defined in HTML 4.
affects: all
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module
Using CommonJS require() on an ESM-only package (v2+).
fix
Use import instead: import { characterEntitiesHtml4 } from 'character-entities-html4'
TypeError: Cannot read properties of undefined (reading 'AElig')
Treating the entity map as a nested object instead of a flat map.
fix
Access entities directly: characterEntitiesHtml4.AElig
undefined is not a function (or similar when trying to call require)
Attempting to require() the package in a Node.js version that doesn't support ESM.
fix
Update Node.js to >=12.20 or use dynamic import() or use v1.x.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
72 hits · last 30 days
node
60
Resources
character-entities-html4 — npm install character-entities-html4 · libregistry