Registry / developer-tools / character-entities

character-entities

JSON →
library2.0.2jsnpmunverified

Map of named character references (HTML entity names to characters). Version 2.0.2, ESM-only, fully typed with TypeScript. Minimal zero-dependency package for use in HTML parsers, minifiers, or entity handling. Provides a case-sensitive mapping of all HTML5 named character references as a plain object. Differentiators: lightweight, tree-shakeable, maintained as part of the unified ecosystem.

npm install character-entities
INSTALL
IMPORT
SIG · CHARACTER-ENTITIES
C
character-entities
developer-toolsjavascriptv2.0.2
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.

characterEntities
import { characterEntities } from 'character-entities'
const characterEntities = require('character-entities')
Package is ESM-only; CommonJS require() will throw an error. Named export only.
characterEntities (type)
import type { CharacterEntities } from 'character-entities'
TypeScript types are bundled. The type for the object is `Record<string, string>` but is exported as `CharacterEntities` for clarity.
default export
import { characterEntities } from 'character-entities'
import characterEntities from 'character-entities'
There is no default export; only the named export `characterEntities` exists.

Demonstrates importing and using the named export to look up HTML entity names. Note that the keys are entity names without the leading ampersand or trailing semicolon.

import { characterEntities } from 'character-entities'; console.log(characterEntities.AElig); // 'Æ' console.log(characterEntities.amp); // '&' console.log(characterEntities.lt); // '<' console.log(characterEntities.gt); // '>' console.log(characterEntities.quot); // '"' console.log(characterEntities['&']); // undefined, entity names are without '&' prefix
Debug
Known issues
breakingVersion 2.0 is ESM-only, dropping CommonJS support entirely.
fix
Use dynamic import() or upgrade to an ESM-compatible environment. For Node.js, set 'type': 'module' in package.json or use .mjs extension.
affects: >=2.0.0
breakingEntity names were not case-sensitive in HTML4, but are case-sensitive in HTML5. The mapping uses lowercase for most HTML5 entities, but some have uppercase variants.
fix
Use the exact casing as specified in the HTML5 spec. Refer to the object keys for correct casing.
affects: >=1.0.0
Errors
Common errors & fixes
require() of ES Module /path/to/node_modules/character-entities/index.js from /path/to/app.js not supported.
Package is ESM-only since version 2.0; CommonJS require() fails.
fix
Use `import { characterEntities } from 'character-entities'` or run in an ESM context.
Cannot find module 'character-entities' or its corresponding type declarations.
TypeScript may need `esModuleInterop` or `moduleResolution: 'node'` for ESM packages.
fix
In tsconfig.json, set `"moduleResolution": "node"` (or `"nodenext"`) and `"esModuleInterop": true`.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
61 hits · last 30 days
node
54
OpenAI (training)
1
Resources
character-entities — npm install character-entities · libregistry