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,392 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Batch Processing Module for Legal Markdown Documents
4
+ *
5
+ * This module provides functionality for processing multiple Legal Markdown files
6
+ * in batch operations. It supports recursive directory processing, concurrent
7
+ * file operations, progress tracking, and error handling.
8
+ *
9
+ * Features:
10
+ * - Batch processing of multiple Legal Markdown files
11
+ * - Recursive directory traversal with pattern matching
12
+ * - Concurrent processing with configurable concurrency limits
13
+ * - Progress tracking and error reporting callbacks
14
+ * - Directory structure preservation in output
15
+ * - File extension filtering and exclusion patterns
16
+ * - Metadata export support for batch operations
17
+ * - Statistics and performance tracking
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { processBatch } from './batch-processor';
22
+ *
23
+ * // Basic batch processing
24
+ * const result = await processBatch({
25
+ * inputDir: './legal-docs',
26
+ * outputDir: './output',
27
+ * extensions: ['.md'],
28
+ * recursive: true
29
+ * });
30
+ *
31
+ * // Advanced batch processing with callbacks
32
+ * const result = await processBatch({
33
+ * inputDir: './contracts',
34
+ * outputDir: './processed-contracts',
35
+ * extensions: ['.md', '.txt'],
36
+ * recursive: true,
37
+ * concurrency: 3,
38
+ * exclude: ['temp', 'backup'],
39
+ * onProgress: (processed, total, currentFile) => {
40
+ * console.log(`Progress: ${processed}/${total} - ${currentFile}`);
41
+ * },
42
+ * onError: (file, error) => {
43
+ * console.error(`Error processing ${file}:`, error.message);
44
+ * }
45
+ * });
46
+ * ```
47
+ */
48
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
49
+ if (k2 === undefined) k2 = k;
50
+ var desc = Object.getOwnPropertyDescriptor(m, k);
51
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
52
+ desc = { enumerable: true, get: function() { return m[k]; } };
53
+ }
54
+ Object.defineProperty(o, k2, desc);
55
+ }) : (function(o, m, k, k2) {
56
+ if (k2 === undefined) k2 = k;
57
+ o[k2] = m[k];
58
+ }));
59
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
60
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
61
+ }) : function(o, v) {
62
+ o["default"] = v;
63
+ });
64
+ var __importStar = (this && this.__importStar) || (function () {
65
+ var ownKeys = function(o) {
66
+ ownKeys = Object.getOwnPropertyNames || function (o) {
67
+ var ar = [];
68
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
69
+ return ar;
70
+ };
71
+ return ownKeys(o);
72
+ };
73
+ return function (mod) {
74
+ if (mod && mod.__esModule) return mod;
75
+ var result = {};
76
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
77
+ __setModuleDefault(result, mod);
78
+ return result;
79
+ };
80
+ })();
81
+ Object.defineProperty(exports, "__esModule", { value: true });
82
+ exports.processBatch = processBatch;
83
+ exports.getProcessingStats = getProcessingStats;
84
+ const fs = __importStar(require("fs"));
85
+ const path = __importStar(require("path"));
86
+ const util_1 = require("util");
87
+ const index_1 = require("../index");
88
+ const readdir = (0, util_1.promisify)(fs.readdir);
89
+ const stat = (0, util_1.promisify)(fs.stat);
90
+ const readFile = (0, util_1.promisify)(fs.readFile);
91
+ const writeFile = (0, util_1.promisify)(fs.writeFile);
92
+ /**
93
+ * Processes multiple legal markdown files in batch
94
+ *
95
+ * This function performs batch processing of Legal Markdown files with support
96
+ * for recursive directory traversal, concurrent processing, and progress tracking.
97
+ * It automatically handles file discovery, directory creation, and error management.
98
+ *
99
+ * @async
100
+ * @function processBatch
101
+ * @param {BatchProcessingOptions} options - Configuration options for batch processing
102
+ * @returns {Promise<BatchProcessingResult>} A promise that resolves to the processing result
103
+ * @throws {Error} When input directory doesn't exist or other setup errors occur
104
+ * @example
105
+ * ```typescript
106
+ * import { processBatch } from './batch-processor';
107
+ *
108
+ * // Process all .md files in a directory
109
+ * const result = await processBatch({
110
+ * inputDir: './legal-documents',
111
+ * outputDir: './processed-documents',
112
+ * extensions: ['.md'],
113
+ * recursive: true,
114
+ * preserveStructure: true,
115
+ * concurrency: 3,
116
+ * onProgress: (processed, total, currentFile) => {
117
+ * console.log(`Progress: ${processed}/${total} - ${path.basename(currentFile)}`);
118
+ * },
119
+ * onError: (file, error) => {
120
+ * console.error(`Error processing ${file}:`, error.message);
121
+ * }
122
+ * });
123
+ *
124
+ * console.log(`Processed ${result.totalProcessed} files successfully`);
125
+ * console.log(`${result.totalErrors} files failed processing`);
126
+ * ```
127
+ */
128
+ async function processBatch(options) {
129
+ const startTime = Date.now();
130
+ const { inputDir, outputDir, extensions = ['.md', '.txt'], recursive = false, preserveStructure = true, exclude = [], concurrency = 5, onProgress, onError, ...processingOptions } = options;
131
+ // Validate input directory
132
+ if (!fs.existsSync(inputDir)) {
133
+ throw new Error(`Input directory does not exist: ${inputDir}`);
134
+ }
135
+ // Create output directory if it doesn't exist
136
+ if (!fs.existsSync(outputDir)) {
137
+ fs.mkdirSync(outputDir, { recursive: true });
138
+ }
139
+ // Find all files to process
140
+ const filesToProcess = await findFilesToProcess(inputDir, extensions, recursive, exclude);
141
+ if (filesToProcess.length === 0) {
142
+ return {
143
+ totalProcessed: 0,
144
+ totalErrors: 0,
145
+ successfulFiles: [],
146
+ failedFiles: [],
147
+ processingTime: Date.now() - startTime,
148
+ };
149
+ }
150
+ const result = {
151
+ totalProcessed: 0,
152
+ totalErrors: 0,
153
+ successfulFiles: [],
154
+ failedFiles: [],
155
+ processingTime: 0,
156
+ };
157
+ // Process files in batches with concurrency control
158
+ const semaphore = new Semaphore(concurrency);
159
+ const promises = filesToProcess.map(async (filePath) => {
160
+ await semaphore.acquire();
161
+ try {
162
+ await processFile(filePath, inputDir, outputDir, preserveStructure, processingOptions, result, onProgress, onError);
163
+ }
164
+ finally {
165
+ semaphore.release();
166
+ }
167
+ });
168
+ await Promise.all(promises);
169
+ result.processingTime = Date.now() - startTime;
170
+ return result;
171
+ }
172
+ /**
173
+ * Finds all files to process in the given directory
174
+ *
175
+ * Recursively searches through directories to find files matching the specified
176
+ * extensions while respecting exclusion patterns and recursive settings.
177
+ *
178
+ * @async
179
+ * @function findFilesToProcess
180
+ * @param {string} dir - Directory to search in
181
+ * @param {string[]} extensions - File extensions to include (e.g., ['.md', '.txt'])
182
+ * @param {boolean} recursive - Whether to search subdirectories recursively
183
+ * @param {string[]} exclude - Patterns to exclude from search
184
+ * @returns {Promise<string[]>} Array of file paths matching the criteria
185
+ * @private
186
+ */
187
+ async function findFilesToProcess(dir, extensions, recursive, exclude) {
188
+ const files = [];
189
+ const entries = await readdir(dir);
190
+ for (const entry of entries) {
191
+ const fullPath = path.join(dir, entry);
192
+ // Skip excluded files/directories
193
+ if (exclude.some(pattern => entry.includes(pattern))) {
194
+ continue;
195
+ }
196
+ const stats = await stat(fullPath);
197
+ if (stats.isDirectory()) {
198
+ if (recursive) {
199
+ const subFiles = await findFilesToProcess(fullPath, extensions, recursive, exclude);
200
+ files.push(...subFiles);
201
+ }
202
+ }
203
+ else if (stats.isFile()) {
204
+ const ext = path.extname(entry);
205
+ if (extensions.includes(ext)) {
206
+ files.push(fullPath);
207
+ }
208
+ }
209
+ }
210
+ return files;
211
+ }
212
+ /**
213
+ * Processes a single file and writes the output
214
+ *
215
+ * Handles the processing of an individual Legal Markdown file, including reading
216
+ * the source file, processing it through the Legal Markdown system, determining
217
+ * the output path, and writing the processed content and any exported files.
218
+ *
219
+ * @async
220
+ * @function processFile
221
+ * @param {string} filePath - Path to the input file to process
222
+ * @param {string} inputDir - Base input directory path
223
+ * @param {string} outputDir - Base output directory path
224
+ * @param {boolean} preserveStructure - Whether to preserve directory structure in output
225
+ * @param {LegalMarkdownOptions} processingOptions - Options for Legal Markdown processing
226
+ * @param {BatchProcessingResult} result - Result object to update with processing outcome
227
+ * @param {Function} [onProgress] - Optional callback for progress updates
228
+ * @param {Function} [onError] - Optional callback for error handling
229
+ * @returns {Promise<void>} Promise that resolves when processing is complete
230
+ * @private
231
+ */
232
+ async function processFile(filePath, inputDir, outputDir, preserveStructure, processingOptions, result, onProgress, onError) {
233
+ try {
234
+ // Read file content
235
+ const content = await readFile(filePath, 'utf8');
236
+ // Process the content
237
+ const processedResult = (0, index_1.processLegalMarkdown)(content, {
238
+ ...processingOptions,
239
+ basePath: path.dirname(filePath),
240
+ });
241
+ // Determine output file path
242
+ const relativePath = path.relative(inputDir, filePath);
243
+ const outputFilePath = preserveStructure
244
+ ? path.join(outputDir, relativePath)
245
+ : path.join(outputDir, path.basename(filePath));
246
+ // Create output directory if needed
247
+ const outputFileDir = path.dirname(outputFilePath);
248
+ if (!fs.existsSync(outputFileDir)) {
249
+ fs.mkdirSync(outputFileDir, { recursive: true });
250
+ }
251
+ // Write processed content
252
+ await writeFile(outputFilePath, processedResult.content);
253
+ // Export metadata if generated
254
+ if (processedResult.exportedFiles && processedResult.exportedFiles.length > 0) {
255
+ // Handle exported metadata files
256
+ for (const exportedFile of processedResult.exportedFiles) {
257
+ const exportedOutputPath = preserveStructure
258
+ ? path.join(outputDir, path.relative(inputDir, exportedFile))
259
+ : path.join(outputDir, path.basename(exportedFile));
260
+ // Copy exported file to output directory
261
+ if (fs.existsSync(exportedFile)) {
262
+ const exportedContent = await readFile(exportedFile, 'utf8');
263
+ await writeFile(exportedOutputPath, exportedContent);
264
+ }
265
+ }
266
+ }
267
+ result.totalProcessed++;
268
+ result.successfulFiles.push(filePath);
269
+ if (onProgress) {
270
+ onProgress(result.totalProcessed + result.totalErrors, -1, filePath);
271
+ }
272
+ }
273
+ catch (error) {
274
+ const errorMessage = error instanceof Error ? error.message : String(error);
275
+ result.totalErrors++;
276
+ result.failedFiles.push({
277
+ file: filePath,
278
+ error: errorMessage,
279
+ });
280
+ if (onError) {
281
+ onError(filePath, error instanceof Error ? error : new Error(String(error)));
282
+ }
283
+ if (onProgress) {
284
+ onProgress(result.totalProcessed + result.totalErrors, -1, filePath);
285
+ }
286
+ }
287
+ }
288
+ /**
289
+ * Simple semaphore for controlling concurrency
290
+ *
291
+ * Provides a mechanism to limit the number of concurrent operations by using
292
+ * a permit-based system. Useful for controlling resource usage during batch processing.
293
+ *
294
+ * @class Semaphore
295
+ * @private
296
+ * @example
297
+ * ```typescript
298
+ * const semaphore = new Semaphore(3); // Allow max 3 concurrent operations
299
+ *
300
+ * async function performOperation() {
301
+ * await semaphore.acquire();
302
+ * try {
303
+ * // Perform the operation
304
+ * await someAsyncOperation();
305
+ * } finally {
306
+ * semaphore.release();
307
+ * }
308
+ * }
309
+ * ```
310
+ */
311
+ class Semaphore {
312
+ /**
313
+ * Creates a new Semaphore instance
314
+ *
315
+ * @param {number} permits - Maximum number of concurrent operations allowed
316
+ */
317
+ constructor(permits) {
318
+ this.waiting = [];
319
+ this.permits = permits;
320
+ }
321
+ /**
322
+ * Acquires a permit, waiting if necessary
323
+ *
324
+ * @async
325
+ * @method acquire
326
+ * @returns {Promise<void>} Promise that resolves when a permit is acquired
327
+ */
328
+ async acquire() {
329
+ if (this.permits > 0) {
330
+ this.permits--;
331
+ return;
332
+ }
333
+ return new Promise(resolve => {
334
+ this.waiting.push(resolve);
335
+ });
336
+ }
337
+ /**
338
+ * Releases a permit, allowing waiting operations to proceed
339
+ *
340
+ * @method release
341
+ * @returns {void}
342
+ */
343
+ release() {
344
+ this.permits++;
345
+ if (this.waiting.length > 0) {
346
+ const next = this.waiting.shift();
347
+ if (next) {
348
+ this.permits--;
349
+ next();
350
+ }
351
+ }
352
+ }
353
+ }
354
+ /**
355
+ * Utility function to get processing statistics from batch processing results
356
+ *
357
+ * Calculates useful statistics about the batch processing operation including
358
+ * success rate, average processing time per file, and throughput metrics.
359
+ *
360
+ * @function getProcessingStats
361
+ * @param {BatchProcessingResult} result - The batch processing result to analyze
362
+ * @returns {Object} Object containing processing statistics
363
+ * @returns {number} returns.successRate - Success rate as a percentage (0-100)
364
+ * @returns {number} returns.averageTimePerFile - Average processing time per file in milliseconds
365
+ * @returns {number} returns.filesPerSecond - Processing throughput in files per second
366
+ * @example
367
+ * ```typescript
368
+ * import { processBatch, getProcessingStats } from './batch-processor';
369
+ *
370
+ * const result = await processBatch({
371
+ * inputDir: './documents',
372
+ * outputDir: './output'
373
+ * });
374
+ *
375
+ * const stats = getProcessingStats(result);
376
+ * console.log(`Success rate: ${stats.successRate.toFixed(2)}%`);
377
+ * console.log(`Average time per file: ${stats.averageTimePerFile.toFixed(2)}ms`);
378
+ * console.log(`Throughput: ${stats.filesPerSecond.toFixed(2)} files/second`);
379
+ * ```
380
+ */
381
+ function getProcessingStats(result) {
382
+ const totalFiles = result.totalProcessed + result.totalErrors;
383
+ const successRate = totalFiles > 0 ? (result.totalProcessed / totalFiles) * 100 : 0;
384
+ const averageTimePerFile = totalFiles > 0 ? result.processingTime / totalFiles : 0;
385
+ const filesPerSecond = result.processingTime > 0 ? (totalFiles / result.processingTime) * 1000 : 0;
386
+ return {
387
+ successRate,
388
+ averageTimePerFile,
389
+ filesPerSecond,
390
+ };
391
+ }
392
+ //# sourceMappingURL=batch-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-processor.js","sourceRoot":"","sources":["../../src/extensions/batch-processor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4IH,oCAwEC;AAuPD,gDAgBC;AAzdD,uCAAyB;AACzB,2CAA6B;AAC7B,+BAAiC;AAEjC,oCAAgD;AAEhD,MAAM,OAAO,GAAG,IAAA,gBAAS,EAAC,EAAE,CAAC,OAAO,CAAC,CAAC;AACtC,MAAM,IAAI,GAAG,IAAA,gBAAS,EAAC,EAAE,CAAC,IAAI,CAAC,CAAC;AAChC,MAAM,QAAQ,GAAG,IAAA,gBAAS,EAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AACxC,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AA6F1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACI,KAAK,UAAU,YAAY,CAChC,OAA+B;IAE/B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,EACJ,QAAQ,EACR,SAAS,EACT,UAAU,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,EAC5B,SAAS,GAAG,KAAK,EACjB,iBAAiB,GAAG,IAAI,EACxB,OAAO,GAAG,EAAE,EACZ,WAAW,GAAG,CAAC,EACf,UAAU,EACV,OAAO,EACP,GAAG,iBAAiB,EACrB,GAAG,OAAO,CAAC;IAEZ,2BAA2B;IAC3B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,8CAA8C;IAC9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G,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACnF,MAAM,cAAc,GAClB,MAAM,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9E,OAAO;QACL,WAAW;QACX,kBAAkB;QAClB,cAAc;KACf,CAAC;AACJ,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @fileoverview Output Formatters for Legal Documents
3
+ *
4
+ * This module provides enhanced formatting capabilities for Legal Markdown documents
5
+ * beyond the core functionality. It includes formatters for different output styles,
6
+ * HTML generation, and document presentation optimizations.
7
+ *
8
+ * Features:
9
+ * - Enhanced document styling with line spacing options
10
+ * - Page break insertion for print-friendly output
11
+ * - HTML generation with legal-specific styling
12
+ * - Header formatting with multiple style options
13
+ * - Extensions not present in the original legal-markdown
14
+ * - Print-optimized document formatting
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { formatLegalDocument, toLegalHTML } from './formatters';
19
+ *
20
+ * // Format document with double line spacing
21
+ * const formatted = formatLegalDocument(content, {
22
+ * lineSpacing: 'double',
23
+ * pageBreaks: true,
24
+ * headerStyle: 'bold'
25
+ * });
26
+ *
27
+ * // Convert to HTML with legal styling
28
+ * const html = toLegalHTML(content);
29
+ * ```
30
+ */
31
+ /**
32
+ * Formats legal document output with enhanced styling options
33
+ *
34
+ * This function provides advanced formatting capabilities for Legal Markdown documents,
35
+ * including line spacing control, page break insertion, and header styling. These
36
+ * features are extensions not present in the original legal-markdown specification.
37
+ *
38
+ * @function formatLegalDocument
39
+ * @param {string} content - The legal document content to format
40
+ * @param {Object} [options={}] - Formatting options
41
+ * @param {'single' | 'double'} [options.lineSpacing='single'] - Line spacing style
42
+ * @param {boolean} [options.pageBreaks=false] - Whether to add page breaks before major sections
43
+ * @param {'bold' | 'underline' | 'both'} [options.headerStyle] - Header styling option
44
+ * @returns {string} The formatted document content
45
+ * @example
46
+ * ```typescript
47
+ * import { formatLegalDocument } from './formatters';
48
+ *
49
+ * // Basic formatting with double line spacing
50
+ * const formatted = formatLegalDocument(content, {
51
+ * lineSpacing: 'double'
52
+ * });
53
+ *
54
+ * // Advanced formatting with page breaks and header styling
55
+ * const formatted = formatLegalDocument(content, {
56
+ * lineSpacing: 'double',
57
+ * pageBreaks: true,
58
+ * headerStyle: 'bold'
59
+ * });
60
+ *
61
+ * // Print-friendly formatting
62
+ * const printReady = formatLegalDocument(content, {
63
+ * lineSpacing: 'single',
64
+ * pageBreaks: true
65
+ * });
66
+ * ```
67
+ */
68
+ export declare function formatLegalDocument(content: string, options?: {
69
+ lineSpacing?: 'single' | 'double';
70
+ pageBreaks?: boolean;
71
+ headerStyle?: 'bold' | 'underline' | 'both';
72
+ }): string;
73
+ /**
74
+ * Converts legal document to HTML with legal-specific styling
75
+ *
76
+ * Generates a complete HTML document with professional legal document styling,
77
+ * including Times New Roman font, proper line spacing, and structured layout
78
+ * with appropriate margins and indentation for legal document presentation.
79
+ *
80
+ * @function toLegalHTML
81
+ * @param {string} content - The legal document content to convert to HTML
82
+ * @returns {string} Complete HTML document with embedded styles
83
+ * @example
84
+ * ```typescript
85
+ * import { toLegalHTML } from './formatters';
86
+ *
87
+ * // Convert processed legal markdown to HTML
88
+ * const htmlDocument = toLegalHTML(processedContent);
89
+ *
90
+ * // Save to file
91
+ * fs.writeFileSync('contract.html', htmlDocument);
92
+ *
93
+ * // Or serve via web server
94
+ * res.setHeader('Content-Type', 'text/html');
95
+ * res.send(htmlDocument);
96
+ * ```
97
+ */
98
+ export declare function toLegalHTML(content: string): string;
99
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/formatters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAClC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;CACxC,GACL,MAAM,CAaR;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAkBnD"}
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Output Formatters for Legal Documents
4
+ *
5
+ * This module provides enhanced formatting capabilities for Legal Markdown documents
6
+ * beyond the core functionality. It includes formatters for different output styles,
7
+ * HTML generation, and document presentation optimizations.
8
+ *
9
+ * Features:
10
+ * - Enhanced document styling with line spacing options
11
+ * - Page break insertion for print-friendly output
12
+ * - HTML generation with legal-specific styling
13
+ * - Header formatting with multiple style options
14
+ * - Extensions not present in the original legal-markdown
15
+ * - Print-optimized document formatting
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { formatLegalDocument, toLegalHTML } from './formatters';
20
+ *
21
+ * // Format document with double line spacing
22
+ * const formatted = formatLegalDocument(content, {
23
+ * lineSpacing: 'double',
24
+ * pageBreaks: true,
25
+ * headerStyle: 'bold'
26
+ * });
27
+ *
28
+ * // Convert to HTML with legal styling
29
+ * const html = toLegalHTML(content);
30
+ * ```
31
+ */
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.formatLegalDocument = formatLegalDocument;
34
+ exports.toLegalHTML = toLegalHTML;
35
+ // Output formatters - Extensions for output formatting beyond core functionality
36
+ /**
37
+ * Formats legal document output with enhanced styling options
38
+ *
39
+ * This function provides advanced formatting capabilities for Legal Markdown documents,
40
+ * including line spacing control, page break insertion, and header styling. These
41
+ * features are extensions not present in the original legal-markdown specification.
42
+ *
43
+ * @function formatLegalDocument
44
+ * @param {string} content - The legal document content to format
45
+ * @param {Object} [options={}] - Formatting options
46
+ * @param {'single' | 'double'} [options.lineSpacing='single'] - Line spacing style
47
+ * @param {boolean} [options.pageBreaks=false] - Whether to add page breaks before major sections
48
+ * @param {'bold' | 'underline' | 'both'} [options.headerStyle] - Header styling option
49
+ * @returns {string} The formatted document content
50
+ * @example
51
+ * ```typescript
52
+ * import { formatLegalDocument } from './formatters';
53
+ *
54
+ * // Basic formatting with double line spacing
55
+ * const formatted = formatLegalDocument(content, {
56
+ * lineSpacing: 'double'
57
+ * });
58
+ *
59
+ * // Advanced formatting with page breaks and header styling
60
+ * const formatted = formatLegalDocument(content, {
61
+ * lineSpacing: 'double',
62
+ * pageBreaks: true,
63
+ * headerStyle: 'bold'
64
+ * });
65
+ *
66
+ * // Print-friendly formatting
67
+ * const printReady = formatLegalDocument(content, {
68
+ * lineSpacing: 'single',
69
+ * pageBreaks: true
70
+ * });
71
+ * ```
72
+ */
73
+ function formatLegalDocument(content, options = {}) {
74
+ let formatted = content;
75
+ if (options.lineSpacing === 'double') {
76
+ formatted = formatted.replace(/\n/g, '\n\n');
77
+ }
78
+ if (options.pageBreaks) {
79
+ // Add page breaks before major sections
80
+ formatted = formatted.replace(/^Article \d+\./gm, '\n---PAGE BREAK---\n$&');
81
+ }
82
+ return formatted;
83
+ }
84
+ /**
85
+ * Converts legal document to HTML with legal-specific styling
86
+ *
87
+ * Generates a complete HTML document with professional legal document styling,
88
+ * including Times New Roman font, proper line spacing, and structured layout
89
+ * with appropriate margins and indentation for legal document presentation.
90
+ *
91
+ * @function toLegalHTML
92
+ * @param {string} content - The legal document content to convert to HTML
93
+ * @returns {string} Complete HTML document with embedded styles
94
+ * @example
95
+ * ```typescript
96
+ * import { toLegalHTML } from './formatters';
97
+ *
98
+ * // Convert processed legal markdown to HTML
99
+ * const htmlDocument = toLegalHTML(processedContent);
100
+ *
101
+ * // Save to file
102
+ * fs.writeFileSync('contract.html', htmlDocument);
103
+ *
104
+ * // Or serve via web server
105
+ * res.setHeader('Content-Type', 'text/html');
106
+ * res.send(htmlDocument);
107
+ * ```
108
+ */
109
+ function toLegalHTML(content) {
110
+ return `<!DOCTYPE html>
111
+ <html>
112
+ <head>
113
+ <title>Legal Document</title>
114
+ <style>
115
+ body { font-family: 'Times New Roman', serif; line-height: 1.6; }
116
+ .article { margin: 20px 0; }
117
+ .section { margin-left: 20px; }
118
+ .subsection { margin-left: 40px; }
119
+ </style>
120
+ </head>
121
+ <body>
122
+ <div class="legal-document">
123
+ ${content.replace(/\n/g, '<br>')}
124
+ </div>
125
+ </body>
126
+ </html>`;
127
+ }
128
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/formatters/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;AAyCH,kDAoBC;AA2BD,kCAkBC;AAxGD,iFAAiF;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,SAAgB,mBAAmB,CACjC,OAAe,EACf,UAII,EAAE;IAEN,IAAI,SAAS,GAAG,OAAO,CAAC;IAExB,IAAI,OAAO,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;QACrC,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,wCAAwC;QACxC,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,kBAAkB,EAAE,wBAAwB,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,WAAW,CAAC,OAAe;IACzC,OAAO;;;;;;;;;;;;;UAaC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;;;QAGhC,CAAC;AACT,CAAC"}