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,150 @@
1
+ /**
2
+ * @fileoverview Utility Library for Legal Markdown Processing
3
+ *
4
+ * This module provides essential utility functions for file operations,
5
+ * path handling, data manipulation, and common programming patterns used
6
+ * throughout the Legal Markdown processing system.
7
+ *
8
+ * Features:
9
+ * - File system operations with error handling
10
+ * - Path resolution and manipulation utilities
11
+ * - Data transformation and merging functions
12
+ * - Input validation and sanitization
13
+ * - Performance optimization utilities (debounce)
14
+ * - URL validation and file extension handling
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import {
19
+ * readFileSync,
20
+ * writeFileSync,
21
+ * resolveFilePath,
22
+ * deepMerge,
23
+ * sanitizeFileName
24
+ * } from './lib';
25
+ *
26
+ * // Read a file safely
27
+ * const content = readFileSync('./document.md');
28
+ *
29
+ * // Resolve relative paths
30
+ * const fullPath = resolveFilePath('./docs', 'contract.md');
31
+ *
32
+ * // Merge configuration objects
33
+ * const config = deepMerge(defaultConfig, userConfig);
34
+ * ```
35
+ */
36
+ /**
37
+ * Ensures that a directory exists, creating it recursively if necessary
38
+ *
39
+ * @param {string} dirPath - The directory path to ensure exists
40
+ * @returns {void}
41
+ * @example
42
+ * ```typescript
43
+ * ensureDirectoryExists('./output/documents');
44
+ * ```
45
+ */
46
+ export declare function ensureDirectoryExists(dirPath: string): void;
47
+ /**
48
+ * Reads a file synchronously with proper error handling
49
+ *
50
+ * @param {string} filePath - The path to the file to read
51
+ * @returns {string} The file content as UTF-8 string
52
+ * @throws {FileNotFoundError} When the file does not exist
53
+ * @throws {Error} For other file system errors
54
+ * @example
55
+ * ```typescript
56
+ * const content = readFileSync('./document.md');
57
+ * ```
58
+ */
59
+ export declare function readFileSync(filePath: string): string;
60
+ /**
61
+ * Writes content to a file synchronously, creating directories as needed
62
+ *
63
+ * @param {string} filePath - The path where the file will be written
64
+ * @param {string} content - The content to write to the file
65
+ * @returns {void}
66
+ * @example
67
+ * ```typescript
68
+ * writeFileSync('./output/document.md', processedContent);
69
+ * ```
70
+ */
71
+ export declare function writeFileSync(filePath: string, content: string): void;
72
+ /**
73
+ * Resolves a file path relative to a base directory
74
+ *
75
+ * @param {string | undefined} basePath - The base directory path (defaults to cwd)
76
+ * @param {string} filePath - The file path to resolve
77
+ * @returns {string} The resolved absolute path
78
+ * @example
79
+ * ```typescript
80
+ * const fullPath = resolveFilePath('./docs', 'contract.md');
81
+ * // Returns: '/path/to/docs/contract.md'
82
+ * ```
83
+ */
84
+ export declare function resolveFilePath(basePath: string | undefined, filePath: string): string;
85
+ /**
86
+ * Gets the file extension from a file path in lowercase
87
+ *
88
+ * @param {string} filePath - The file path to extract extension from
89
+ * @returns {string} The file extension in lowercase (including the dot)
90
+ * @example
91
+ * ```typescript
92
+ * const ext = getFileExtension('document.MD');
93
+ * // Returns: '.md'
94
+ * ```
95
+ */
96
+ export declare function getFileExtension(filePath: string): string;
97
+ /**
98
+ * Validates if a string is a valid URL
99
+ *
100
+ * @param {string} str - The string to validate
101
+ * @returns {boolean} True if the string is a valid URL, false otherwise
102
+ * @example
103
+ * ```typescript
104
+ * const isValid = isValidUrl('https://example.com');
105
+ * // Returns: true
106
+ * ```
107
+ */
108
+ export declare function isValidUrl(str: string): boolean;
109
+ /**
110
+ * Sanitizes a file name by replacing invalid characters with underscores
111
+ *
112
+ * @param {string} fileName - The file name to sanitize
113
+ * @returns {string} The sanitized file name
114
+ * @example
115
+ * ```typescript
116
+ * const safe = sanitizeFileName('My Document!.pdf');
117
+ * // Returns: 'My_Document_.pdf'
118
+ * ```
119
+ */
120
+ export declare function sanitizeFileName(fileName: string): string;
121
+ /**
122
+ * Creates a debounced version of a function that delays execution
123
+ *
124
+ * @param {T} func - The function to debounce
125
+ * @param {number} wait - The delay in milliseconds
126
+ * @returns {Function} The debounced function
127
+ * @example
128
+ * ```typescript
129
+ * const debouncedSave = debounce(saveDocument, 300);
130
+ * debouncedSave(content); // Will only execute after 300ms of inactivity
131
+ * ```
132
+ */
133
+ export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => void;
134
+ /**
135
+ * Performs a deep merge of objects, combining nested properties
136
+ *
137
+ * @param {T} target - The target object to merge into
138
+ * @param {...Partial<T>} sources - The source objects to merge from
139
+ * @returns {T} The merged object
140
+ * @example
141
+ * ```typescript
142
+ * const merged = deepMerge(
143
+ * { a: { b: 1 } },
144
+ * { a: { c: 2 } }
145
+ * );
146
+ * // Returns: { a: { b: 1, c: 2 } }
147
+ * ```
148
+ */
149
+ export declare function deepMerge<T extends Record<string, any>>(target: T, ...sources: Partial<T>[]): T;
150
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAMH;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAI3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CASrD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAIrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOtF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO/C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAMlC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAgB/F"}
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Utility Library for Legal Markdown Processing
4
+ *
5
+ * This module provides essential utility functions for file operations,
6
+ * path handling, data manipulation, and common programming patterns used
7
+ * throughout the Legal Markdown processing system.
8
+ *
9
+ * Features:
10
+ * - File system operations with error handling
11
+ * - Path resolution and manipulation utilities
12
+ * - Data transformation and merging functions
13
+ * - Input validation and sanitization
14
+ * - Performance optimization utilities (debounce)
15
+ * - URL validation and file extension handling
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import {
20
+ * readFileSync,
21
+ * writeFileSync,
22
+ * resolveFilePath,
23
+ * deepMerge,
24
+ * sanitizeFileName
25
+ * } from './lib';
26
+ *
27
+ * // Read a file safely
28
+ * const content = readFileSync('./document.md');
29
+ *
30
+ * // Resolve relative paths
31
+ * const fullPath = resolveFilePath('./docs', 'contract.md');
32
+ *
33
+ * // Merge configuration objects
34
+ * const config = deepMerge(defaultConfig, userConfig);
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.ensureDirectoryExists = ensureDirectoryExists;
72
+ exports.readFileSync = readFileSync;
73
+ exports.writeFileSync = writeFileSync;
74
+ exports.resolveFilePath = resolveFilePath;
75
+ exports.getFileExtension = getFileExtension;
76
+ exports.isValidUrl = isValidUrl;
77
+ exports.sanitizeFileName = sanitizeFileName;
78
+ exports.debounce = debounce;
79
+ exports.deepMerge = deepMerge;
80
+ const fs = __importStar(require("fs"));
81
+ const path = __importStar(require("path"));
82
+ const _errors_1 = require("../errors/index.js");
83
+ /**
84
+ * Ensures that a directory exists, creating it recursively if necessary
85
+ *
86
+ * @param {string} dirPath - The directory path to ensure exists
87
+ * @returns {void}
88
+ * @example
89
+ * ```typescript
90
+ * ensureDirectoryExists('./output/documents');
91
+ * ```
92
+ */
93
+ function ensureDirectoryExists(dirPath) {
94
+ if (!fs.existsSync(dirPath)) {
95
+ fs.mkdirSync(dirPath, { recursive: true });
96
+ }
97
+ }
98
+ /**
99
+ * Reads a file synchronously with proper error handling
100
+ *
101
+ * @param {string} filePath - The path to the file to read
102
+ * @returns {string} The file content as UTF-8 string
103
+ * @throws {FileNotFoundError} When the file does not exist
104
+ * @throws {Error} For other file system errors
105
+ * @example
106
+ * ```typescript
107
+ * const content = readFileSync('./document.md');
108
+ * ```
109
+ */
110
+ function readFileSync(filePath) {
111
+ try {
112
+ return fs.readFileSync(filePath, 'utf-8');
113
+ }
114
+ catch (error) {
115
+ if (error.code === 'ENOENT') {
116
+ throw new _errors_1.FileNotFoundError(filePath);
117
+ }
118
+ throw error;
119
+ }
120
+ }
121
+ /**
122
+ * Writes content to a file synchronously, creating directories as needed
123
+ *
124
+ * @param {string} filePath - The path where the file will be written
125
+ * @param {string} content - The content to write to the file
126
+ * @returns {void}
127
+ * @example
128
+ * ```typescript
129
+ * writeFileSync('./output/document.md', processedContent);
130
+ * ```
131
+ */
132
+ function writeFileSync(filePath, content) {
133
+ const dir = path.dirname(filePath);
134
+ ensureDirectoryExists(dir);
135
+ fs.writeFileSync(filePath, content, 'utf-8');
136
+ }
137
+ /**
138
+ * Resolves a file path relative to a base directory
139
+ *
140
+ * @param {string | undefined} basePath - The base directory path (defaults to cwd)
141
+ * @param {string} filePath - The file path to resolve
142
+ * @returns {string} The resolved absolute path
143
+ * @example
144
+ * ```typescript
145
+ * const fullPath = resolveFilePath('./docs', 'contract.md');
146
+ * // Returns: '/path/to/docs/contract.md'
147
+ * ```
148
+ */
149
+ function resolveFilePath(basePath, filePath) {
150
+ if (path.isAbsolute(filePath)) {
151
+ return filePath;
152
+ }
153
+ const base = basePath || process.cwd();
154
+ return path.resolve(base, filePath);
155
+ }
156
+ /**
157
+ * Gets the file extension from a file path in lowercase
158
+ *
159
+ * @param {string} filePath - The file path to extract extension from
160
+ * @returns {string} The file extension in lowercase (including the dot)
161
+ * @example
162
+ * ```typescript
163
+ * const ext = getFileExtension('document.MD');
164
+ * // Returns: '.md'
165
+ * ```
166
+ */
167
+ function getFileExtension(filePath) {
168
+ return path.extname(filePath).toLowerCase();
169
+ }
170
+ /**
171
+ * Validates if a string is a valid URL
172
+ *
173
+ * @param {string} str - The string to validate
174
+ * @returns {boolean} True if the string is a valid URL, false otherwise
175
+ * @example
176
+ * ```typescript
177
+ * const isValid = isValidUrl('https://example.com');
178
+ * // Returns: true
179
+ * ```
180
+ */
181
+ function isValidUrl(str) {
182
+ try {
183
+ new URL(str);
184
+ return true;
185
+ }
186
+ catch {
187
+ return false;
188
+ }
189
+ }
190
+ /**
191
+ * Sanitizes a file name by replacing invalid characters with underscores
192
+ *
193
+ * @param {string} fileName - The file name to sanitize
194
+ * @returns {string} The sanitized file name
195
+ * @example
196
+ * ```typescript
197
+ * const safe = sanitizeFileName('My Document!.pdf');
198
+ * // Returns: 'My_Document_.pdf'
199
+ * ```
200
+ */
201
+ function sanitizeFileName(fileName) {
202
+ return fileName.replace(/[^a-z0-9.-]/gi, '_');
203
+ }
204
+ /**
205
+ * Creates a debounced version of a function that delays execution
206
+ *
207
+ * @param {T} func - The function to debounce
208
+ * @param {number} wait - The delay in milliseconds
209
+ * @returns {Function} The debounced function
210
+ * @example
211
+ * ```typescript
212
+ * const debouncedSave = debounce(saveDocument, 300);
213
+ * debouncedSave(content); // Will only execute after 300ms of inactivity
214
+ * ```
215
+ */
216
+ function debounce(func, wait) {
217
+ let timeout;
218
+ return (...args) => {
219
+ clearTimeout(timeout);
220
+ timeout = setTimeout(() => func(...args), wait);
221
+ };
222
+ }
223
+ /**
224
+ * Performs a deep merge of objects, combining nested properties
225
+ *
226
+ * @param {T} target - The target object to merge into
227
+ * @param {...Partial<T>} sources - The source objects to merge from
228
+ * @returns {T} The merged object
229
+ * @example
230
+ * ```typescript
231
+ * const merged = deepMerge(
232
+ * { a: { b: 1 } },
233
+ * { a: { c: 2 } }
234
+ * );
235
+ * // Returns: { a: { b: 1, c: 2 } }
236
+ * ```
237
+ */
238
+ function deepMerge(target, ...sources) {
239
+ if (!sources.length)
240
+ return target;
241
+ const source = sources.shift();
242
+ if (isObject(target) && isObject(source)) {
243
+ for (const key in source) {
244
+ if (isObject(source[key])) {
245
+ if (!target[key])
246
+ Object.assign(target, { [key]: {} });
247
+ deepMerge(target[key], source[key]);
248
+ }
249
+ else {
250
+ Object.assign(target, { [key]: source[key] });
251
+ }
252
+ }
253
+ }
254
+ return deepMerge(target, ...sources);
255
+ }
256
+ /**
257
+ * Type guard to check if an item is a plain object
258
+ *
259
+ * @param {any} item - The item to check
260
+ * @returns {boolean} True if the item is a plain object, false otherwise
261
+ */
262
+ function isObject(item) {
263
+ return item && typeof item === 'object' && !Array.isArray(item);
264
+ }
265
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;;;;;;;;;;;;;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,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;oBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBACvD,SAAS,CAAC,MAAM,CAAC,GAAG,CAAwB,EAAE,MAAM,CAAC,GAAG,CAAwB,CAAC,CAAC;YACpF,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,IAAS;IACzB,OAAO,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @fileoverview Content Detection Module for Legal Markdown Processing
3
+ *
4
+ * This module provides intelligent content type detection for various document
5
+ * formats including reStructuredText (RST) and LaTeX. It uses pattern matching
6
+ * and heuristics to determine if content requires specific parsers for conversion
7
+ * to Legal Markdown format.
8
+ *
9
+ * Features:
10
+ * - reStructuredText format detection with pattern-based analysis
11
+ * - LaTeX document format detection with command recognition
12
+ * - YAML frontmatter awareness to avoid false positives
13
+ * - Robust pattern matching with configurable thresholds
14
+ * - Support for various RST directives and syntax elements
15
+ * - LaTeX command and environment detection
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { ContentDetector } from './content-detector';
20
+ *
21
+ * // Detect RST content
22
+ * const isRst = ContentDetector.needsRstParser(content);
23
+ * if (isRst) {
24
+ * content = await convertRstToLegalMarkdown(content);
25
+ * }
26
+ *
27
+ * // Detect LaTeX content
28
+ * const isLatex = ContentDetector.needsLatexParser(content);
29
+ * if (isLatex) {
30
+ * content = await convertLatexToLegalMarkdown(content);
31
+ * }
32
+ * ```
33
+ */
34
+ /**
35
+ * Content detection utility class for identifying document formats
36
+ *
37
+ * Provides static methods to detect different document formats using pattern
38
+ * matching and content analysis. Designed to prevent unnecessary processing
39
+ * of content that doesn't require specific parsers.
40
+ *
41
+ * @class ContentDetector
42
+ * @example
43
+ * ```typescript
44
+ * import { ContentDetector } from './content-detector';
45
+ *
46
+ * // Check if content needs RST processing
47
+ * if (ContentDetector.needsRstParser(content)) {
48
+ * content = await processRstContent(content);
49
+ * }
50
+ *
51
+ * // Check if content needs LaTeX processing
52
+ * if (ContentDetector.needsLatexParser(content)) {
53
+ * content = await processLatexContent(content);
54
+ * }
55
+ * ```
56
+ */
57
+ export declare class ContentDetector {
58
+ /**
59
+ * Detects if content requires reStructuredText parsing
60
+ *
61
+ * Uses pattern matching to identify RST-specific syntax elements including
62
+ * directives, header underlines, reference links, code blocks, and other
63
+ * RST constructs. Avoids false positives with YAML frontmatter content.
64
+ *
65
+ * @static
66
+ * @param {string} content - The content to analyze for RST patterns
67
+ * @returns {boolean} True if content appears to be reStructuredText, false otherwise
68
+ * @example
69
+ * ```typescript
70
+ * const rstContent = `
71
+ * Introduction
72
+ * ============
73
+ *
74
+ * This is a sample RST document.
75
+ *
76
+ * .. note::
77
+ * This is an RST directive.
78
+ * `;
79
+ *
80
+ * const isRst = ContentDetector.needsRstParser(rstContent);
81
+ * console.log(isRst); // true
82
+ * ```
83
+ */
84
+ static needsRstParser(content: string): boolean;
85
+ /**
86
+ * Detects if content requires LaTeX parsing
87
+ *
88
+ * Uses pattern matching to identify LaTeX-specific commands, environments,
89
+ * and syntax elements including document classes, sections, text formatting
90
+ * commands, and environments. Requires multiple pattern matches to avoid
91
+ * false positives.
92
+ *
93
+ * @static
94
+ * @param {string} content - The content to analyze for LaTeX patterns
95
+ * @returns {boolean} True if content appears to be LaTeX, false otherwise
96
+ * @example
97
+ * ```typescript
98
+ * const latexContent = `
99
+ * \\documentclass{article}
100
+ * \\begin{document}
101
+ * \\section{Introduction}
102
+ * This is \\textbf{bold} text in LaTeX.
103
+ * \\end{document}
104
+ * `;
105
+ *
106
+ * const isLatex = ContentDetector.needsLatexParser(latexContent);
107
+ * console.log(isLatex); // true
108
+ * ```
109
+ */
110
+ static needsLatexParser(content: string): boolean;
111
+ /**
112
+ * Detects if content requires Pandoc processing
113
+ *
114
+ * This is a convenience method that combines RST and LaTeX detection to
115
+ * determine if content needs any form of Pandoc processing for conversion
116
+ * to Legal Markdown format.
117
+ *
118
+ * @static
119
+ * @param {string} content - The content to analyze for format patterns
120
+ * @returns {boolean} True if content needs Pandoc processing, false otherwise
121
+ * @example
122
+ * ```typescript
123
+ * const needsProcessing = ContentDetector.needsPandoc(content);
124
+ * if (needsProcessing) {
125
+ * content = await processThroughPandoc(content);
126
+ * }
127
+ * ```
128
+ */
129
+ static needsPandoc(content: string): boolean;
130
+ }
131
+ //# sourceMappingURL=content-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-detector.d.ts","sourceRoot":"","sources":["../../src/parsers/content-detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,eAAe;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IA6C/C;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAoDjD;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAG7C"}