Registry / serialization / micromark-util-decode-numeric-character-reference

micromark-util-decode-numeric-character-reference

JSON →
library2.0.2jsnpmunverified

micromark-util-decode-numeric-character-reference is a focused utility within the micromark ecosystem designed to safely decode numeric character references found in markdown (e.g., `A` for 'A'). The current stable major version is `2.x.x`, with `2.0.2` being the latest patch. As part of the unified collective, it follows a regular release cadence, often aligned with broader micromark updates. A key differentiator is its robust handling of non-characters and control characters, ensuring safe output by replacing them with the Unicode replacement character. This package is ESM-only and ships with full TypeScript type definitions, making it suitable for modern JavaScript and TypeScript environments, and is compatible with Node.js 16+.

npm install micromark-util-decode-numeric-character-reference
INSTALL
IMPORT
SIG · MICROMARK-UTIL-DEC
M
micromark-util-decode-numeric-character-reference
serializationjavascriptv2.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

decodeNumericCharacterReference
import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference'
const { decodeNumericCharacterReference } = require('micromark-util-decode-numeric-character-reference')
This package is ESM-only since v1 and cannot be imported with `require()`.
decodeNumericCharacterReference (Type)
import type { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference'
TypeScript types are included, use `import type` for type-only imports.

Demonstrates how to decode various numeric character references, including ASCII, control characters, and out-of-range Unicode points, showcasing the utility's safe decoding behavior.

import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference'; // Example 1: Basic ASCII character decoding from hexadecimal const charA_hex = decodeNumericCharacterReference('41', 16); console.log(`Hex '41' (16-base) decodes to: '${charA_hex}'`); // Expected: 'A' // Example 2: Basic ASCII character decoding from decimal const charA_dec = decodeNumericCharacterReference('65', 10); console.log(`Dec '65' (10-base) decodes to: '${charA_dec}'`); // Expected: 'A' // Example 3: Decoding a newline character (common in references) const newline_hex = decodeNumericCharacterReference('A', 16); console.log(`Hex 'A' (16-base) decodes to: '${JSON.stringify(newline_hex)}' (newline)`); // Expected: '\n' // Example 4: Handling control characters (these are replaced with a replacement character) const controlChar_hex = decodeNumericCharacterReference('7F', 16); // DEL character console.log(`Hex '7F' (16-base) decodes to: '${controlChar_hex}'`); // Expected: '�' (replacement character) // Example 5: Handling out-of-range Unicode code points const outOfRange_hex = decodeNumericCharacterReference('110000', 16); // Beyond U+10FFFF console.log(`Hex '110000' (16-base) decodes to: '${outOfRange_hex}'`); // Expected: '�' (replacement character) console.log("\nThis utility ensures safe decoding, replacing invalid or control characters with the Unicode replacement character.");
Debug
Known issues
breakingThis package is ESM-only and no longer supports CommonJS `require()`. Applications must use ES modules.
fix
Migrate your project to ES modules (`import`/`export`) or use a tool like `esm` for CommonJS environments if absolutely necessary. Ensure your `package.json` includes `"type": "module"` if using `.js` files with ESM.
affects: >=1.0.0
breakingThe package requires Node.js version 16 or higher.
fix
Upgrade your Node.js environment to version 16 or newer to ensure compatibility.
affects: >=2.0.0
gotchaThis utility is designed for compatibility with `micromark@3`. While it might work with other versions, compatibility is only guaranteed with `micromark@3`.
fix
Ensure your `micromark` core package is at version `3.x.x` to guarantee full compatibility and expected behavior.
affects: >=2.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES module /path/to/node_modules/micromark-util-decode-numeric-character-reference/index.js from /path/to/your/file.js not supported.
Attempting to import an ESM-only package using CommonJS `require()` syntax.
fix
Change your import statement to `import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference';` and ensure your environment supports ES modules (e.g., `"type": "module"` in `package.json`).
ReferenceError: decodeNumericCharacterReference is not defined
Incorrectly importing the named export `decodeNumericCharacterReference` without destructuring in CommonJS, or a typo in the import.
fix
If using ESM, ensure `import { decodeNumericCharacterReference } from '...'`. If you are stuck with CommonJS, you cannot directly import named exports this way for an ESM package; you must refactor to ESM.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
micromark-util-decode-numeric-character-reference — npm install micromark-util-decode-numeric-character-reference · libregistry