legal-markdown-js
Version:
Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version
95 lines • 3.69 kB
TypeScript
/**
* Mixin Processing Module for Legal Markdown Documents
*
* This module provides comprehensive mixin processing functionality for Legal Markdown
* documents, supporting variable substitution, helper functions, conditional logic,
* and nested value access. It integrates with the field tracking system to monitor
* variable usage and provides robust error handling for complex document templates.
*
* Features:
* - Variable substitution syntax: {{variable}}
* - Helper function calls: {{helperName(arg1, arg2)}}
* - Conditional mixins: {{condition ? trueValue : falseValue}}
* - Nested metadata access with dot notation
* - Array access with bracket notation: {{parties[0].name}}
* - Recursive mixin processing for nested substitutions
* - Field tracking integration for highlighting and validation
* - Special value handling (@today, booleans, numbers, strings)
* - Graceful error handling and fallback behavior
*
* @example
* ```typescript
* import { processMixins } from './mixin-processor';
*
* const content = `
* This agreement is between {{client.name}} and {{provider.name}}.
* {{confidentiality ? "This includes confidentiality provisions." : ""}}
* Total amount: {{formatCurrency(contract.amount, "USD")}}
* Generated on: {{formatDate(@today, "long")}}
* `;
*
* const metadata = {
* client: { name: "Acme Corp" },
* provider: { name: "Service Ltd" },
* confidentiality: true,
* contract: { amount: 25000 }
* };
*
* const processed = processMixins(content, metadata);
* console.log(processed);
* // Output:
* // This agreement is between Acme Corp and Service Ltd.
* // This includes confidentiality provisions.
* // Total amount: $25,000.00
* // Generated on: January 15, 2024
* ```
*
* @module
*/
import { LegalMarkdownOptions } from '../../types';
/**
* Processes mixin references in legal documents
*
* This is the main function that processes mixin references using the {{variable}}
* syntax. It supports variable substitution, helper functions, conditional logic,
* and integrates with field tracking for document validation and highlighting.
*
* @param {string} content - The document content containing mixin references
* @param {Record<string, any>} metadata - Document metadata with variable values
* @param {LegalMarkdownOptions} [options={}] - Processing options
* @returns {string} Processed content with mixins resolved
* @example
* ```typescript
* // Basic variable substitution
* const content1 = "Hello {{user.name}}, welcome to {{company.name}}!";
* const metadata1 = {
* user: { name: "John" },
* company: { name: "Acme Corp" }
* };
* const result1 = processMixins(content1, metadata1);
* // Output: "Hello John, welcome to Acme Corp!"
*
* // Helper function usage
* const content2 = "Today is {{formatDate(@today, 'long')}}";
* const result2 = processMixins(content2, {});
* // Output: "Today is January 15, 2024"
*
* // Conditional mixins
* const content3 = "{{premium ? 'Premium features enabled' : 'Standard features'}}";
* const metadata3 = { premium: true };
* const result3 = processMixins(content3, metadata3);
* // Output: "Premium features enabled"
*
* // Array access
* const content4 = "Primary contact: {{contacts[0].name}} ({{contacts[0].email}})";
* const metadata4 = {
* contacts: [
* { name: "Jane Doe", email: "jane@example.com" }
* ]
* };
* const result4 = processMixins(content4, metadata4);
* // Output: "Primary contact: Jane Doe (jane@example.com)"
* ```
*/
export declare function processMixins(content: string, metadata: Record<string, any>, options?: LegalMarkdownOptions): string;
//# sourceMappingURL=mixin-processor.d.ts.map