Registry / serialization / micromark-util-decode-string

micromark-util-decode-string

JSON →
library2.0.1jsnpmunverified

micromark-util-decode-string is a low-level utility within the unifiedjs `micromark` ecosystem, specifically designed to process and decode character escapes and character references found in Markdown strings. It provides a single, focused function, `decodeString`, which is crucial for correctly interpreting content in areas like fenced code info strings, link destinations, labels, and titles according to the CommonMark specification. The current stable version for this utility is `2.0.1`, which is compatible with `micromark@3` and Node.js 16 and higher. While part of a larger monorepo, this package maintains its own versioning tied to its API stability. Its release cadence generally aligns with major `micromark` releases, often involving updates to drop support for unmaintained Node.js versions. As an ESM-only package, it adheres to modern JavaScript module standards. Its key differentiator is its precise adherence to Markdown specification for string decoding, making it an essential building block for custom `micromark` extensions or other Markdown processing tools.

npm install micromark-util-decode-string
INSTALL
IMPORT
SIG · MICROMARK-UTIL-DEC
M
micromark-util-decode-string
serializationjavascriptv2.0.1
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.

decodeString
import { decodeString } from 'micromark-util-decode-string';
const { decodeString } = require('micromark-util-decode-string');
This package is ESM-only. CommonJS `require` is not supported. Use dynamic import for compatibility if needed.
decodeString
import { decodeString } from 'https://esm.sh/micromark-util-decode-string@2'
import { decodeString } from 'micromark-util-decode-string';
For Deno or browser environments, use an ESM CDN like `esm.sh` and specify the version, e.g., `@2` for v2.x.
decodeString (Type)
import type { decodeString } from 'micromark-util-decode-string';
When only importing the type of `decodeString`, use `import type` for better tree-shaking and clarity in TypeScript.

This quickstart demonstrates the `decodeString` function's capability to correctly interpret and resolve various character escapes and references found within Markdown strings, including HTML entities, numeric references, and backslash escapes. It covers common use cases for this low-level utility, which is fundamental to `micromark`'s parsing process.

import { decodeString } from 'micromark-util-decode-string'; // Example 1: Decoding HTML character references like `&` console.log('Decoding HTML character references:'); const htmlRefString = 'This is a string with & entities ©.'; console.log(`Original: "${htmlRefString}"`); console.log(`Decoded: "${decodeString(htmlRefString)}"`); // Expected output: Original: "This is a string with & entities ©." // Decoded: "This is a string with & entities ©." console.log('\n---'); // Example 2: Decoding numeric character references (decimal and hexadecimal) console.log('Decoding numeric character references:'); const numericRefString = 'Hello € world ☺!'; console.log(`Original: "${numericRefString}"`); console.log(`Decoded: "${decodeString(numericRefString)}"`); // Expected output: Original: "Hello € world ☺!" // Decoded: "Hello € world ☺!" console.log('\n---'); // Example 3: Decoding Markdown character escapes (e.g., backslash escapes) console.log('Decoding Markdown character escapes:'); const escapeString = 'Special characters like \\*asterisks\\* and \\_underscores\\_ are unescaped.'; console.log(`Original: "${escapeString}"`); console.log(`Decoded: "${decodeString(escapeString)}"`); // Expected output: Original: "Special characters like \*asterisks\* and \_underscores\_ are unescaped." // Decoded: "Special characters like *asterisks* and _underscores_ are unescaped." console.log('\n---'); // Example 4: Mixed string with common markdown context, simulating internal micromark use console.log('Mixed context decoding:'); const mixedString = 'A link title with some \\& escaped characters — "Example"'; console.log(`Original: "${mixedString}"`); console.log(`Decoded: "${decodeString(mixedString)}"`); // Expected output: Original: "A link title with some \& escaped characters — "Example"" // Decoded: "A link title with some & escaped characters — "Example"" // This utility is typically used internally by micromark or in custom micromark extensions // for precise Markdown string processing.
Debug
Known issues
breakingMajor versions of `micromark-util-decode-string` may drop support for unmaintained Node.js versions. Version `2.x` is compatible with Node.js 16 and higher.
fix
Ensure your Node.js environment is updated to a currently maintained LTS version (e.g., Node.js 16+, 18+, 20+). Refer to the Node.js release schedule for support timelines.
affects: >=2.0.0
gotchaThis package is ESM-only and does not provide a CommonJS export. Attempting to `require()` it will result in a module loading error.
fix
Migrate your project to use ECMAScript Modules (`import` / `export`) or use dynamic `import()` if you need to load ESM from a CommonJS context. Ensure your `package.json` specifies `"type": "module"` if running in Node.js.
affects: >=2.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: Must use import to load ES Module: .../node_modules/micromark-util-decode-string/index.js
Attempting to import `micromark-util-decode-string` using CommonJS `require()` syntax in a Node.js environment.
fix
Change your import statement from `const { decodeString } = require('micromark-util-decode-string');` to `import { decodeString } from 'micromark-util-decode-string';`. Ensure your `package.json` is configured for ESM, or use a bundler.
TypeError: Cannot read properties of undefined (reading 'decodeString')
This error often indicates that the module was loaded incorrectly or the named export `decodeString` was not found, possibly due to a CommonJS-style default import `import decodeString from '...'`. The package provides only named exports.
fix
Verify that you are using a named import: `import { decodeString } from 'micromark-util-decode-string';`. Avoid default imports or incorrect destructuring.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
micromark-util-decode-string — npm install micromark-util-decode-string · libregistry