Registry / serialization / micromark-util-classify-character

micromark-util-classify-character

JSON →
library2.0.1jsnpmunverified

The `micromark-util-classify-character` package, currently at version 2.0.1, is a focused utility within the `micromark` ecosystem designed to classify individual Unicode character codes. It categorizes characters into three groups: whitespace, punctuation, or neither. This classification is primarily used in `micromark` extensions, particularly for determining the opening and closing behavior of 'attention' sequences such as emphasis and strong formatting, which depend on the character classes surrounding the sequence. As a part of the actively maintained `micromark` project, its release cadence is tied to the broader library. A key differentiator is its low-level, performance-optimized approach to character classification, directly supporting `micromark`'s parsing algorithms. The package is ESM-only, requiring Node.js version 16 or newer, and ships with complete TypeScript type definitions, making it suitable for modern JavaScript and TypeScript environments.

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

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
Debug
Known issues
breakingThis package is ESM-only. Attempting to import it using CommonJS `require()` will result in an error.
fix
Migrate your project to use ES modules (`import` statements) or ensure your environment is configured for ESM.
affects: >=1.0.0
breaking`micromark-util-classify-character@2` requires Node.js version 16 or higher.
fix
Upgrade your Node.js runtime to version 16.x or newer.
affects: >=2.0.0
gotchaThis utility is part of the `micromark` ecosystem and is specifically designed to work with `micromark@3`. While it might function with other versions, compatibility is only guaranteed for `micromark@3`.
fix
Ensure your `micromark` package is installed at version `3.x`.
affects: >=2.0.0
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`).
fix
Change `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.
fix
Either 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(...))`.
Upgrade
Version history
2.0.1latest on npm
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`.
Agent activity
8 hits · last 30 days
node
8
Resources
micromark-util-classify-character — npm install micromark-util-classify-character · libregistry