{"id":11311,"library":"micromark-util-decode-numeric-character-reference","title":"micromark Numeric Character Reference Decoder","description":"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., `&#x41;` 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+.","status":"active","version":"2.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/micromark/micromark#main","tags":["javascript","micromark","util","utility","decode","numeric","number","character","reference","typescript"],"install":[{"cmd":"npm install micromark-util-decode-numeric-character-reference","lang":"bash","label":"npm"},{"cmd":"yarn add micromark-util-decode-numeric-character-reference","lang":"bash","label":"yarn"},{"cmd":"pnpm add micromark-util-decode-numeric-character-reference","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since v1 and cannot be imported with `require()`.","wrong":"const { decodeNumericCharacterReference } = require('micromark-util-decode-numeric-character-reference')","symbol":"decodeNumericCharacterReference","correct":"import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference'"},{"note":"TypeScript types are included, use `import type` for type-only imports.","symbol":"decodeNumericCharacterReference (Type)","correct":"import type { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference'"}],"quickstart":{"code":"import { decodeNumericCharacterReference } from 'micromark-util-decode-numeric-character-reference';\n\n// Example 1: Basic ASCII character decoding from hexadecimal\nconst charA_hex = decodeNumericCharacterReference('41', 16);\nconsole.log(`Hex '41' (16-base) decodes to: '${charA_hex}'`); // Expected: 'A'\n\n// Example 2: Basic ASCII character decoding from decimal\nconst charA_dec = decodeNumericCharacterReference('65', 10);\nconsole.log(`Dec '65' (10-base) decodes to: '${charA_dec}'`); // Expected: 'A'\n\n// Example 3: Decoding a newline character (common in references)\nconst newline_hex = decodeNumericCharacterReference('A', 16);\nconsole.log(`Hex 'A' (16-base) decodes to: '${JSON.stringify(newline_hex)}' (newline)`); // Expected: '\\n'\n\n// Example 4: Handling control characters (these are replaced with a replacement character)\nconst controlChar_hex = decodeNumericCharacterReference('7F', 16); // DEL character\nconsole.log(`Hex '7F' (16-base) decodes to: '${controlChar_hex}'`); // Expected: '�' (replacement character)\n\n// Example 5: Handling out-of-range Unicode code points\nconst outOfRange_hex = decodeNumericCharacterReference('110000', 16); // Beyond U+10FFFF\nconsole.log(`Hex '110000' (16-base) decodes to: '${outOfRange_hex}'`); // Expected: '�' (replacement character)\n\nconsole.log(\"\\nThis utility ensures safe decoding, replacing invalid or control characters with the Unicode replacement character.\");","lang":"typescript","description":"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."},"warnings":[{"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.","message":"This package is ESM-only and no longer supports CommonJS `require()`. Applications must use ES modules.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade your Node.js environment to version 16 or newer to ensure compatibility.","message":"The package requires Node.js version 16 or higher.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your `micromark` core package is at version `3.x.x` to guarantee full compatibility and expected behavior.","message":"This utility is designed for compatibility with `micromark@3`. While it might work with other versions, compatibility is only guaranteed with `micromark@3`.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'16':118 '2':40 '2.0.2':43 'align':61 'broader':63 'cadenc':59 'charact':3,11,26,76,79,90,126 'collect':53 'compat':115 'control':78 'current':35 'decod':5,9,24,123 'definit':103 'design':21 'differenti':68 'e.g':31 'ecosystem':20 'ensur':80 'environ':112 'esm':95 'esm-on':94 'focus':15 'follow':55 'found':28 'full':100 'handl':72 'javascript':109,119 'key':67 'latest':46 'major':37 'make':104 'markdown':30 'micromark':1,7,19,64,120 'micromark-util-decode-numeric-character-refer':6 'modern':108 'node.js':117 'non':75 'non-charact':74 'number':125 'numer':2,10,25,124 'often':60 'output':82 'packag':92 'part':49 'patch':47 'refer':4,12,27,127 'regular':57 'releas':58 'replac':84,89 'robust':71 'safe':23,81 'ship':98 'stabl':36 'suitabl':106 'type':102 'typescript':101,111,128 'unicod':88 'unifi':52 'updat':65 'util':8,16,121,122 'version':38 'within':17 'x.x':41","created_at":"2026-04-19T13:37:19.562798+00:00","updated_at":"2026-04-19T13:37:19.562798+00:00","problems":[{"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`).","cause":"Attempting to import an ESM-only package using CommonJS `require()` syntax.","error":"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."},{"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.","cause":"Incorrectly importing the named export `decodeNumericCharacterReference` without destructuring in CommonJS, or a typo in the import.","error":"ReferenceError: decodeNumericCharacterReference is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/micromark/micromark.git#main","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/micromark-util-decode-numeric-character-reference","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}