Registry / serialization / micromark-util-character

micromark-util-character

JSON →
library2.1.1jsnpmunverified

micromark-util-character is a utility package within the micromark ecosystem, providing a collection of pure functions to efficiently check whether a given character code belongs to various predefined groups, such as ASCII alphanumeric, punctuation, or Markdown-specific line endings and spaces. It is currently at version 2.1.1. As part of the larger micromark project, its release cadence is tied to the main project's development. This package is crucial for developers building custom micromark extensions or parsers who need granular control and performant character classification, differentiating itself by offering a specialized, low-level API for fundamental parsing operations rather than general-purpose string manipulation.

npm install micromark-util-character
INSTALL
IMPORT
SIG · MICROMARK-UTIL-CHA
M
micromark-util-character
serializationjavascriptv2.1.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.

asciiAlpha
import { asciiAlpha } from 'micromark-util-character'
const { asciiAlpha } = require('micromark-util-character')
micromark-util-character is an ESM-only package since v1. Named imports are required as there is no default export.
markdownLineEnding
import { markdownLineEnding } from 'micromark-util-character'
import markdownLineEnding from 'micromark-util-character'
Only named exports are available; there is no default export from this module.
unicodeWhitespace
import { unicodeWhitespace } from 'micromark-util-character'
const unicodeWhitespace = require('micromark-util-character').unicodeWhitespace
Ensure you are using named imports for ESM modules. Direct property access on a require result will fail.

This quickstart demonstrates how to use several utility functions to check character codes for various properties, such as being an ASCII alpha, Markdown line ending, or Unicode punctuation. It also shows a simple custom function combining these utilities.

import { asciiAlpha, markdownLineEnding, unicodePunctuation, asciiDigit } from 'micromark-util-character'; console.log('--- Character Checks ---'); const charA = 65; // 'A' const charNewline = 10; // '\n' const charAmpersand = 38; // '&' const charDigit = 50; // '2' const charSpace = 32; // ' ' const charUnicodePunctuation = 8212; // '—' (em dash) console.log(`Is '${String.fromCharCode(charA)}' an ASCII alpha character? ${asciiAlpha(charA)}`); console.log(`Is '${String.fromCharCode(charNewline)}' a Markdown line ending? ${markdownLineEnding(charNewline)}`); console.log(`Is '${String.fromCharCode(charAmpersand)}' a Unicode punctuation character? ${unicodePunctuation(charAmpersand)}`); console.log(`Is '${String.fromCharCode(charDigit)}' an ASCII digit character? ${asciiDigit(charDigit)}`); console.log(`Is '${String.fromCharCode(charSpace)}' a Markdown space? ${markdownLineEnding(charSpace)}`); console.log(`Is '${String.fromCharCode(charUnicodePunctuation)}' a Unicode punctuation character? ${unicodePunctuation(charUnicodePunctuation)}`); // Demonstrating a common pattern for custom parsers: function isStartOfWord(code) { return asciiAlpha(code) || asciiDigit(code); } const testCode = 'H'.charCodeAt(0); console.log(`Is '${String.fromCharCode(testCode)}' a start of word? ${isStartOfWord(testCode)}`);
Debug
Known issues
breakingThe package transitioned to being ESM-only. CommonJS `require()` statements will no longer work and will result in errors.
fix
Migrate your import statements to use ES modules syntax: `import { functionName } from 'micromark-util-character'`.
affects: >=1.0.0
breakingVersion 2.1.0 included updates for 'CM 0.31' and added Unicode symbols for attention. While not explicitly detailed as breaking, changes related to character attention and CommonMark versions can subtly alter parsing behavior if custom extensions relied on previous interpretations.
fix
Review any custom micromark extensions that interact closely with character classification, especially for Unicode characters or 'attention' mechanisms, and test thoroughly with the new version.
affects: >=2.1.0
gotchaThe utility functions expect character *codes* (numbers), not character *strings*. Passing a string will result in incorrect behavior or runtime errors.
fix
Always convert characters to their code points using `String.prototype.charCodeAt(0)` before passing them to these utility functions.
affects: >=1.0.0
gotchaBe mindful of the distinction between 'ASCII' and 'Unicode' prefixed functions. Functions like `asciiAlpha` only check within the ASCII range, while `unicodePunctuation` and `unicodeWhitespace` handle a broader set of characters. Using an ASCII-only check for non-ASCII input will yield false results.
fix
Choose the appropriate utility function based on the character set you intend to handle. For broader internationalization, prefer `unicode*` checks where available or implement custom logic.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to import an ESM-only package using CommonJS `require()` syntax.
fix
Change `const { asciiAlpha } = require('micromark-util-character')` to `import { asciiAlpha } from 'micromark-util-character'`.
TypeError: Cannot read properties of undefined (reading 'charCodeAt')
Passing `null` or `undefined` as a character code to a utility function.
fix
Ensure the input to character utility functions is always a valid number representing a character code. Add checks for `null` or `undefined` if the source of the code is untrustworthy.
Property 'asciiAlpha' does not exist on type 'typeof import("micromark-util-character")'.
Attempting to use a non-existent export or incorrect named import for a utility function.
fix
Verify the exact name of the imported function and ensure it is correctly destructured from the named exports, e.g., `import { asciiAlpha } from 'micromark-util-character'`.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

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