What is decode-named-character-reference?
The decode-named-character-reference npm package is used to decode named character references (also known as HTML entities) into their corresponding characters. This is particularly useful when dealing with HTML or XML content where special characters are encoded as named entities.
What are decode-named-character-reference's main functionalities?
Decode Named Character Reference
This feature allows you to decode a named character reference into its corresponding character. In this example, the named character reference '&' is decoded to '&'.
const decode = require('decode-named-character-reference');
const decodedString = decode('&');
console.log(decodedString); // Output: &
Decode Multiple Named Character References
This feature allows you to decode multiple named character references within a string. In this example, both '&' and '<' are decoded to '&' and '<' respectively.
const decode = require('decode-named-character-reference');
const decodedString = decode('Hello & welcome to the world of <coding>!');
console.log(decodedString); // Output: Hello & welcome to the world of <coding>!
Other packages similar to decode-named-character-reference
he
The 'he' package (short for HTML entities) is a robust HTML entity encoder/decoder. It supports both named and numeric character references and can handle both encoding and decoding. Compared to decode-named-character-reference, 'he' offers more comprehensive functionality including encoding capabilities.
entities
The 'entities' package provides fast and robust encoding and decoding of XML and HTML entities. It supports both named and numeric character references. Similar to 'he', it offers both encoding and decoding functionalities, making it more versatile than decode-named-character-reference.
html-entities
The 'html-entities' package is another library for encoding and decoding HTML entities. It supports named, numeric, and hexadecimal character references. This package is similar to 'he' and 'entities' in terms of functionality, providing both encoding and decoding capabilities.
decode-named-character-reference

Decode named character references.
Contents
What is this?
A workaround for webpack.
When should I use this?
Never use this.
Use parse-entities
.
It uses this.
Install
This package is ESM only.
In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:
npm install decode-named-character-reference
In Deno with esm.sh
:
import {decodeNamedCharacterReference} from 'https://esm.sh/decode-named-character-reference@1'
In browsers with esm.sh
:
<script type="module">
import {decodeNamedCharacterReference} from 'https://esm.sh/decode-named-character-reference@1?bundle'
</script>
Use
import {decodeNamedCharacterReference} from 'decode-named-character-reference'
decodeNamedCharacterReference('amp')
API
This package exports the following identifier: decodeNamedCharacterReference
.
There is no default export.
decodeNamedCharacterReference(value)
Again, use parse-entities
.
Types
This package is fully typed with TypeScript.
Compatibility
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
It also works in Deno and modern browsers.
Security
This package is safe.
Related
Contribute
Yes please!
See How to Contribute to Open Source.
License
MIT © Titus Wormer