New

docx-editor 1.x has shipped. Vue support, i18n, agents. Read the migration guide →

API Referencev1.0.2

@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)

Create default find options

declare function createDefaultFindOptions(): FindOptions;

Create a regex pattern from search text and options

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

Escape string for use in regex pattern

declare function escapeRegexString(str: string): string;

Find all matches of search text in content

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

Find all matches in a document

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

Find matches in a single paragraph

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

Get default highlight options

declare function getDefaultHighlightOptions(): HighlightOptions;

Get match count for status display

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

Check if search text is empty or whitespace-only

declare function isEmptySearch(searchText: string): boolean;

Replace text in content

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

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;
};

Scroll to a match in the document

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

Interfaces(4)

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

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)

Find result with all matches

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

Highlight options for document rendering

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