legal-markdown-js 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +168 -0
  3. package/dist/browser.d.ts +87 -0
  4. package/dist/browser.d.ts.map +1 -0
  5. package/dist/browser.js +157 -0
  6. package/dist/browser.js.map +1 -0
  7. package/dist/cli/index.d.ts +34 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +221 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/cli/service.d.ts +128 -0
  12. package/dist/cli/service.d.ts.map +1 -0
  13. package/dist/cli/service.js +284 -0
  14. package/dist/cli/service.js.map +1 -0
  15. package/dist/constants/index.d.ts +229 -0
  16. package/dist/constants/index.d.ts.map +1 -0
  17. package/dist/constants/index.js +232 -0
  18. package/dist/constants/index.js.map +1 -0
  19. package/dist/core/exporters/metadata-exporter.d.ts +104 -0
  20. package/dist/core/exporters/metadata-exporter.d.ts.map +1 -0
  21. package/dist/core/exporters/metadata-exporter.js +201 -0
  22. package/dist/core/exporters/metadata-exporter.js.map +1 -0
  23. package/dist/core/index.d.ts +40 -0
  24. package/dist/core/index.d.ts.map +1 -0
  25. package/dist/core/index.js +56 -0
  26. package/dist/core/index.js.map +1 -0
  27. package/dist/core/parsers/yaml-parser.d.ts +149 -0
  28. package/dist/core/parsers/yaml-parser.d.ts.map +1 -0
  29. package/dist/core/parsers/yaml-parser.js +321 -0
  30. package/dist/core/parsers/yaml-parser.js.map +1 -0
  31. package/dist/core/processors/clause-processor.d.ts +74 -0
  32. package/dist/core/processors/clause-processor.d.ts.map +1 -0
  33. package/dist/core/processors/clause-processor.js +213 -0
  34. package/dist/core/processors/clause-processor.js.map +1 -0
  35. package/dist/core/processors/date-processor.d.ts +90 -0
  36. package/dist/core/processors/date-processor.d.ts.map +1 -0
  37. package/dist/core/processors/date-processor.js +336 -0
  38. package/dist/core/processors/date-processor.js.map +1 -0
  39. package/dist/core/processors/header-processor.d.ts +104 -0
  40. package/dist/core/processors/header-processor.d.ts.map +1 -0
  41. package/dist/core/processors/header-processor.js +585 -0
  42. package/dist/core/processors/header-processor.js.map +1 -0
  43. package/dist/core/processors/import-processor.d.ts +116 -0
  44. package/dist/core/processors/import-processor.d.ts.map +1 -0
  45. package/dist/core/processors/import-processor.js +236 -0
  46. package/dist/core/processors/import-processor.js.map +1 -0
  47. package/dist/core/processors/mixin-processor.d.ts +93 -0
  48. package/dist/core/processors/mixin-processor.d.ts.map +1 -0
  49. package/dist/core/processors/mixin-processor.js +378 -0
  50. package/dist/core/processors/mixin-processor.js.map +1 -0
  51. package/dist/core/processors/reference-processor.d.ts +115 -0
  52. package/dist/core/processors/reference-processor.d.ts.map +1 -0
  53. package/dist/core/processors/reference-processor.js +273 -0
  54. package/dist/core/processors/reference-processor.js.map +1 -0
  55. package/dist/errors/index.d.ts +234 -0
  56. package/dist/errors/index.d.ts.map +1 -0
  57. package/dist/errors/index.js +267 -0
  58. package/dist/errors/index.js.map +1 -0
  59. package/dist/extensions/batch-processor.d.ts +197 -0
  60. package/dist/extensions/batch-processor.d.ts.map +1 -0
  61. package/dist/extensions/batch-processor.js +392 -0
  62. package/dist/extensions/batch-processor.js.map +1 -0
  63. package/dist/extensions/formatters/index.d.ts +99 -0
  64. package/dist/extensions/formatters/index.d.ts.map +1 -0
  65. package/dist/extensions/formatters/index.js +128 -0
  66. package/dist/extensions/formatters/index.js.map +1 -0
  67. package/dist/extensions/index.d.ts +53 -0
  68. package/dist/extensions/index.d.ts.map +1 -0
  69. package/dist/extensions/index.js +71 -0
  70. package/dist/extensions/index.js.map +1 -0
  71. package/dist/extensions/latex-parser.d.ts +111 -0
  72. package/dist/extensions/latex-parser.d.ts.map +1 -0
  73. package/dist/extensions/latex-parser.js +563 -0
  74. package/dist/extensions/latex-parser.js.map +1 -0
  75. package/dist/extensions/rst-parser.d.ts +112 -0
  76. package/dist/extensions/rst-parser.d.ts.map +1 -0
  77. package/dist/extensions/rst-parser.js +268 -0
  78. package/dist/extensions/rst-parser.js.map +1 -0
  79. package/dist/extensions/template-loops.d.ts +61 -0
  80. package/dist/extensions/template-loops.d.ts.map +1 -0
  81. package/dist/extensions/template-loops.js +418 -0
  82. package/dist/extensions/template-loops.js.map +1 -0
  83. package/dist/extensions/utilities/index.d.ts +114 -0
  84. package/dist/extensions/utilities/index.d.ts.map +1 -0
  85. package/dist/extensions/utilities/index.js +137 -0
  86. package/dist/extensions/utilities/index.js.map +1 -0
  87. package/dist/extensions/validators/index.d.ts +65 -0
  88. package/dist/extensions/validators/index.d.ts.map +1 -0
  89. package/dist/extensions/validators/index.js +88 -0
  90. package/dist/extensions/validators/index.js.map +1 -0
  91. package/dist/generators/html-generator.d.ts +184 -0
  92. package/dist/generators/html-generator.d.ts.map +1 -0
  93. package/dist/generators/html-generator.js +361 -0
  94. package/dist/generators/html-generator.js.map +1 -0
  95. package/dist/generators/pdf-generator.d.ts +165 -0
  96. package/dist/generators/pdf-generator.d.ts.map +1 -0
  97. package/dist/generators/pdf-generator.js +275 -0
  98. package/dist/generators/pdf-generator.js.map +1 -0
  99. package/dist/helpers/date-helpers.d.ts +216 -0
  100. package/dist/helpers/date-helpers.d.ts.map +1 -0
  101. package/dist/helpers/date-helpers.js +402 -0
  102. package/dist/helpers/date-helpers.js.map +1 -0
  103. package/dist/helpers/index.d.ts +87 -0
  104. package/dist/helpers/index.d.ts.map +1 -0
  105. package/dist/helpers/index.js +149 -0
  106. package/dist/helpers/index.js.map +1 -0
  107. package/dist/helpers/number-helpers.d.ts +269 -0
  108. package/dist/helpers/number-helpers.d.ts.map +1 -0
  109. package/dist/helpers/number-helpers.js +406 -0
  110. package/dist/helpers/number-helpers.js.map +1 -0
  111. package/dist/helpers/string-helpers.d.ts +391 -0
  112. package/dist/helpers/string-helpers.d.ts.map +1 -0
  113. package/dist/helpers/string-helpers.js +549 -0
  114. package/dist/helpers/string-helpers.js.map +1 -0
  115. package/dist/index.d.ts +229 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +384 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/legal-markdown.umd.min.js +2 -0
  120. package/dist/legal-markdown.umd.min.js.LICENSE.txt +14 -0
  121. package/dist/legal-markdown.umd.min.js.map +1 -0
  122. package/dist/lib/index.d.ts +150 -0
  123. package/dist/lib/index.d.ts.map +1 -0
  124. package/dist/lib/index.js +265 -0
  125. package/dist/lib/index.js.map +1 -0
  126. package/dist/parsers/content-detector.d.ts +131 -0
  127. package/dist/parsers/content-detector.d.ts.map +1 -0
  128. package/dist/parsers/content-detector.js +220 -0
  129. package/dist/parsers/content-detector.js.map +1 -0
  130. package/dist/parsers/fallback-parsers.d.ts +14 -0
  131. package/dist/parsers/fallback-parsers.d.ts.map +1 -0
  132. package/dist/parsers/fallback-parsers.js +188 -0
  133. package/dist/parsers/fallback-parsers.js.map +1 -0
  134. package/dist/parsers/implementations/pandoc-native.d.ts +13 -0
  135. package/dist/parsers/implementations/pandoc-native.d.ts.map +1 -0
  136. package/dist/parsers/implementations/pandoc-native.js +63 -0
  137. package/dist/parsers/implementations/pandoc-native.js.map +1 -0
  138. package/dist/parsers/implementations/pandoc-wasm.d.ts +14 -0
  139. package/dist/parsers/implementations/pandoc-wasm.d.ts.map +1 -0
  140. package/dist/parsers/implementations/pandoc-wasm.js +64 -0
  141. package/dist/parsers/implementations/pandoc-wasm.js.map +1 -0
  142. package/dist/parsers/pandoc-factory.d.ts +97 -0
  143. package/dist/parsers/pandoc-factory.d.ts.map +1 -0
  144. package/dist/parsers/pandoc-factory.js +146 -0
  145. package/dist/parsers/pandoc-factory.js.map +1 -0
  146. package/dist/parsers/pandoc-loader.d.ts +24 -0
  147. package/dist/parsers/pandoc-loader.d.ts.map +1 -0
  148. package/dist/parsers/pandoc-loader.js +124 -0
  149. package/dist/parsers/pandoc-loader.js.map +1 -0
  150. package/dist/parsers/pandoc-parser.d.ts +27 -0
  151. package/dist/parsers/pandoc-parser.d.ts.map +1 -0
  152. package/dist/parsers/pandoc-parser.js +3 -0
  153. package/dist/parsers/pandoc-parser.js.map +1 -0
  154. package/dist/styles/default.css +125 -0
  155. package/dist/styles/headers.css +146 -0
  156. package/dist/styles/highlight.css +171 -0
  157. package/dist/tracking/field-tracker.d.ts +206 -0
  158. package/dist/tracking/field-tracker.d.ts.map +1 -0
  159. package/dist/tracking/field-tracker.js +247 -0
  160. package/dist/tracking/field-tracker.js.map +1 -0
  161. package/dist/types.d.ts +186 -0
  162. package/dist/types.d.ts.map +1 -0
  163. package/dist/types.js +33 -0
  164. package/dist/types.js.map +1 -0
  165. package/dist/utils/logger.d.ts +107 -0
  166. package/dist/utils/logger.d.ts.map +1 -0
  167. package/dist/utils/logger.js +122 -0
  168. package/dist/utils/logger.js.map +1 -0
  169. package/dist/web/bundle-standalone.js +28 -0
  170. package/dist/web/bundle.js +17 -0
  171. package/dist/web/index.html +1465 -0
  172. package/dist/web/legal-markdown.umd.min.js +2 -0
  173. package/dist/web/standalone.html +390 -0
  174. package/dist/web/styles.css +874 -0
  175. package/package.json +118 -0
@@ -0,0 +1,321 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview YAML Front Matter Parser for Legal Markdown Documents
4
+ *
5
+ * This module provides functionality to parse YAML front matter from Legal Markdown
6
+ * documents, extracting metadata and configuration options for document processing.
7
+ * It handles both valid and invalid YAML gracefully, with options for strict error
8
+ * handling when needed.
9
+ *
10
+ * Features:
11
+ * - YAML front matter parsing with js-yaml library
12
+ * - Graceful error handling for malformed YAML
13
+ * - Metadata extraction and validation
14
+ * - Content separation from front matter
15
+ * - YAML serialization utilities
16
+ * - Metadata output configuration extraction
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { parseYamlFrontMatter } from './yaml-parser';
21
+ *
22
+ * const content = `---
23
+ * title: Legal Agreement
24
+ * date: 2024-01-01
25
+ * parties:
26
+ * - name: Company A
27
+ * role: Provider
28
+ * ---
29
+ * # Agreement Content
30
+ * This is the document content.`;
31
+ *
32
+ * const result = parseYamlFrontMatter(content);
33
+ * console.log(result.metadata.title); // "Legal Agreement"
34
+ * console.log(result.content); // "# Agreement Content\nThis is the document content."
35
+ * ```
36
+ */
37
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
38
+ if (k2 === undefined) k2 = k;
39
+ var desc = Object.getOwnPropertyDescriptor(m, k);
40
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
41
+ desc = { enumerable: true, get: function() { return m[k]; } };
42
+ }
43
+ Object.defineProperty(o, k2, desc);
44
+ }) : (function(o, m, k, k2) {
45
+ if (k2 === undefined) k2 = k;
46
+ o[k2] = m[k];
47
+ }));
48
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
49
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
50
+ }) : function(o, v) {
51
+ o["default"] = v;
52
+ });
53
+ var __importStar = (this && this.__importStar) || (function () {
54
+ var ownKeys = function(o) {
55
+ ownKeys = Object.getOwnPropertyNames || function (o) {
56
+ var ar = [];
57
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
58
+ return ar;
59
+ };
60
+ return ownKeys(o);
61
+ };
62
+ return function (mod) {
63
+ if (mod && mod.__esModule) return mod;
64
+ var result = {};
65
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
66
+ __setModuleDefault(result, mod);
67
+ return result;
68
+ };
69
+ })();
70
+ Object.defineProperty(exports, "__esModule", { value: true });
71
+ exports.parseYamlFrontMatter = parseYamlFrontMatter;
72
+ exports.serializeToYaml = serializeToYaml;
73
+ exports.extractMetadataOutputConfig = extractMetadataOutputConfig;
74
+ const yaml = __importStar(require("js-yaml"));
75
+ /**
76
+ * Parses YAML Front Matter from a markdown document
77
+ *
78
+ * Extracts and parses YAML metadata from the beginning of a document,
79
+ * separated by triple dashes (---). The parser handles malformed YAML
80
+ * gracefully unless strict error handling is enabled.
81
+ *
82
+ * @param {string} content - The content of the document to parse
83
+ * @param {boolean} [throwOnError=false] - Whether to throw errors on invalid YAML
84
+ * @returns {YamlParsingResult} Object containing the content without YAML and the parsed metadata
85
+ * @throws {Error} When throwOnError is true and YAML parsing fails
86
+ * @example
87
+ * ```typescript
88
+ * // Basic usage with valid YAML
89
+ * const content = `---
90
+ * title: Contract
91
+ * version: 1.0
92
+ * ---
93
+ * # Contract Content`;
94
+ *
95
+ * const result = parseYamlFrontMatter(content);
96
+ * // result.metadata = { title: "Contract", version: 1.0 }
97
+ * // result.content = "# Contract Content"
98
+ *
99
+ * // Usage with error handling
100
+ * const malformedContent = `---
101
+ * title: Contract
102
+ * invalid: yaml: content
103
+ * ---
104
+ * # Content`;
105
+ *
106
+ * const safeResult = parseYamlFrontMatter(malformedContent, false);
107
+ * // Returns original content with empty metadata
108
+ *
109
+ * const strictResult = parseYamlFrontMatter(malformedContent, true);
110
+ * // Throws Error: "Invalid YAML Front Matter: ..."
111
+ * ```
112
+ */
113
+ function parseYamlFrontMatter(content, throwOnError = false) {
114
+ // Default result
115
+ const defaultResult = {
116
+ content,
117
+ metadata: {},
118
+ };
119
+ // Check if content starts with YAML delimiter
120
+ if (!content.startsWith('---')) {
121
+ return defaultResult;
122
+ }
123
+ // Find the closing delimiter
124
+ const endDelimiterIndex = content.indexOf('---', 3);
125
+ if (endDelimiterIndex === -1) {
126
+ return defaultResult;
127
+ }
128
+ // Extract YAML content
129
+ let yamlContent = content.substring(3, endDelimiterIndex).trim();
130
+ const remainingContent = content.substring(endDelimiterIndex + 3).trim();
131
+ // Process @today references in YAML content before parsing
132
+ yamlContent = processDateReferencesInYaml(yamlContent);
133
+ try {
134
+ // Parse YAML
135
+ const metadata = yaml.load(yamlContent);
136
+ // Handle empty YAML
137
+ if (!metadata || typeof metadata !== 'object') {
138
+ return {
139
+ content: remainingContent,
140
+ metadata: {},
141
+ };
142
+ }
143
+ return {
144
+ content: remainingContent,
145
+ metadata,
146
+ };
147
+ }
148
+ catch (error) {
149
+ if (throwOnError) {
150
+ // Throw error for CLI to handle
151
+ throw new Error(`Invalid YAML Front Matter: ${error instanceof Error ? error.message : 'Unknown error'}`);
152
+ }
153
+ else {
154
+ // Return original content if YAML parsing fails (graceful handling)
155
+ // Silently ignore YAML parsing errors unless throwOnError is true
156
+ return defaultResult;
157
+ }
158
+ }
159
+ }
160
+ /**
161
+ * Serializes metadata to YAML format
162
+ *
163
+ * Converts a JavaScript object to YAML string format using js-yaml library.
164
+ * Handles serialization errors gracefully by returning an empty string and
165
+ * logging the error to the console.
166
+ *
167
+ * @param {Record<string, any>} metadata - The metadata object to serialize
168
+ * @returns {string} YAML string representation of the metadata
169
+ * @example
170
+ * ```typescript
171
+ * const metadata = {
172
+ * title: "Legal Agreement",
173
+ * date: "2024-01-01",
174
+ * parties: [
175
+ * { name: "Company A", role: "Provider" },
176
+ * { name: "Company B", role: "Client" }
177
+ * ]
178
+ * };
179
+ *
180
+ * const yamlString = serializeToYaml(metadata);
181
+ * console.log(yamlString);
182
+ * // Output:
183
+ * // title: Legal Agreement
184
+ * // date: '2024-01-01'
185
+ * // parties:
186
+ * // - name: Company A
187
+ * // role: Provider
188
+ * // - name: Company B
189
+ * // role: Client
190
+ * ```
191
+ */
192
+ function serializeToYaml(metadata) {
193
+ try {
194
+ return yaml.dump(metadata);
195
+ }
196
+ catch (error) {
197
+ console.error('Error serializing metadata to YAML:', error);
198
+ return '';
199
+ }
200
+ }
201
+ /**
202
+ * Extracts specific metadata output configuration
203
+ *
204
+ * Parses document metadata to extract configuration options for metadata output,
205
+ * including file paths, formats, and inclusion settings. This function looks for
206
+ * specially named metadata fields that control how processed metadata is exported.
207
+ *
208
+ * @param {Record<string, any>} metadata - The document metadata to extract configuration from
209
+ * @returns {Object} Configuration object for metadata output
210
+ * @returns {string} [returns.yamlOutput] - Path for YAML metadata output file
211
+ * @returns {string} [returns.jsonOutput] - Path for JSON metadata output file
212
+ * @returns {string} [returns.outputPath] - General output path for metadata files
213
+ * @returns {boolean} [returns.includeOriginal] - Whether to include original metadata in output
214
+ * @example
215
+ * ```typescript
216
+ * const metadata = {
217
+ * title: "Contract",
218
+ * "meta-yaml-output": "contract-metadata.yml",
219
+ * "meta-json-output": "contract-metadata.json",
220
+ * "meta-output-path": "./output/",
221
+ * "meta-include-original": true
222
+ * };
223
+ *
224
+ * const config = extractMetadataOutputConfig(metadata);
225
+ * console.log(config);
226
+ * // Output:
227
+ * // {
228
+ * // yamlOutput: "contract-metadata.yml",
229
+ * // jsonOutput: "contract-metadata.json",
230
+ * // outputPath: "./output/",
231
+ * // includeOriginal: true
232
+ * // }
233
+ * ```
234
+ */
235
+ function extractMetadataOutputConfig(metadata) {
236
+ return {
237
+ yamlOutput: metadata['meta-yaml-output'],
238
+ jsonOutput: metadata['meta-json-output'],
239
+ outputPath: metadata['meta-output-path'],
240
+ includeOriginal: metadata['meta-include-original'],
241
+ };
242
+ }
243
+ /**
244
+ * Processes @today references in YAML content before parsing
245
+ *
246
+ * Replaces @today references with properly formatted date strings that are valid YAML.
247
+ * This prevents YAML parsing errors when @today is used in frontmatter.
248
+ *
249
+ * @private
250
+ * @param {string} yamlContent - The raw YAML content containing @today references
251
+ * @returns {string} YAML content with @today references replaced by actual dates
252
+ * @example
253
+ * ```typescript
254
+ * const yamlContent = `
255
+ * title: Document
256
+ * date: @today
257
+ * deadline: @today[long]
258
+ * `;
259
+ *
260
+ * const processed = processDateReferencesInYaml(yamlContent);
261
+ * // Returns:
262
+ * // title: Document
263
+ * // date: "2024-01-15"
264
+ * // deadline: "January 15, 2024"
265
+ * ```
266
+ */
267
+ function processDateReferencesInYaml(yamlContent) {
268
+ // Regular expression to match @today references with optional format specifiers
269
+ const todayPattern = /@today(?:\[([^\]]+)\])?/g;
270
+ return yamlContent.replace(todayPattern, (match, formatOverride) => {
271
+ // Use format override if provided, otherwise use ISO format for YAML compatibility
272
+ const format = formatOverride || 'YYYY-MM-DD';
273
+ const formattedDate = formatDateForYaml(new Date(), format);
274
+ // Quote the date string to ensure it's valid YAML
275
+ return `"${formattedDate}"`;
276
+ });
277
+ }
278
+ /**
279
+ * Formats a date for YAML compatibility
280
+ *
281
+ * @private
282
+ * @param {Date} date - The date to format
283
+ * @param {string} format - Format specification
284
+ * @returns {string} Formatted date string
285
+ */
286
+ function formatDateForYaml(date, format) {
287
+ try {
288
+ // Handle different format patterns
289
+ switch (format.toLowerCase()) {
290
+ case 'iso':
291
+ case 'yyyy-mm-dd':
292
+ return date.toISOString().split('T')[0];
293
+ case 'long':
294
+ return date.toLocaleDateString('en-US', {
295
+ year: 'numeric',
296
+ month: 'long',
297
+ day: 'numeric',
298
+ });
299
+ case 'medium':
300
+ return date.toLocaleDateString('en-US', {
301
+ year: 'numeric',
302
+ month: 'short',
303
+ day: 'numeric',
304
+ });
305
+ case 'short':
306
+ return date.toLocaleDateString('en-US', {
307
+ year: '2-digit',
308
+ month: 'short',
309
+ day: 'numeric',
310
+ });
311
+ default:
312
+ // For any other format, default to ISO
313
+ return date.toISOString().split('T')[0];
314
+ }
315
+ }
316
+ catch (error) {
317
+ // Fallback to ISO format if there's an error
318
+ return date.toISOString().split('T')[0];
319
+ }
320
+ }
321
+ //# sourceMappingURL=yaml-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml-parser.js","sourceRoot":"","sources":["../../../src/core/parsers/yaml-parser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CH,oDAwDC;AAkCD,0CAOC;AAoCD,kEAYC;AA1LD,8CAAgC;AAGhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,SAAgB,oBAAoB,CAClC,OAAe,EACf,eAAwB,KAAK;IAE7B,iBAAiB;IACjB,MAAM,aAAa,GAAsB;QACvC,OAAO;QACP,QAAQ,EA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KAAK,KAAK,CAAC;YACX,KAAK,YAAY;gBACf,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAE1C,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE;oBACtC,IAAI,EAAE,SAAS;oBACf,KAAK,EAAE,MAAM;oBACb,GAAG,EAAE,SAAS;iBACf,CAAC,CAAC;YAEL,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE;oBACtC,IAAI,EAAE,SAAS;oBACf,KAAK,EAAE,OAAO;oBACd,GAAG,EAAE,SAAS;iBACf,CAAC,CAAC;YAEL,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE;oBACtC,IAAI,EAAE,SAAS;oBACf,KAAK,EAAE,OAAO;oBACd,GAAG,EAAE,SAAS;iBACf,CAAC,CAAC;YAEL;gBACE,uCAAuC;gBACvC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,6CAA6C;QAC7C,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @fileoverview Optional Clause Processing Module for Legal Markdown Documents
3
+ *
4
+ * This module provides functionality to process conditional clauses in Legal Markdown
5
+ * documents, allowing for dynamic content inclusion based on metadata conditions.
6
+ * It supports complex boolean logic with AND/OR operations, equality comparisons,
7
+ * and nested value access for sophisticated document customization.
8
+ *
9
+ * Features:
10
+ * - Conditional clause syntax: [content]{condition}
11
+ * - Boolean logic with AND/OR operations
12
+ * - Equality and inequality comparisons
13
+ * - Nested metadata value access with dot notation
14
+ * - Type-aware value comparison (strings, numbers, booleans)
15
+ * - Graceful error handling for invalid conditions
16
+ * - Support for quoted string values in conditions
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { processOptionalClauses } from './clause-processor';
21
+ *
22
+ * const content = `
23
+ * This agreement [includes confidentiality clauses]{confidentiality}
24
+ * [and has a termination period of {{termination_days}} days]{termination_days}
25
+ * [with special provisions for European clients]{client.region = "EU"}.
26
+ * `;
27
+ *
28
+ * const metadata = {
29
+ * confidentiality: true,
30
+ * termination_days: 30,
31
+ * client: { region: "EU" }
32
+ * };
33
+ *
34
+ * const processed = processOptionalClauses(content, metadata);
35
+ * console.log(processed);
36
+ * // Output:
37
+ * // This agreement includes confidentiality clauses
38
+ * // and has a termination period of 30 days
39
+ * // with special provisions for European clients.
40
+ * ```
41
+ */
42
+ /**
43
+ * Processes optional clauses in a LegalMarkdown document
44
+ *
45
+ * Evaluates conditional clauses using the syntax [content]{condition} and includes
46
+ * or excludes content based on metadata values. Supports complex boolean logic
47
+ * and various comparison operators for sophisticated document customization.
48
+ *
49
+ * @param {string} content - The document content containing optional clauses
50
+ * @param {Record<string, any>} metadata - Document metadata with clause conditions
51
+ * @returns {string} Processed content with conditional clauses evaluated
52
+ * @example
53
+ * ```typescript
54
+ * // Simple boolean condition
55
+ * const content1 = '[This clause is included]{include_special}';
56
+ * const metadata1 = { include_special: true };
57
+ * const result1 = processOptionalClauses(content1, metadata1);
58
+ * // Output: "This clause is included"
59
+ *
60
+ * // Complex condition with AND/OR logic
61
+ * const content2 = '[Premium features available]{premium = true AND region != "restricted"}';
62
+ * const metadata2 = { premium: true, region: "US" };
63
+ * const result2 = processOptionalClauses(content2, metadata2);
64
+ * // Output: "Premium features available"
65
+ *
66
+ * // Nested metadata access
67
+ * const content3 = '[European compliance required]{client.location.country = "DE"}';
68
+ * const metadata3 = { client: { location: { country: "DE" } } };
69
+ * const result3 = processOptionalClauses(content3, metadata3);
70
+ * // Output: "European compliance required"
71
+ * ```
72
+ */
73
+ export declare function processOptionalClauses(content: string, metadata: Record<string, any>): string;
74
+ //# sourceMappingURL=clause-processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clause-processor.d.ts","sourceRoot":"","sources":["../../../src/core/processors/clause-processor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAY7F"}
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Optional Clause Processing Module for Legal Markdown Documents
4
+ *
5
+ * This module provides functionality to process conditional clauses in Legal Markdown
6
+ * documents, allowing for dynamic content inclusion based on metadata conditions.
7
+ * It supports complex boolean logic with AND/OR operations, equality comparisons,
8
+ * and nested value access for sophisticated document customization.
9
+ *
10
+ * Features:
11
+ * - Conditional clause syntax: [content]{condition}
12
+ * - Boolean logic with AND/OR operations
13
+ * - Equality and inequality comparisons
14
+ * - Nested metadata value access with dot notation
15
+ * - Type-aware value comparison (strings, numbers, booleans)
16
+ * - Graceful error handling for invalid conditions
17
+ * - Support for quoted string values in conditions
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { processOptionalClauses } from './clause-processor';
22
+ *
23
+ * const content = `
24
+ * This agreement [includes confidentiality clauses]{confidentiality}
25
+ * [and has a termination period of {{termination_days}} days]{termination_days}
26
+ * [with special provisions for European clients]{client.region = "EU"}.
27
+ * `;
28
+ *
29
+ * const metadata = {
30
+ * confidentiality: true,
31
+ * termination_days: 30,
32
+ * client: { region: "EU" }
33
+ * };
34
+ *
35
+ * const processed = processOptionalClauses(content, metadata);
36
+ * console.log(processed);
37
+ * // Output:
38
+ * // This agreement includes confidentiality clauses
39
+ * // and has a termination period of 30 days
40
+ * // with special provisions for European clients.
41
+ * ```
42
+ */
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.processOptionalClauses = processOptionalClauses;
45
+ /**
46
+ * Processes optional clauses in a LegalMarkdown document
47
+ *
48
+ * Evaluates conditional clauses using the syntax [content]{condition} and includes
49
+ * or excludes content based on metadata values. Supports complex boolean logic
50
+ * and various comparison operators for sophisticated document customization.
51
+ *
52
+ * @param {string} content - The document content containing optional clauses
53
+ * @param {Record<string, any>} metadata - Document metadata with clause conditions
54
+ * @returns {string} Processed content with conditional clauses evaluated
55
+ * @example
56
+ * ```typescript
57
+ * // Simple boolean condition
58
+ * const content1 = '[This clause is included]{include_special}';
59
+ * const metadata1 = { include_special: true };
60
+ * const result1 = processOptionalClauses(content1, metadata1);
61
+ * // Output: "This clause is included"
62
+ *
63
+ * // Complex condition with AND/OR logic
64
+ * const content2 = '[Premium features available]{premium = true AND region != "restricted"}';
65
+ * const metadata2 = { premium: true, region: "US" };
66
+ * const result2 = processOptionalClauses(content2, metadata2);
67
+ * // Output: "Premium features available"
68
+ *
69
+ * // Nested metadata access
70
+ * const content3 = '[European compliance required]{client.location.country = "DE"}';
71
+ * const metadata3 = { client: { location: { country: "DE" } } };
72
+ * const result3 = processOptionalClauses(content3, metadata3);
73
+ * // Output: "European compliance required"
74
+ * ```
75
+ */
76
+ function processOptionalClauses(content, metadata) {
77
+ // Regular expression to match optional clauses
78
+ // Format: [Optional text]{condition}
79
+ const optionalClausePattern = /\[(.*?)\]\{(.*?)\}/gs;
80
+ return content.replace(optionalClausePattern, (match, text, condition) => {
81
+ // Evaluate the condition
82
+ const shouldInclude = evaluateCondition(condition, metadata);
83
+ // Include the text if condition is true, otherwise return empty string
84
+ return shouldInclude ? text : '';
85
+ });
86
+ }
87
+ /**
88
+ * Evaluates a condition expression against metadata
89
+ *
90
+ * Parses and evaluates condition expressions that can include simple variable
91
+ * references, equality/inequality comparisons, and boolean logic with AND/OR
92
+ * operations. Supports nested metadata access using dot notation.
93
+ *
94
+ * @private
95
+ * @param {string} condition - Condition expression to evaluate
96
+ * @param {Record<string, any>} metadata - Document metadata to test against
97
+ * @returns {boolean} True if condition evaluates to true, false otherwise
98
+ * @example
99
+ * ```typescript
100
+ * const metadata = {
101
+ * active: true,
102
+ * user: { role: "admin", level: 5 },
103
+ * region: "US"
104
+ * };
105
+ *
106
+ * console.log(evaluateCondition("active", metadata)); // true
107
+ * console.log(evaluateCondition("user.role = \"admin\"", metadata)); // true
108
+ * console.log(evaluateCondition("user.level != 3", metadata)); // true
109
+ * console.log(evaluateCondition("active AND region = \"US\"", metadata)); // true
110
+ * console.log(evaluateCondition("active OR region = \"EU\"", metadata)); // true
111
+ * ```
112
+ */
113
+ function evaluateCondition(condition, metadata) {
114
+ // Handle empty condition (always true)
115
+ if (!condition.trim()) {
116
+ return true;
117
+ }
118
+ // Simple variable reference (e.g., "include_clause")
119
+ if (!condition.includes('=') &&
120
+ !condition.includes('!') &&
121
+ !condition.includes('AND') &&
122
+ !condition.includes('OR')) {
123
+ const value = getNestedValue(metadata, condition.trim());
124
+ return Boolean(value);
125
+ }
126
+ // Complex conditions
127
+ try {
128
+ // Handle logical AND first (higher precedence in processing)
129
+ if (condition.includes(' AND ')) {
130
+ const subConditions = condition.split(' AND ').map(c => c.trim());
131
+ return subConditions.every(cond => evaluateCondition(cond, metadata));
132
+ }
133
+ // Handle logical OR
134
+ if (condition.includes(' OR ')) {
135
+ const subConditions = condition.split(' OR ').map(c => c.trim());
136
+ return subConditions.some(cond => evaluateCondition(cond, metadata));
137
+ }
138
+ // Handle equality/inequality (after logical operators)
139
+ if (condition.includes('=')) {
140
+ // Parse "key = value" or "key != value"
141
+ const isNotEqual = condition.includes('!=');
142
+ const parts = condition.split(isNotEqual ? '!=' : '=').map(p => p.trim());
143
+ if (parts.length !== 2) {
144
+ return false;
145
+ }
146
+ const [key, valueStr] = parts;
147
+ const metadataValue = getNestedValue(metadata, key);
148
+ // Parse the value string (handle quoted strings, booleans, numbers)
149
+ let expectedValue = valueStr;
150
+ if (valueStr.startsWith('"') && valueStr.endsWith('"')) {
151
+ expectedValue = valueStr.slice(1, -1);
152
+ }
153
+ else if (valueStr === 'true') {
154
+ expectedValue = true;
155
+ }
156
+ else if (valueStr === 'false') {
157
+ expectedValue = false;
158
+ }
159
+ else if (!isNaN(Number(valueStr))) {
160
+ expectedValue = Number(valueStr);
161
+ }
162
+ return isNotEqual ? metadataValue !== expectedValue : metadataValue === expectedValue;
163
+ }
164
+ // Default to false for unknown condition formats
165
+ return false;
166
+ }
167
+ catch (error) {
168
+ console.error('Error evaluating condition:', error);
169
+ return false;
170
+ }
171
+ }
172
+ /**
173
+ * Gets a potentially nested value from an object
174
+ *
175
+ * Traverses an object using dot notation to access nested properties safely.
176
+ * Returns undefined if any part of the path doesn't exist, preventing errors
177
+ * when accessing deeply nested properties.
178
+ *
179
+ * @private
180
+ * @param {Record<string, any>} obj - Object to extract value from
181
+ * @param {string} path - Dot-separated path to the value (e.g., "user.profile.name")
182
+ * @returns {any} The value at the specified path, or undefined if not found
183
+ * @example
184
+ * ```typescript
185
+ * const obj = {
186
+ * user: {
187
+ * profile: {
188
+ * name: "John",
189
+ * settings: { theme: "dark" }
190
+ * },
191
+ * active: true
192
+ * }
193
+ * };
194
+ *
195
+ * console.log(getNestedValue(obj, "user.profile.name")); // "John"
196
+ * console.log(getNestedValue(obj, "user.active")); // true
197
+ * console.log(getNestedValue(obj, "user.profile.settings.theme")); // "dark"
198
+ * console.log(getNestedValue(obj, "user.nonexistent")); // undefined
199
+ * console.log(getNestedValue(obj, "missing.path")); // undefined
200
+ * ```
201
+ */
202
+ function getNestedValue(obj, path) {
203
+ const keys = path.split('.');
204
+ let value = obj;
205
+ for (const key of keys) {
206
+ if (value === undefined || value === null) {
207
+ return undefined;
208
+ }
209
+ value = value[key];
210
+ }
211
+ return value;
212
+ }
213
+ //# sourceMappingURL=clause-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clause-processor.js","sourceRoot":"","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