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.
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/browser.d.ts +87 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +157 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli/index.d.ts +34 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +221 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/service.d.ts +128 -0
- package/dist/cli/service.d.ts.map +1 -0
- package/dist/cli/service.js +284 -0
- package/dist/cli/service.js.map +1 -0
- package/dist/constants/index.d.ts +229 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +232 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/core/exporters/metadata-exporter.d.ts +104 -0
- package/dist/core/exporters/metadata-exporter.d.ts.map +1 -0
- package/dist/core/exporters/metadata-exporter.js +201 -0
- package/dist/core/exporters/metadata-exporter.js.map +1 -0
- package/dist/core/index.d.ts +40 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +56 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/parsers/yaml-parser.d.ts +149 -0
- package/dist/core/parsers/yaml-parser.d.ts.map +1 -0
- package/dist/core/parsers/yaml-parser.js +321 -0
- package/dist/core/parsers/yaml-parser.js.map +1 -0
- package/dist/core/processors/clause-processor.d.ts +74 -0
- package/dist/core/processors/clause-processor.d.ts.map +1 -0
- package/dist/core/processors/clause-processor.js +213 -0
- package/dist/core/processors/clause-processor.js.map +1 -0
- package/dist/core/processors/date-processor.d.ts +90 -0
- package/dist/core/processors/date-processor.d.ts.map +1 -0
- package/dist/core/processors/date-processor.js +336 -0
- package/dist/core/processors/date-processor.js.map +1 -0
- package/dist/core/processors/header-processor.d.ts +104 -0
- package/dist/core/processors/header-processor.d.ts.map +1 -0
- package/dist/core/processors/header-processor.js +585 -0
- package/dist/core/processors/header-processor.js.map +1 -0
- package/dist/core/processors/import-processor.d.ts +116 -0
- package/dist/core/processors/import-processor.d.ts.map +1 -0
- package/dist/core/processors/import-processor.js +236 -0
- package/dist/core/processors/import-processor.js.map +1 -0
- package/dist/core/processors/mixin-processor.d.ts +93 -0
- package/dist/core/processors/mixin-processor.d.ts.map +1 -0
- package/dist/core/processors/mixin-processor.js +378 -0
- package/dist/core/processors/mixin-processor.js.map +1 -0
- package/dist/core/processors/reference-processor.d.ts +115 -0
- package/dist/core/processors/reference-processor.d.ts.map +1 -0
- package/dist/core/processors/reference-processor.js +273 -0
- package/dist/core/processors/reference-processor.js.map +1 -0
- package/dist/errors/index.d.ts +234 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +267 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/extensions/batch-processor.d.ts +197 -0
- package/dist/extensions/batch-processor.d.ts.map +1 -0
- package/dist/extensions/batch-processor.js +392 -0
- package/dist/extensions/batch-processor.js.map +1 -0
- package/dist/extensions/formatters/index.d.ts +99 -0
- package/dist/extensions/formatters/index.d.ts.map +1 -0
- package/dist/extensions/formatters/index.js +128 -0
- package/dist/extensions/formatters/index.js.map +1 -0
- package/dist/extensions/index.d.ts +53 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +71 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/latex-parser.d.ts +111 -0
- package/dist/extensions/latex-parser.d.ts.map +1 -0
- package/dist/extensions/latex-parser.js +563 -0
- package/dist/extensions/latex-parser.js.map +1 -0
- package/dist/extensions/rst-parser.d.ts +112 -0
- package/dist/extensions/rst-parser.d.ts.map +1 -0
- package/dist/extensions/rst-parser.js +268 -0
- package/dist/extensions/rst-parser.js.map +1 -0
- package/dist/extensions/template-loops.d.ts +61 -0
- package/dist/extensions/template-loops.d.ts.map +1 -0
- package/dist/extensions/template-loops.js +418 -0
- package/dist/extensions/template-loops.js.map +1 -0
- package/dist/extensions/utilities/index.d.ts +114 -0
- package/dist/extensions/utilities/index.d.ts.map +1 -0
- package/dist/extensions/utilities/index.js +137 -0
- package/dist/extensions/utilities/index.js.map +1 -0
- package/dist/extensions/validators/index.d.ts +65 -0
- package/dist/extensions/validators/index.d.ts.map +1 -0
- package/dist/extensions/validators/index.js +88 -0
- package/dist/extensions/validators/index.js.map +1 -0
- package/dist/generators/html-generator.d.ts +184 -0
- package/dist/generators/html-generator.d.ts.map +1 -0
- package/dist/generators/html-generator.js +361 -0
- package/dist/generators/html-generator.js.map +1 -0
- package/dist/generators/pdf-generator.d.ts +165 -0
- package/dist/generators/pdf-generator.d.ts.map +1 -0
- package/dist/generators/pdf-generator.js +275 -0
- package/dist/generators/pdf-generator.js.map +1 -0
- package/dist/helpers/date-helpers.d.ts +216 -0
- package/dist/helpers/date-helpers.d.ts.map +1 -0
- package/dist/helpers/date-helpers.js +402 -0
- package/dist/helpers/date-helpers.js.map +1 -0
- package/dist/helpers/index.d.ts +87 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +149 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/number-helpers.d.ts +269 -0
- package/dist/helpers/number-helpers.d.ts.map +1 -0
- package/dist/helpers/number-helpers.js +406 -0
- package/dist/helpers/number-helpers.js.map +1 -0
- package/dist/helpers/string-helpers.d.ts +391 -0
- package/dist/helpers/string-helpers.d.ts.map +1 -0
- package/dist/helpers/string-helpers.js +549 -0
- package/dist/helpers/string-helpers.js.map +1 -0
- package/dist/index.d.ts +229 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +384 -0
- package/dist/index.js.map +1 -0
- package/dist/legal-markdown.umd.min.js +2 -0
- package/dist/legal-markdown.umd.min.js.LICENSE.txt +14 -0
- package/dist/legal-markdown.umd.min.js.map +1 -0
- package/dist/lib/index.d.ts +150 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +265 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/parsers/content-detector.d.ts +131 -0
- package/dist/parsers/content-detector.d.ts.map +1 -0
- package/dist/parsers/content-detector.js +220 -0
- package/dist/parsers/content-detector.js.map +1 -0
- package/dist/parsers/fallback-parsers.d.ts +14 -0
- package/dist/parsers/fallback-parsers.d.ts.map +1 -0
- package/dist/parsers/fallback-parsers.js +188 -0
- package/dist/parsers/fallback-parsers.js.map +1 -0
- package/dist/parsers/implementations/pandoc-native.d.ts +13 -0
- package/dist/parsers/implementations/pandoc-native.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-native.js +63 -0
- package/dist/parsers/implementations/pandoc-native.js.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts +14 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.js +64 -0
- package/dist/parsers/implementations/pandoc-wasm.js.map +1 -0
- package/dist/parsers/pandoc-factory.d.ts +97 -0
- package/dist/parsers/pandoc-factory.d.ts.map +1 -0
- package/dist/parsers/pandoc-factory.js +146 -0
- package/dist/parsers/pandoc-factory.js.map +1 -0
- package/dist/parsers/pandoc-loader.d.ts +24 -0
- package/dist/parsers/pandoc-loader.d.ts.map +1 -0
- package/dist/parsers/pandoc-loader.js +124 -0
- package/dist/parsers/pandoc-loader.js.map +1 -0
- package/dist/parsers/pandoc-parser.d.ts +27 -0
- package/dist/parsers/pandoc-parser.d.ts.map +1 -0
- package/dist/parsers/pandoc-parser.js +3 -0
- package/dist/parsers/pandoc-parser.js.map +1 -0
- package/dist/styles/default.css +125 -0
- package/dist/styles/headers.css +146 -0
- package/dist/styles/highlight.css +171 -0
- package/dist/tracking/field-tracker.d.ts +206 -0
- package/dist/tracking/field-tracker.d.ts.map +1 -0
- package/dist/tracking/field-tracker.js +247 -0
- package/dist/tracking/field-tracker.js.map +1 -0
- package/dist/types.d.ts +186 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +33 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/logger.d.ts +107 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +122 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/web/bundle-standalone.js +28 -0
- package/dist/web/bundle.js +17 -0
- package/dist/web/index.html +1465 -0
- package/dist/web/legal-markdown.umd.min.js +2 -0
- package/dist/web/standalone.html +390 -0
- package/dist/web/styles.css +874 -0
- package/package.json +118 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Date Processing Module for Legal Markdown Documents
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive date processing functionality for Legal Markdown
|
|
5
|
+
* documents, supporting the @today syntax with various formatting options. It handles
|
|
6
|
+
* different date formats, timezones, locales, and provides specialized formatting
|
|
7
|
+
* for legal documents including ordinal suffixes and custom format patterns.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - @today syntax for current date insertion
|
|
11
|
+
* - Format override support: @today[format]
|
|
12
|
+
* - Multiple predefined formats (ISO, US, European, legal, etc.)
|
|
13
|
+
* - Custom format pattern parsing (YYYY-MM-DD, etc.)
|
|
14
|
+
* - Timezone and locale support
|
|
15
|
+
* - Ordinal suffix generation for legal formats
|
|
16
|
+
* - Graceful error handling with fallback formatting
|
|
17
|
+
* - Integration with metadata for default settings
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { processDateReferences } from './date-processor';
|
|
22
|
+
*
|
|
23
|
+
* const content = `
|
|
24
|
+
* This document is dated @today.
|
|
25
|
+
* Contract effective date: @today[long]
|
|
26
|
+
* Expiration: @today[YYYY-MM-DD]
|
|
27
|
+
* Legal format: @today[legal]
|
|
28
|
+
* `;
|
|
29
|
+
*
|
|
30
|
+
* const metadata = {
|
|
31
|
+
* 'date-format': 'ISO',
|
|
32
|
+
* 'timezone': 'America/New_York',
|
|
33
|
+
* 'locale': 'en-US'
|
|
34
|
+
* };
|
|
35
|
+
*
|
|
36
|
+
* const processed = processDateReferences(content, metadata);
|
|
37
|
+
* console.log(processed);
|
|
38
|
+
* // Output:
|
|
39
|
+
* // This document is dated 2024-01-15.
|
|
40
|
+
* // Contract effective date: January 15, 2024
|
|
41
|
+
* // Expiration: 2024-01-15
|
|
42
|
+
* // Legal format: January 15th, 2024
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
import { LegalMarkdownOptions } from '@types';
|
|
46
|
+
/**
|
|
47
|
+
* Date format options that can be specified in YAML front matter
|
|
48
|
+
*
|
|
49
|
+
* @interface DateFormatOptions
|
|
50
|
+
*/
|
|
51
|
+
export interface DateFormatOptions {
|
|
52
|
+
/** Default date format to use (ISO, US, European, legal, long, medium, short, or custom pattern) */
|
|
53
|
+
dateFormat?: string;
|
|
54
|
+
/** Timezone identifier (e.g., 'America/New_York', 'Europe/London', 'UTC') */
|
|
55
|
+
timezone?: string;
|
|
56
|
+
/** Locale identifier for formatting (e.g., 'en-US', 'en-GB', 'de-DE') */
|
|
57
|
+
locale?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Processes special date references in legal documents
|
|
61
|
+
*
|
|
62
|
+
* This is the main function that processes @today references in Legal Markdown
|
|
63
|
+
* documents. It supports format overrides and uses metadata settings for
|
|
64
|
+
* default formatting, timezone, and locale preferences.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} content - The document content containing @today references
|
|
67
|
+
* @param {Record<string, any>} metadata - Document metadata with date formatting options
|
|
68
|
+
* @param {LegalMarkdownOptions} [options={}] - Additional processing options
|
|
69
|
+
* @returns {string} Processed content with @today references replaced by formatted dates
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* // Basic usage with default format
|
|
73
|
+
* const content1 = "Document dated @today";
|
|
74
|
+
* const result1 = processDateReferences(content1, {});
|
|
75
|
+
* // Output: "Document dated 2024-01-15"
|
|
76
|
+
*
|
|
77
|
+
* // Format override
|
|
78
|
+
* const content2 = "Contract effective @today[long]";
|
|
79
|
+
* const result2 = processDateReferences(content2, {});
|
|
80
|
+
* // Output: "Contract effective January 15, 2024"
|
|
81
|
+
*
|
|
82
|
+
* // Using metadata settings
|
|
83
|
+
* const content3 = "Generated @today";
|
|
84
|
+
* const metadata = { 'date-format': 'legal', 'timezone': 'America/New_York' };
|
|
85
|
+
* const result3 = processDateReferences(content3, metadata);
|
|
86
|
+
* // Output: "Generated January 15th, 2024"
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function processDateReferences(content: string, metadata: Record<string, any>, options?: LegalMarkdownOptions): string;
|
|
90
|
+
//# sourceMappingURL=date-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-processor.d.ts","sourceRoot":"","sources":["../../../src/core/processors/date-processor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,oGAAoG;IACpG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,OAAO,GAAE,oBAAyB,GACjC,MAAM,CAeR"}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Date Processing Module for Legal Markdown Documents
|
|
4
|
+
*
|
|
5
|
+
* This module provides comprehensive date processing functionality for Legal Markdown
|
|
6
|
+
* documents, supporting the @today syntax with various formatting options. It handles
|
|
7
|
+
* different date formats, timezones, locales, and provides specialized formatting
|
|
8
|
+
* for legal documents including ordinal suffixes and custom format patterns.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - @today syntax for current date insertion
|
|
12
|
+
* - Format override support: @today[format]
|
|
13
|
+
* - Multiple predefined formats (ISO, US, European, legal, etc.)
|
|
14
|
+
* - Custom format pattern parsing (YYYY-MM-DD, etc.)
|
|
15
|
+
* - Timezone and locale support
|
|
16
|
+
* - Ordinal suffix generation for legal formats
|
|
17
|
+
* - Graceful error handling with fallback formatting
|
|
18
|
+
* - Integration with metadata for default settings
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { processDateReferences } from './date-processor';
|
|
23
|
+
*
|
|
24
|
+
* const content = `
|
|
25
|
+
* This document is dated @today.
|
|
26
|
+
* Contract effective date: @today[long]
|
|
27
|
+
* Expiration: @today[YYYY-MM-DD]
|
|
28
|
+
* Legal format: @today[legal]
|
|
29
|
+
* `;
|
|
30
|
+
*
|
|
31
|
+
* const metadata = {
|
|
32
|
+
* 'date-format': 'ISO',
|
|
33
|
+
* 'timezone': 'America/New_York',
|
|
34
|
+
* 'locale': 'en-US'
|
|
35
|
+
* };
|
|
36
|
+
*
|
|
37
|
+
* const processed = processDateReferences(content, metadata);
|
|
38
|
+
* console.log(processed);
|
|
39
|
+
* // Output:
|
|
40
|
+
* // This document is dated 2024-01-15.
|
|
41
|
+
* // Contract effective date: January 15, 2024
|
|
42
|
+
* // Expiration: 2024-01-15
|
|
43
|
+
* // Legal format: January 15th, 2024
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.processDateReferences = processDateReferences;
|
|
48
|
+
/**
|
|
49
|
+
* Processes special date references in legal documents
|
|
50
|
+
*
|
|
51
|
+
* This is the main function that processes @today references in Legal Markdown
|
|
52
|
+
* documents. It supports format overrides and uses metadata settings for
|
|
53
|
+
* default formatting, timezone, and locale preferences.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} content - The document content containing @today references
|
|
56
|
+
* @param {Record<string, any>} metadata - Document metadata with date formatting options
|
|
57
|
+
* @param {LegalMarkdownOptions} [options={}] - Additional processing options
|
|
58
|
+
* @returns {string} Processed content with @today references replaced by formatted dates
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // Basic usage with default format
|
|
62
|
+
* const content1 = "Document dated @today";
|
|
63
|
+
* const result1 = processDateReferences(content1, {});
|
|
64
|
+
* // Output: "Document dated 2024-01-15"
|
|
65
|
+
*
|
|
66
|
+
* // Format override
|
|
67
|
+
* const content2 = "Contract effective @today[long]";
|
|
68
|
+
* const result2 = processDateReferences(content2, {});
|
|
69
|
+
* // Output: "Contract effective January 15, 2024"
|
|
70
|
+
*
|
|
71
|
+
* // Using metadata settings
|
|
72
|
+
* const content3 = "Generated @today";
|
|
73
|
+
* const metadata = { 'date-format': 'legal', 'timezone': 'America/New_York' };
|
|
74
|
+
* const result3 = processDateReferences(content3, metadata);
|
|
75
|
+
* // Output: "Generated January 15th, 2024"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
function processDateReferences(content, metadata, options = {}) {
|
|
79
|
+
// Extract date format options from metadata
|
|
80
|
+
const dateOptions = extractDateOptions(metadata);
|
|
81
|
+
// Regular expression to match @today references
|
|
82
|
+
const todayPattern = /@today(?:\[([^\]]+)\])?/g;
|
|
83
|
+
return content.replace(todayPattern, (match, formatOverride) => {
|
|
84
|
+
// Use format override if provided, otherwise use metadata format, otherwise use default
|
|
85
|
+
const format = formatOverride || dateOptions.dateFormat || 'YYYY-MM-DD';
|
|
86
|
+
const timezone = dateOptions.timezone || 'UTC';
|
|
87
|
+
const locale = dateOptions.locale || 'en-US';
|
|
88
|
+
return formatDate(new Date(), format, timezone, locale);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Extracts date formatting options from metadata
|
|
93
|
+
*
|
|
94
|
+
* Parses document metadata to extract date formatting configuration,
|
|
95
|
+
* supporting both hyphenated and camelCase property names for flexibility.
|
|
96
|
+
*
|
|
97
|
+
* @private
|
|
98
|
+
* @param {Record<string, any>} metadata - Document metadata containing date options
|
|
99
|
+
* @returns {DateFormatOptions} Extracted date formatting options
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const metadata = {
|
|
103
|
+
* 'date-format': 'legal',
|
|
104
|
+
* 'timezone': 'America/New_York',
|
|
105
|
+
* 'locale': 'en-US'
|
|
106
|
+
* };
|
|
107
|
+
*
|
|
108
|
+
* const options = extractDateOptions(metadata);
|
|
109
|
+
* // Returns: { dateFormat: 'legal', timezone: 'America/New_York', locale: 'en-US' }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
function extractDateOptions(metadata) {
|
|
113
|
+
return {
|
|
114
|
+
dateFormat: metadata['date-format'] || metadata.dateFormat,
|
|
115
|
+
timezone: metadata['timezone'] || metadata.tz,
|
|
116
|
+
locale: metadata['locale'] || metadata.lang,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Formats a date according to the specified format, timezone, and locale
|
|
121
|
+
*
|
|
122
|
+
* Converts a Date object to a formatted string using various predefined formats
|
|
123
|
+
* or custom format patterns. Supports timezone conversion and locale-specific
|
|
124
|
+
* formatting with fallback to ISO format on errors.
|
|
125
|
+
*
|
|
126
|
+
* @private
|
|
127
|
+
* @param {Date} date - The date to format
|
|
128
|
+
* @param {string} format - Format specification (ISO, US, European, legal, long, etc.)
|
|
129
|
+
* @param {string} timezone - Timezone identifier (e.g., 'America/New_York')
|
|
130
|
+
* @param {string} locale - Locale identifier (e.g., 'en-US')
|
|
131
|
+
* @returns {string} Formatted date string
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const date = new Date('2024-01-15');
|
|
135
|
+
*
|
|
136
|
+
* console.log(formatDate(date, 'ISO', 'UTC', 'en-US')); // '2024-01-15'
|
|
137
|
+
* console.log(formatDate(date, 'US', 'UTC', 'en-US')); // '01/15/2024'
|
|
138
|
+
* console.log(formatDate(date, 'legal', 'UTC', 'en-US')); // 'January 15th, 2024'
|
|
139
|
+
* console.log(formatDate(date, 'YYYY-MM-DD', 'UTC', 'en-US')); // '2024-01-15'
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
function formatDate(date, format, timezone, locale) {
|
|
143
|
+
try {
|
|
144
|
+
// Create a new date in the specified timezone
|
|
145
|
+
const options = {
|
|
146
|
+
timeZone: timezone,
|
|
147
|
+
};
|
|
148
|
+
// Handle different format patterns
|
|
149
|
+
switch (format.toLowerCase()) {
|
|
150
|
+
case 'iso':
|
|
151
|
+
case 'yyyy-mm-dd':
|
|
152
|
+
options.year = 'numeric';
|
|
153
|
+
options.month = '2-digit';
|
|
154
|
+
options.day = '2-digit';
|
|
155
|
+
return new Intl.DateTimeFormat('en-CA', options).format(date);
|
|
156
|
+
case 'us':
|
|
157
|
+
case 'mm/dd/yyyy':
|
|
158
|
+
options.year = 'numeric';
|
|
159
|
+
options.month = '2-digit';
|
|
160
|
+
options.day = '2-digit';
|
|
161
|
+
return new Intl.DateTimeFormat('en-US', options).format(date);
|
|
162
|
+
case 'european':
|
|
163
|
+
case 'dd/mm/yyyy':
|
|
164
|
+
options.year = 'numeric';
|
|
165
|
+
options.month = '2-digit';
|
|
166
|
+
options.day = '2-digit';
|
|
167
|
+
return new Intl.DateTimeFormat('en-GB', options).format(date);
|
|
168
|
+
case 'long':
|
|
169
|
+
options.year = 'numeric';
|
|
170
|
+
options.month = 'long';
|
|
171
|
+
options.day = 'numeric';
|
|
172
|
+
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
173
|
+
case 'medium':
|
|
174
|
+
options.year = 'numeric';
|
|
175
|
+
options.month = 'short';
|
|
176
|
+
options.day = 'numeric';
|
|
177
|
+
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
178
|
+
case 'short':
|
|
179
|
+
options.year = '2-digit';
|
|
180
|
+
options.month = 'short';
|
|
181
|
+
options.day = 'numeric';
|
|
182
|
+
return new Intl.DateTimeFormat(locale, options).format(date);
|
|
183
|
+
case 'legal': {
|
|
184
|
+
// Legal format: "January 1st, 2024"
|
|
185
|
+
options.year = 'numeric';
|
|
186
|
+
options.month = 'long';
|
|
187
|
+
options.day = 'numeric';
|
|
188
|
+
const formatted = new Intl.DateTimeFormat(locale, options).format(date);
|
|
189
|
+
return addOrdinalSuffix(formatted, date.getDate());
|
|
190
|
+
}
|
|
191
|
+
default:
|
|
192
|
+
// Try to parse custom format patterns
|
|
193
|
+
try {
|
|
194
|
+
return parseCustomFormat(date, format, timezone, locale);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
// If custom format parsing fails, fallback to ISO
|
|
198
|
+
return date.toISOString().split('T')[0];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
// Fallback to ISO format if there's an error
|
|
204
|
+
return date.toISOString().split('T')[0];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Adds ordinal suffix to legal format (1st, 2nd, 3rd, etc.)
|
|
209
|
+
*
|
|
210
|
+
* Modifies a formatted date string to include ordinal suffixes for the day,
|
|
211
|
+
* used specifically in legal document formatting.
|
|
212
|
+
*
|
|
213
|
+
* @private
|
|
214
|
+
* @param {string} formatted - The formatted date string
|
|
215
|
+
* @param {number} day - The day number to add ordinal suffix to
|
|
216
|
+
* @returns {string} Date string with ordinal suffix
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const formatted = addOrdinalSuffix('January 1, 2024', 1);
|
|
220
|
+
* // Returns: 'January 1st, 2024'
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
function addOrdinalSuffix(formatted, day) {
|
|
224
|
+
const suffix = getOrdinalSuffix(day);
|
|
225
|
+
return formatted.replace(/\b\d+\b/, `${day}${suffix}`);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Gets ordinal suffix for a number
|
|
229
|
+
*
|
|
230
|
+
* Determines the appropriate ordinal suffix (st, nd, rd, th) for a given number
|
|
231
|
+
* following English ordinal number rules.
|
|
232
|
+
*
|
|
233
|
+
* @private
|
|
234
|
+
* @param {number} num - The number to get ordinal suffix for
|
|
235
|
+
* @returns {string} The ordinal suffix (st, nd, rd, or th)
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* console.log(getOrdinalSuffix(1)); // 'st'
|
|
239
|
+
* console.log(getOrdinalSuffix(2)); // 'nd'
|
|
240
|
+
* console.log(getOrdinalSuffix(3)); // 'rd'
|
|
241
|
+
* console.log(getOrdinalSuffix(4)); // 'th'
|
|
242
|
+
* console.log(getOrdinalSuffix(11)); // 'th'
|
|
243
|
+
* console.log(getOrdinalSuffix(21)); // 'st'
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
function getOrdinalSuffix(num) {
|
|
247
|
+
const lastDigit = num % 10;
|
|
248
|
+
const lastTwoDigits = num % 100;
|
|
249
|
+
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
|
|
250
|
+
return 'th';
|
|
251
|
+
}
|
|
252
|
+
switch (lastDigit) {
|
|
253
|
+
case 1:
|
|
254
|
+
return 'st';
|
|
255
|
+
case 2:
|
|
256
|
+
return 'nd';
|
|
257
|
+
case 3:
|
|
258
|
+
return 'rd';
|
|
259
|
+
default:
|
|
260
|
+
return 'th';
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Parses custom date format patterns
|
|
265
|
+
*
|
|
266
|
+
* Processes custom date format strings using token replacement patterns.
|
|
267
|
+
* Supports various tokens like YYYY, MM, DD, etc., and throws an error
|
|
268
|
+
* for invalid or unrecognized format patterns.
|
|
269
|
+
*
|
|
270
|
+
* @private
|
|
271
|
+
* @param {Date} date - The date to format
|
|
272
|
+
* @param {string} format - Custom format pattern string
|
|
273
|
+
* @param {string} timezone - Timezone identifier
|
|
274
|
+
* @param {string} locale - Locale identifier
|
|
275
|
+
* @returns {string} Formatted date string
|
|
276
|
+
* @throws {Error} When format pattern is invalid or contains unrecognized tokens
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const date = new Date('2024-01-15');
|
|
280
|
+
*
|
|
281
|
+
* console.log(parseCustomFormat(date, 'YYYY-MM-DD', 'UTC', 'en-US')); // '2024-01-15'
|
|
282
|
+
* console.log(parseCustomFormat(date, 'DD/MM/YYYY', 'UTC', 'en-US')); // '15/01/2024'
|
|
283
|
+
* console.log(parseCustomFormat(date, 'MMMM D, YYYY', 'UTC', 'en-US')); // 'January 15, 2024'
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
function parseCustomFormat(date, format, timezone, locale) {
|
|
287
|
+
const options = {
|
|
288
|
+
timeZone: timezone,
|
|
289
|
+
};
|
|
290
|
+
// Define token patterns and their formatters
|
|
291
|
+
const tokenPatterns = [
|
|
292
|
+
{
|
|
293
|
+
pattern: /YYYY/g,
|
|
294
|
+
formatter: () => new Intl.DateTimeFormat(locale, { ...options, year: 'numeric' }).format(date),
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
pattern: /YY/g,
|
|
298
|
+
formatter: () => new Intl.DateTimeFormat(locale, { ...options, year: '2-digit' }).format(date),
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
pattern: /MMMM/g,
|
|
302
|
+
formatter: () => new Intl.DateTimeFormat(locale, { ...options, month: 'long' }).format(date),
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
pattern: /MMM/g,
|
|
306
|
+
formatter: () => new Intl.DateTimeFormat(locale, { ...options, month: 'short' }).format(date),
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
pattern: /MM/g,
|
|
310
|
+
formatter: () => new Intl.DateTimeFormat(locale, { ...options, month: '2-digit' }).format(date),
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
pattern: /\bM\b/g,
|
|
314
|
+
formatter: () => new Intl.DateTimeFormat(locale, { ...options, month: 'numeric' }).format(date),
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
pattern: /DD/g,
|
|
318
|
+
formatter: () => new Intl.DateTimeFormat(locale, { ...options, day: '2-digit' }).format(date),
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
pattern: /\bD\b/g,
|
|
322
|
+
formatter: () => new Intl.DateTimeFormat(locale, { ...options, day: 'numeric' }).format(date),
|
|
323
|
+
},
|
|
324
|
+
];
|
|
325
|
+
// Apply token replacements
|
|
326
|
+
let result = format;
|
|
327
|
+
for (const { pattern, formatter } of tokenPatterns) {
|
|
328
|
+
result = result.replace(pattern, formatter());
|
|
329
|
+
}
|
|
330
|
+
// If result still contains unreplaced tokens of our pattern, it's an invalid format
|
|
331
|
+
if (result.match(/\b[YMDH]+\b/) || result === format) {
|
|
332
|
+
throw new Error('Invalid format pattern');
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=date-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-processor.js","sourceRoot":"","sources":["../../../src/core/processors/date-processor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;;AAgDH,sDAmBC;AAjDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAgB,qBAAqB,CACnC,OAAe,EACf,QAA6B,EAC7B,UAAgC,EAAE;IAElC,4CAA4C;IAC5C,MAAM,WAAW,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAEjD,gDAAgD;IAChD,MAAM,YAAY,GAAG,0BAA0B,CAAC;IAEhD,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,EA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MAAM,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Header Processing Module for Legal Markdown Documents
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive header processing functionality for Legal Markdown
|
|
5
|
+
* documents, supporting both traditional (l., ll., lll.) and alternative (lfunction extractHeaderOptions(
|
|
6
|
+
metadata: Record<string, any>,
|
|
7
|
+
processingOptions: {
|
|
8
|
+
noReset?: boolean;
|
|
9
|
+
noIndent?: boolean;
|
|
10
|
+
enableFieldTracking?: boolean;
|
|
11
|
+
}
|
|
12
|
+
): HeaderOptions {l2., l3.)
|
|
13
|
+
* header syntax. It handles complex numbering schemes, hierarchical structures, and
|
|
14
|
+
* various formatting options including Roman numerals, alphabetic labels, and custom
|
|
15
|
+
* indentation patterns.
|
|
16
|
+
*
|
|
17
|
+
* Features:
|
|
18
|
+
* - Dual header syntax support (traditional and alternative)
|
|
19
|
+
* - Complex hierarchical numbering with automatic level management
|
|
20
|
+
* - Roman numeral and alphabetic label generation
|
|
21
|
+
* - Customizable header formatting templates
|
|
22
|
+
* - Academic and legal document formatting patterns
|
|
23
|
+
* - Automatic indentation and spacing control
|
|
24
|
+
* - Continuous numbering and reset control options
|
|
25
|
+
* - Level-specific formatting with placeholder substitution
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { processHeaders } from './header-processor';
|
|
30
|
+
*
|
|
31
|
+
* const content = `l. Introduction
|
|
32
|
+
* ll. Terms and Conditions
|
|
33
|
+
* lll. Payment Terms
|
|
34
|
+
* l2. Liability`;
|
|
35
|
+
*
|
|
36
|
+
* const metadata = {
|
|
37
|
+
* 'level-one': 'Article %n.',
|
|
38
|
+
* 'level-two': 'Section %n.',
|
|
39
|
+
* 'level-three': '(%n)'
|
|
40
|
+
* };
|
|
41
|
+
*
|
|
42
|
+
* const processed = processHeaders(content, metadata);
|
|
43
|
+
* console.log(processed);
|
|
44
|
+
* // Output:
|
|
45
|
+
* // Article 1. Introduction
|
|
46
|
+
* // Section 1. Terms and Conditions
|
|
47
|
+
* // (1) Payment Terms
|
|
48
|
+
* // Section 2. Liability
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* Processes structured headers in a LegalMarkdown document
|
|
53
|
+
*
|
|
54
|
+
* This is the main function that processes both traditional (l., ll., lll.) and
|
|
55
|
+
* alternative (l1., l2., l3.) header syntax. It maintains proper hierarchical
|
|
56
|
+
* numbering, applies custom formatting templates, and handles complex academic
|
|
57
|
+
* and legal document structures.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} content - The document content containing headers to process
|
|
60
|
+
* @param {Record<string, any>} metadata - Document metadata with potential header formatting options
|
|
61
|
+
* @param {Object} [processingOptions={}] - Additional processing options
|
|
62
|
+
* @param {boolean} [processingOptions.noReset] - Disable header numbering reset (continuous numbering)
|
|
63
|
+
* @param {boolean} [processingOptions.noIndent] - Disable header indentation (flat formatting)
|
|
64
|
+
* @returns {string} Processed content with formatted headers
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* // Basic header processing
|
|
68
|
+
* const content = `l. First Article
|
|
69
|
+
* ll. First Section
|
|
70
|
+
* lll. Subsection A
|
|
71
|
+
* ll. Second Section
|
|
72
|
+
* l. Second Article`;
|
|
73
|
+
*
|
|
74
|
+
* const metadata = {
|
|
75
|
+
* 'level-one': 'Article %n.',
|
|
76
|
+
* 'level-two': 'Section %n.',
|
|
77
|
+
* 'level-three': '(%c)'
|
|
78
|
+
* };
|
|
79
|
+
*
|
|
80
|
+
* const result = processHeaders(content, metadata);
|
|
81
|
+
* // Output:
|
|
82
|
+
* // Article 1. First Article
|
|
83
|
+
* // Section 1. First Section
|
|
84
|
+
* // (a) Subsection A
|
|
85
|
+
* // Section 2. Second Section
|
|
86
|
+
* // Article 2. Second Article
|
|
87
|
+
*
|
|
88
|
+
* // Alternative syntax
|
|
89
|
+
* const altContent = `l1. Introduction
|
|
90
|
+
* l2. Background
|
|
91
|
+
* l3. Technical Details
|
|
92
|
+
* l2. Implementation
|
|
93
|
+
* l1. Conclusion`;
|
|
94
|
+
*
|
|
95
|
+
* const altResult = processHeaders(altContent, metadata);
|
|
96
|
+
* // Produces similar hierarchical numbering
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function processHeaders(content: string, metadata: Record<string, any>, processingOptions?: {
|
|
100
|
+
noReset?: boolean;
|
|
101
|
+
noIndent?: boolean;
|
|
102
|
+
enableFieldTracking?: boolean;
|
|
103
|
+
}): string;
|
|
104
|
+
//# sourceMappingURL=header-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header-processor.d.ts","sourceRoot":"","sources":["../../../src/core/processors/header-processor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,iBAAiB,GAAE;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC1B,GACL,MAAM,CAsGR"}
|