UNPKG

@pho9ubenaa/remark-mask-text-beta

Version:

A remark plugin to mask text content with block characters

61 lines (60 loc) 3.05 kB
/** * AST manipulation utilities for remark-mask-text plugin * * This module provides pure functions for transforming Abstract Syntax Tree nodes * in a functional, immutable way. It separates AST manipulation concerns from * the main plugin logic, improving code organization and testability. * * Why (Business Logic Background): * - Safe AST transformation: To modify only text content without breaking Markdown structure * - Performance: To execute in linear time even for large document processing * - Extensibility: To easily support new Markdown elements and structures * - Debug support: To collect transformation statistics for identifying performance issues * - Quality assurance: To prevent side effects and ensure predictable behavior through immutable transformations * * All functions follow functional programming principles: * - Pure functions with no side effects * - Immutable data transformations * - Explicit error handling through Result types * - Single responsibility principle */ import type { Root } from "mdast"; import type { ASTNode, TextNode } from "./ast-types.js"; import type { ProcessingError, Result, TransformationContext } from "./types/index.js"; /** * Creates a new text node with the specified content * * This factory function ensures consistent text node creation with proper * type safety and immutable structure. * * @param content - The text content for the node * @returns A new immutable text node */ export declare const createTextNode: (content: string) => TextNode; /** * Transforms a text node containing mask delimiters into multiple nodes * * This is the main transformation function that processes individual text nodes * to identify and mask specified regions. It follows functional programming * principles with immutable transformations and explicit error handling. * * @param textNode - The text node to transform * @param maskChar - The character to use for masking * @param delimiter - The delimiter pattern to search for * @returns Result containing either transformed nodes or error information */ export declare const transformTextNodeFunctional: (textNode: TextNode, maskChar: string, delimiter: string) => Result<ASTNode[], ProcessingError>; /** * Transforms an AST tree using functional programming principles * * This function implements immutable tree transformation using a bottom-up * approach that processes leaf nodes first, then builds up the transformed tree. * It maintains the original tree structure while applying transformations. * * @param node - The AST node to transform * @param maskChar - The character to use for masking * @param delimiter - The delimiter pattern to search for * @param context - Transformation context for error reporting * @returns Result containing either the transformed node or error information */ export declare const transformTreeFunctional: (node: Root | ASTNode, maskChar: string, delimiter: string, context?: TransformationContext) => Result<ASTNode[] | Root | ASTNode, ProcessingError>;