docx
    Preparing search index...

    Function patchDetector

    • Detects all placeholders present in a document template.

      Scans through all XML content in a .docx file to find placeholder text enclosed in delimiters (default: {{placeholder}}). This is useful for discovering what patches a template expects before performing replacement.

      Parameters

      • options: PatchDetectorOptions

        Patch detector configuration

      Returns Promise<readonly string[]>

      Array of placeholder keys found in the document

      const placeholders = await patchDetector({ data: templateBuffer });
      // Returns: ["name", "date", "address"] if template contains {{name}}, {{date}}, {{address}}

      // Use detected placeholders to create patches
      const patches = {};
      placeholders.forEach(key => {
      patches[key] = {
      type: PatchType.PARAGRAPH,
      children: [new TextRun(getUserData(key))],
      };
      });