micromark Utility Types

2.0.2 · active · verified Sun Apr 19

micromark-util-types is a utility package within the micromark ecosystem, currently at version 2.0.2. Its sole purpose is to provide a comprehensive set of TypeScript types that are shared across various micromark packages, enabling developers to create robust and type-safe micromark extensions. The package itself exports no runtime code or identifiers, serving purely as a type declaration module. This focused approach differentiates it from general-purpose utility libraries, making it an essential dependency for anyone building custom parsers or extensions with TypeScript for micromark. Releases typically align with the broader micromark monorepo, with updates often focusing on performance, bug fixes, and maintaining compatibility with supported Node.js versions and the latest micromark parser core.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing and utilizing key TypeScript types like `Code`, `State`, `Effects`, `TokenType`, `Point`, and `Token` to define functions for a custom micromark tokenizer extension.

import type {
  Code,
  State,
  Effects,
  TokenType,
  Point,
  Token
} from 'micromark-util-types';

// Example: A simple state function for a custom micromark extension
function factory(effects: Effects, ok: State, nok: State): State {
  return start;

  function start(code: Code): State | undefined {
    // Implement custom parsing logic here
    if (code === 91 /* `[` */) {
      effects.enter('myCustomNode' as TokenType);
      effects.consume(code);
      return afterOpenBracket;
    }
    return nok(code);
  }

  function afterOpenBracket(code: Code): State | undefined {
    if (code === 93 /* `]` */) {
      effects.exit('myCustomNode' as TokenType);
      effects.consume(code);
      return ok;
    }
    return nok(code);
  }
}

// This code snippet demonstrates how to leverage types from micromark-util-types
// within a custom micromark extension. The 'factory' function would be integrated
// into a micromark tokenizer. This file compiles but does not have a runtime effect
// as it's purely for type demonstration.
console.log('Micromark types loaded for extension development.');

view raw JSON →