@pho9ubenaa/remark-mask-text-beta
Version:
A remark plugin to mask text content with block characters
66 lines (65 loc) • 2.17 kB
TypeScript
import type { Root } from "mdast";
import type { Plugin } from "unified";
/**
* Configuration options for the remark-mask-text plugin
*
* This interface defines all configurable aspects of the plugin behavior.
* All options are optional and have sensible defaults that work in most scenarios.
*
* @example
* // Using default options (maskCharacter: '#', maskDelimiter: '::')
* const processor = remark().use(remarkMaskText);
*
* @example
* // Using custom options
* const processor = remark().use(remarkMaskText, {
* maskCharacter: '*',
* maskDelimiter: '||'
* });
*/
export interface RemarkMaskTextOptions {
/**
* The character used to replace masked content
*
* Should be a single character that will be repeated to match the length
* of the original masked content. Common choices include '#', '*', 'X'.
*
* @default '#'
* @example '*' // Results in '****' for 4-character content
*/
maskCharacter?: string;
/**
* The delimiter pattern that marks text to be masked
*
* Should be a string that clearly delineates masked content. The pattern
* should be easily recognizable and unlikely to appear in normal text.
* Special regex characters will be automatically escaped.
*
* @default '::'
* @example '||' // Masks content like ||secret||
*/
maskDelimiter?: string;
}
/**
* Validated configuration options with guaranteed values
*
* This interface represents the options after validation, ensuring all
* values are present and valid. Used internally by the plugin.
*/
export interface ValidatedOptions {
/**
* Validated mask character (guaranteed to be exactly one character)
*/
maskCharacter: string;
/**
* Validated delimiter (guaranteed to be non-empty and properly escaped)
*/
maskDelimiter: string;
}
/**
* Strictly typed remark plugin that enforces exact option types
*
* This plugin type ensures that only valid RemarkMaskTextOptions are accepted,
* providing better type inference and preventing invalid properties
*/
export type StrictRemarkPlugin = Plugin<[RemarkMaskTextOptions?], Root, Root>;