Registry /
serialization / micromark-util-classify-character
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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
classifyCharacter
✓ import { classifyCharacter } from 'micromark-util-classify-character';
✗ const { classifyCharacter } = require('micromark-util-classify-character');
This package is ESM only. CommonJS `require` statements are not supported for this module since version 1.0.0.
characterGroupWhitespace
✓ import { characterGroupWhitespace } from 'micromark-util-constants';
✗ const { characterGroupWhitespace } = require('micromark-util-constants');
Constants like `characterGroupWhitespace` and `characterGroupPunctuation` are used with `classifyCharacter` and typically imported from `micromark-util-constants`. This package is also ESM-only.
Code
✓ import type { Code } from 'micromark-util-types';
While `micromark-util-classify-character` ships its own types, if you need the `Code` type for parameters, it's typically imported from `micromark-util-types` within the micromark ecosystem.
This quickstart demonstrates how to import and use the `classifyCharacter` function to determine if a character code represents whitespace, punctuation, or neither. It also shows how to use the constants for comparison.
import { classifyCharacter } from 'micromark-util-classify-character';
import { characterGroupWhitespace, characterGroupPunctuation } from 'micromark-util-constants';
/**
* Classify a given character and return its category as a string.
* @param {string | null} char The character to classify, or null for EOF.
* @returns {string} The classification result.
*/
function getCharacterCategory(char: string | null): string {
const code = char === null ? null : char.charCodeAt(0);
const classification = classifyCharacter(code);
switch (classification) {
case characterGroupWhitespace:
return `'${char}' (code: ${code}) is classified as WHITESPACE.`;
case characterGroupPunctuation:
return `'${char}' (code: ${code}) is classified as PUNCTUATION.`;
default:
return `'${char}' (code: ${code}) is classified as NEITHER.`;
}
}
console.log(getCharacterCategory(' ')); // Space character
console.log(getCharacterCategory('\t')); // Tab character
console.log(getCharacterCategory('.')); // Period character
console.log(getCharacterCategory('!')); // Exclamation mark
console.log(getCharacterCategory('a')); // Letter 'a'
console.log(getCharacterCategory('7')); // Digit '7'
console.log(getCharacterCategory(null)); // End of file (EOF) is treated as whitespace
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use CommonJS `require` to import an ESM-only package in an ES module context (e.g., in a `.mjs` file or when `"type": "module"` is set in `package.json`).
fixChange `const { classifyCharacter } = require('micromark-util-classify-character');` to `import { classifyCharacter } from 'micromark-util-classify-character';` ERR_REQUIRE_ESM
Attempting to use CommonJS `require` to import `micromark-util-classify-character`, which is an ES module, in a CommonJS context.
fixEither convert your consuming module to ESM by adding `"type": "module"` to your `package.json` or changing its extension to `.mjs`, then use `import` syntax. Alternatively, if your project must remain CommonJS, you might need to use a dynamic import: `import('micromark-util-classify-character').then(mod => mod.classifyCharacter(...))`. Audit
Dependencies
micromarkrequiredThis utility is designed to work as part of the micromark parsing ecosystem; specifically, `micromark-util-classify-character@2` is compatible with `micromark@3`.
micromark-util-constantsrequiredThe `classifyCharacter` function returns values from `constants.characterGroupWhitespace` or `constants.characterGroupPunctuation`, which are typically imported from `micromark-util-constants`.