{"id":11309,"library":"micromark-util-classify-character","title":"micromark Character Classifier Utility","description":"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.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/micromark/micromark#main","tags":["javascript","micromark","util","utility","attention","classify","character","typescript"],"install":[{"cmd":"npm install micromark-util-classify-character","lang":"bash","label":"npm"},{"cmd":"yarn add micromark-util-classify-character","lang":"bash","label":"yarn"},{"cmd":"pnpm add micromark-util-classify-character","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This utility is designed to work as part of the micromark parsing ecosystem; specifically, `micromark-util-classify-character@2` is compatible with `micromark@3`.","package":"micromark","optional":false},{"reason":"The `classifyCharacter` function returns values from `constants.characterGroupWhitespace` or `constants.characterGroupPunctuation`, which are typically imported from `micromark-util-constants`.","package":"micromark-util-constants","optional":false}],"imports":[{"note":"This package is ESM only. CommonJS `require` statements are not supported for this module since version 1.0.0.","wrong":"const { classifyCharacter } = require('micromark-util-classify-character');","symbol":"classifyCharacter","correct":"import { classifyCharacter } from 'micromark-util-classify-character';"},{"note":"Constants like `characterGroupWhitespace` and `characterGroupPunctuation` are used with `classifyCharacter` and typically imported from `micromark-util-constants`. This package is also ESM-only.","wrong":"const { characterGroupWhitespace } = require('micromark-util-constants');","symbol":"characterGroupWhitespace","correct":"import { characterGroupWhitespace } from 'micromark-util-constants';"},{"note":"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.","symbol":"Code","correct":"import type { Code } from 'micromark-util-types';"}],"quickstart":{"code":"import { classifyCharacter } from 'micromark-util-classify-character';\nimport { characterGroupWhitespace, characterGroupPunctuation } from 'micromark-util-constants';\n\n/**\n * Classify a given character and return its category as a string.\n * @param {string | null} char The character to classify, or null for EOF.\n * @returns {string} The classification result.\n */\nfunction getCharacterCategory(char: string | null): string {\n  const code = char === null ? null : char.charCodeAt(0);\n  const classification = classifyCharacter(code);\n\n  switch (classification) {\n    case characterGroupWhitespace:\n      return `'${char}' (code: ${code}) is classified as WHITESPACE.`;\n    case characterGroupPunctuation:\n      return `'${char}' (code: ${code}) is classified as PUNCTUATION.`;\n    default:\n      return `'${char}' (code: ${code}) is classified as NEITHER.`;\n  }\n}\n\nconsole.log(getCharacterCategory(' ')); // Space character\nconsole.log(getCharacterCategory('\\t')); // Tab character\nconsole.log(getCharacterCategory('.')); // Period character\nconsole.log(getCharacterCategory('!')); // Exclamation mark\nconsole.log(getCharacterCategory('a')); // Letter 'a'\nconsole.log(getCharacterCategory('7')); // Digit '7'\nconsole.log(getCharacterCategory(null)); // End of file (EOF) is treated as whitespace\n","lang":"typescript","description":"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."},"warnings":[{"fix":"Migrate your project to use ES modules (`import` statements) or ensure your environment is configured for ESM.","message":"This package is ESM-only. Attempting to import it using CommonJS `require()` will result in an error.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade your Node.js runtime to version 16.x or newer.","message":"`micromark-util-classify-character@2` requires Node.js version 16 or higher.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your `micromark` package is installed at version `3.x`.","message":"This 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`.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const { classifyCharacter } = require('micromark-util-classify-character');` to `import { classifyCharacter } from 'micromark-util-classify-character';`","cause":"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`).","error":"ReferenceError: require is not defined"},{"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(...))`.","cause":"Attempting to use CommonJS `require` to import `micromark-util-classify-character`, which is an ES module, in a CommonJS context.","error":"ERR_REQUIRE_ESM"}],"ecosystem":"npm"}