@eigenpal/docx-editor-core/utils/findReplace

Find & Replace Utility Functions

Pure utility functions for text search, pattern matching, and document search. Lifted from packages/react/src/components/dialogs/ findReplaceUtils.ts so the React adapter and the Vue adapter share one implementation.

Functions (12)

createDefaultFindOptionsfunctionSource ↗

Create default find options

declare function createDefaultFindOptions(): FindOptions;

createSearchPatternfunctionSource ↗

Create a regex pattern from search text and options

declare function createSearchPattern(searchText: string, options: FindOptions): RegExp | null;

escapeRegexStringfunctionSource ↗

Escape string for use in regex pattern

declare function escapeRegexString(str: string): string;

findAllMatchesfunctionSource ↗

Find all matches of search text in content

declare function findAllMatches(content: string, searchText: string, options: FindOptions): Array<{
    start: number;
    end: number;
}>;

findInDocumentfunctionSource ↗

Find all matches in a document

declare function findInDocument(document: any, searchText: string, options: FindOptions): FindMatch[];

findInParagraphfunctionSource ↗

Find matches in a single paragraph

declare function findInParagraph(paragraph: any, searchText: string, options: FindOptions, paragraphIndex: number): FindMatch[];

getDefaultHighlightOptionsfunctionSource ↗

Get default highlight options

declare function getDefaultHighlightOptions(): HighlightOptions;

getMatchCountTextfunctionSource ↗

Get match count for status display

declare function getMatchCountText(result: FindResult | null): string;

isEmptySearchfunctionSource ↗

Check if search text is empty or whitespace-only

declare function isEmptySearch(searchText: string): boolean;

replaceAllInContentfunctionSource ↗

Replace text in content

declare function replaceAllInContent(content: string, searchText: string, replaceText: string, options: FindOptions): string;

replaceFirstInContentfunctionSource ↗

Replace first match in content

declare function replaceFirstInContent(content: string, searchText: string, replaceText: string, options: FindOptions, startIndex?: number): {
    content: string;
    replaced: boolean;
    matchStart: number;
    matchEnd: number;
};

scrollToMatchfunctionSource ↗

Scroll to a match in the document

declare function scrollToMatch(containerElement: HTMLElement | null, match: FindMatch): void;

Interfaces (4)

FindMatchinterfaceSource ↗

A single match result in the document

interface FindMatch
MemberTypeSummary
contentIndexnumberIndex of the run/content within the paragraph
endOffsetnumberCharacter offset for end of match
paragraphIndexnumberIndex of the paragraph containing the match
startOffsetnumberCharacter offset within the content
textstringThe matched text

FindOptionsinterfaceSource ↗

Find options for controlling search behavior

interface FindOptions
MemberTypeSummary
matchCasebooleanWhether to match case
matchWholeWordbooleanWhether to match whole words only
useRegex?booleanWhether to use regular expressions (future)

FindResultinterfaceSource ↗

Find result with all matches

interface FindResult
MemberTypeSummary
currentIndexnumberCurrent match index (0-based)
matchesFindMatch[]All matches found
totalCountnumberTotal match count

HighlightOptionsinterfaceSource ↗

Highlight options for document rendering

interface HighlightOptions
MemberTypeSummary
currentMatchColorstringBackground color for current match
otherMatchColorstringBackground color for other matches

On this page