html-entities-list
v1.0.2
Published
[DEPRECATED] A complete, typed dataset of common HTML entities with utilities for encoding/decoding.
Maintainers
Readme
⚠️ DEPRECATED
This package is no longer maintained.
Please use html-entities instead. See: https://www.npmjs.com/package/html-entities
Original README below:
html-entities-list
(https://codecov.io/gh/venkatajanapareddy/html-entities-list)
A complete, typed dataset of common HTML entities with utilities for encoding and decoding. This library provides a comprehensive list of HTML named entities along with robust functions for encoding text to HTML entities and decoding HTML entities from text.
Features
- 📚 Complete dataset of common HTML named entities
- 🔒 Zero runtime dependencies
- 📝 Strong TypeScript support with full type definitions
- 🛠️ Utility functions for encoding and decoding
- 🧪 Thoroughly tested with high coverage
- 📦 Dual module support (ESM and CommonJS)
- 🌳 Tree-shakable
Installation
npm install html-entities-listUsage
Basic Usage
import { encodeHtmlEntities, decodeHtmlEntities } from 'html-entities-list';
// Encoding
encodeHtmlEntities('Hello & World'); // 'Hello & World'
encodeHtmlEntities('<script>'); // '<script>'
// Decoding
decodeHtmlEntities('Hello & World'); // 'Hello & World'
decodeHtmlEntities('<script>'); // '<script>'Working with Entity Data
import { htmlEntities, getEntityByName, getCharacterByEntityName } from 'html-entities-list';
// Get all entities
console.log(htmlEntities); // Array of all HTML entities
// Get entity by name
const entity = getEntityByName('©');
console.log(entity);
// {
// name: '©',
// character: '©',
// description: 'Copyright sign',
// numericDecimal: 169,
// numericHex: 'A9'
// }
// Get character by entity name
const character = getCharacterByEntityName('>');
console.log(character); // '>'Advanced Encoding Options
import { encodeHtmlEntities } from 'html-entities-list';
// Encode specific characters only
encodeHtmlEntities('<>&"\'', { subset: ['<', '>'] }); // '<>&"\''
// Encode non-ASCII characters
encodeHtmlEntities('Hello © World', { encodeNonAscii: true }); // 'Hello © World'API Reference
Data Exports
htmlEntities: Readonly<HtmlEntity[]>- Array of all HTML entitieshtmlEntityMapByName: Readonly<Record<HtmlEntityName, HtmlEntity>>- Map of entities keyed by name
Utility Functions
encodeHtmlEntities(text: string | null | undefined, options?: EncodeOptions): string
Encodes specific characters in a string into their HTML entity equivalents.
Options:
subset?: ('<' | '>' | '&' | '"' | "'")[]- Specify which characters to encodeencodeNonAscii?: boolean- Whether to encode non-ASCII characters
decodeHtmlEntities(text: string | null | undefined): string
Decodes HTML entities in a string into their corresponding characters.
getEntityByName(entityName: HtmlEntityName | string): HtmlEntity | undefined
Gets an HTML entity by its name.
getCharacterByEntityName(entityName: HtmlEntityName | string): string | undefined
Gets the decoded character for an HTML entity name.
Types
type HtmlEntityName = string; // e.g., ' ', '<'
type DecodedCharacter = string; // e.g., '\u00A0', '<'
interface HtmlEntity {
name: HtmlEntityName;
character: DecodedCharacter;
description: string;
numericDecimal?: number;
numericHex?: string;
}
interface EncodeOptions {
subset?: ('<' | '>' | '&' | '"' | "'")[];
encodeNonAscii?: boolean;
}Data Source
The HTML entity data is sourced from the WHATWG HTML Living Standard.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
