{"id":14704,"library":"micromark-util-character","title":"micromark Character Utilities","description":"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.","status":"active","version":"2.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/micromark/micromark#main","tags":["javascript","micromark","util","utility","character","typescript"],"install":[{"cmd":"npm install micromark-util-character","lang":"bash","label":"npm"},{"cmd":"yarn add micromark-util-character","lang":"bash","label":"yarn"},{"cmd":"pnpm add micromark-util-character","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"micromark-util-character is an ESM-only package since v1. Named imports are required as there is no default export.","wrong":"const { asciiAlpha } = require('micromark-util-character')","symbol":"asciiAlpha","correct":"import { asciiAlpha } from 'micromark-util-character'"},{"note":"Only named exports are available; there is no default export from this module.","wrong":"import markdownLineEnding from 'micromark-util-character'","symbol":"markdownLineEnding","correct":"import { markdownLineEnding } from 'micromark-util-character'"},{"note":"Ensure you are using named imports for ESM modules. Direct property access on a require result will fail.","wrong":"const unicodeWhitespace = require('micromark-util-character').unicodeWhitespace","symbol":"unicodeWhitespace","correct":"import { unicodeWhitespace } from 'micromark-util-character'"}],"quickstart":{"code":"import { asciiAlpha, markdownLineEnding, unicodePunctuation, asciiDigit } from 'micromark-util-character';\n\nconsole.log('--- Character Checks ---');\n\nconst charA = 65; // 'A'\nconst charNewline = 10; // '\\n'\nconst charAmpersand = 38; // '&'\nconst charDigit = 50; // '2'\nconst charSpace = 32; // ' '\nconst charUnicodePunctuation = 8212; // '—' (em dash)\n\nconsole.log(`Is '${String.fromCharCode(charA)}' an ASCII alpha character? ${asciiAlpha(charA)}`);\nconsole.log(`Is '${String.fromCharCode(charNewline)}' a Markdown line ending? ${markdownLineEnding(charNewline)}`);\nconsole.log(`Is '${String.fromCharCode(charAmpersand)}' a Unicode punctuation character? ${unicodePunctuation(charAmpersand)}`);\nconsole.log(`Is '${String.fromCharCode(charDigit)}' an ASCII digit character? ${asciiDigit(charDigit)}`);\nconsole.log(`Is '${String.fromCharCode(charSpace)}' a Markdown space? ${markdownLineEnding(charSpace)}`);\nconsole.log(`Is '${String.fromCharCode(charUnicodePunctuation)}' a Unicode punctuation character? ${unicodePunctuation(charUnicodePunctuation)}`);\n\n// Demonstrating a common pattern for custom parsers:\nfunction isStartOfWord(code) {\n  return asciiAlpha(code) || asciiDigit(code);\n}\n\nconst testCode = 'H'.charCodeAt(0);\nconsole.log(`Is '${String.fromCharCode(testCode)}' a start of word? ${isStartOfWord(testCode)}`);","lang":"typescript","description":"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."},"warnings":[{"fix":"Migrate your import statements to use ES modules syntax: `import { functionName } from 'micromark-util-character'`.","message":"The package transitioned to being ESM-only. CommonJS `require()` statements will no longer work and will result in errors.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=2.1.0"},{"fix":"Always convert characters to their code points using `String.prototype.charCodeAt(0)` before passing them to these utility functions.","message":"The utility functions expect character *codes* (numbers), not character *strings*. Passing a string will result in incorrect behavior or runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Be 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.","severity":"gotcha","affected_versions":">=1.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 { asciiAlpha } = require('micromark-util-character')` to `import { asciiAlpha } from 'micromark-util-character'`.","cause":"Attempting to import an ESM-only package using CommonJS `require()` syntax.","error":"ERR_REQUIRE_ESM"},{"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.","cause":"Passing `null` or `undefined` as a character code to a utility function.","error":"TypeError: Cannot read properties of undefined (reading 'charCodeAt')"},{"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'`.","cause":"Attempting to use a non-existent export or incorrect named import for a utility function.","error":"Property 'asciiAlpha' does not exist on type 'typeof import(\"micromark-util-character\")'."}],"ecosystem":"npm"}