nx-md-parser 1.0.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/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +32 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/markdown-transformer.d.ts +105 -0
- package/dist/src/lib/markdown-transformer.d.ts.map +1 -0
- package/dist/src/lib/markdown-transformer.js +455 -0
- package/dist/src/lib/markdown-transformer.js.map +1 -0
- package/docs/QUICKSTART.md +197 -0
- package/docs/README.md +366 -0
- package/docs/SUMMARY.md +270 -0
- package/examples/integration-example.ts +531 -0
- package/examples/markdown-example.ts +221 -0
- package/package.json +55 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Usage: Markdown to JSON Transformer
|
|
3
|
+
*
|
|
4
|
+
* Shows how to parse markdown text and transform it to a desired JSON schema
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { JSONTransformer, Schema, MarkdownParser } from '../src';
|
|
8
|
+
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Example 1: Your Exact Use Case
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
const markdownInput = `### Short Answer
|
|
14
|
+
The asset is a server named server1 with private IP 192.168.1.1. Next steps include documenting it in the CMDB, identifying its OS/role, and performing baseline security and inventory checks.
|
|
15
|
+
|
|
16
|
+
### Full Answer
|
|
17
|
+
The input specifies a single asset with the following attributes: assetType = server, assetName = server1, assetIp = 192.168.1.1. The IP address falls within a private RFC1918 range, indicating it is intended for internal network use rather than public exposure. To manage this asset effectively, consider the following actions:
|
|
18
|
+
|
|
19
|
+
- Inventory and ownership: Add server1 to your configuration management database (CMDB) or asset registry with fields for owner, location (rack or data center, if physical), environment (prod, staging, dev), and asset lifecycle data (purchase date, warranty, maintenance contracts).
|
|
20
|
+
- Determine the server's role and baseline: Clarify the operating system, version, installed applications, and the primary function (e.g., web server, application server, database). Establish a baseline configuration and security policies (patching cadence, anti-malware, configuration hardening).
|
|
21
|
+
- Security and compliance checks: Verify that appropriate access controls exist (least privilege, SSH/RDP hardening, multi-factor authentication where applicable), and ensure network segmentation and firewall rules restrict external access. Plan vulnerability management and regular scans, plus backup and recovery testing.
|
|
22
|
+
- Monitoring and maintenance: Ensure logging, monitoring (performance, security events), and alerting are in place. Confirm backup status and disaster recovery procedures, including recovery objectives and RPO/RTO.
|
|
23
|
+
- Information gaps to fill: Owner contact, exact OS and version, hardware vs. VM status, network topology (subnet, gateway, DNS), exposed services/ports, and current patch level.
|
|
24
|
+
|
|
25
|
+
If you want, I can draft a concrete onboarding checklist or a template CMDB entry for server1 based on your environment.
|
|
26
|
+
|
|
27
|
+
### Assumptions
|
|
28
|
+
- The asset is intended to be tracked in an internal asset management system (CMDB/CMR).
|
|
29
|
+
- The IP 192.168.1.1 is an internal address and not publicly routable.
|
|
30
|
+
|
|
31
|
+
### Unknowns
|
|
32
|
+
- Operating system and version running on server1.
|
|
33
|
+
- Physical vs. virtual server status and its exact location/topology.
|
|
34
|
+
|
|
35
|
+
### Evidence
|
|
36
|
+
1. Asset details provided: assetType = "server", assetName = "server1", assetIp = "192.168.1.1".
|
|
37
|
+
2. The IP address 192.168.1.1 is within the private address space (RFC1918).`;
|
|
38
|
+
|
|
39
|
+
// Define the desired JSON schema
|
|
40
|
+
const desiredSchema = Schema.object({
|
|
41
|
+
shortAnswer: Schema.string(),
|
|
42
|
+
fullAnswer: Schema.string(),
|
|
43
|
+
assumptions: Schema.array(Schema.string()),
|
|
44
|
+
unknowns: Schema.array(Schema.string()),
|
|
45
|
+
evidence: Schema.array(Schema.string()),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Transform markdown to JSON
|
|
49
|
+
const transformer = new JSONTransformer(desiredSchema);
|
|
50
|
+
const result = transformer.transformMarkdown(markdownInput);
|
|
51
|
+
|
|
52
|
+
console.log('='.repeat(70));
|
|
53
|
+
console.log('EXAMPLE 1: Markdown to Structured JSON');
|
|
54
|
+
console.log('='.repeat(70));
|
|
55
|
+
console.log('\nStatus:', result.status);
|
|
56
|
+
console.log('\nResult:');
|
|
57
|
+
console.log(JSON.stringify(result.result, null, 2));
|
|
58
|
+
|
|
59
|
+
if (result.fixes) {
|
|
60
|
+
console.log('\nFixes applied:');
|
|
61
|
+
result.fixes.forEach(fix => console.log(` - ${fix}`));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ============================================================================
|
|
65
|
+
// Example 2: Nested Schema with Asset Details
|
|
66
|
+
// ============================================================================
|
|
67
|
+
|
|
68
|
+
const assetSchema = Schema.object({
|
|
69
|
+
asset: Schema.object({
|
|
70
|
+
type: Schema.string(),
|
|
71
|
+
name: Schema.string(),
|
|
72
|
+
ip: Schema.string(),
|
|
73
|
+
}),
|
|
74
|
+
analysis: Schema.object({
|
|
75
|
+
shortAnswer: Schema.string(),
|
|
76
|
+
fullAnswer: Schema.string(),
|
|
77
|
+
}),
|
|
78
|
+
metadata: Schema.object({
|
|
79
|
+
assumptions: Schema.array(Schema.string()),
|
|
80
|
+
unknowns: Schema.array(Schema.string()),
|
|
81
|
+
evidence: Schema.array(Schema.string()),
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const transformer2 = new JSONTransformer(assetSchema);
|
|
86
|
+
const result2 = transformer2.transformMarkdown(markdownInput);
|
|
87
|
+
|
|
88
|
+
console.log('\n' + '='.repeat(70));
|
|
89
|
+
console.log('EXAMPLE 2: Nested Schema Structure');
|
|
90
|
+
console.log('='.repeat(70));
|
|
91
|
+
console.log('\nStatus:', result2.status);
|
|
92
|
+
console.log('\nResult:');
|
|
93
|
+
console.log(JSON.stringify(result2.result, null, 2));
|
|
94
|
+
|
|
95
|
+
// ============================================================================
|
|
96
|
+
// Example 3: Simple Markdown Sections
|
|
97
|
+
// ============================================================================
|
|
98
|
+
|
|
99
|
+
const simpleMarkdown = `### Title
|
|
100
|
+
My Project Documentation
|
|
101
|
+
|
|
102
|
+
### Description
|
|
103
|
+
This is a detailed description of the project with multiple lines.
|
|
104
|
+
It includes various features and capabilities.
|
|
105
|
+
|
|
106
|
+
### Tags
|
|
107
|
+
- TypeScript
|
|
108
|
+
- Node.js
|
|
109
|
+
- Nx
|
|
110
|
+
|
|
111
|
+
### Status
|
|
112
|
+
Active`;
|
|
113
|
+
|
|
114
|
+
const simpleSchema = Schema.object({
|
|
115
|
+
title: Schema.string(),
|
|
116
|
+
description: Schema.string(),
|
|
117
|
+
tags: Schema.array(Schema.string()),
|
|
118
|
+
status: Schema.string(),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const transformer3 = new JSONTransformer(simpleSchema);
|
|
122
|
+
const result3 = transformer3.transformMarkdown(simpleMarkdown);
|
|
123
|
+
|
|
124
|
+
console.log('\n' + '='.repeat(70));
|
|
125
|
+
console.log('EXAMPLE 3: Simple Markdown Sections');
|
|
126
|
+
console.log('='.repeat(70));
|
|
127
|
+
console.log('\nMarkdown Input:');
|
|
128
|
+
console.log(simpleMarkdown);
|
|
129
|
+
console.log('\nStatus:', result3.status);
|
|
130
|
+
console.log('\nResult:');
|
|
131
|
+
console.log(JSON.stringify(result3.result, null, 2));
|
|
132
|
+
|
|
133
|
+
// ============================================================================
|
|
134
|
+
// Example 4: Using MarkdownParser Directly
|
|
135
|
+
// ============================================================================
|
|
136
|
+
|
|
137
|
+
const sections = MarkdownParser.parseSections(markdownInput);
|
|
138
|
+
|
|
139
|
+
console.log('\n' + '='.repeat(70));
|
|
140
|
+
console.log('EXAMPLE 4: Direct Markdown Parsing');
|
|
141
|
+
console.log('='.repeat(70));
|
|
142
|
+
console.log('\nParsed Sections:');
|
|
143
|
+
sections.forEach((section, i) => {
|
|
144
|
+
console.log(`\n${i + 1}. ${section.heading} (Level ${section.level})`);
|
|
145
|
+
console.log(` Content preview: ${section.content.substring(0, 80)}...`);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const parsed = MarkdownParser.sectionsToObject(sections);
|
|
149
|
+
console.log('\nParsed Object:');
|
|
150
|
+
console.log(JSON.stringify(parsed, null, 2));
|
|
151
|
+
|
|
152
|
+
// ============================================================================
|
|
153
|
+
// Example 5: Flexible Schema Matching
|
|
154
|
+
// ============================================================================
|
|
155
|
+
|
|
156
|
+
const flexibleMarkdown = `### Short Ans
|
|
157
|
+
Quick summary here
|
|
158
|
+
|
|
159
|
+
### Full Ans
|
|
160
|
+
Detailed explanation
|
|
161
|
+
|
|
162
|
+
### Assumtions
|
|
163
|
+
- First assumption
|
|
164
|
+
- Second assumption`;
|
|
165
|
+
|
|
166
|
+
const flexibleSchema = Schema.object({
|
|
167
|
+
shortAnswer: Schema.string(),
|
|
168
|
+
fullAnswer: Schema.string(),
|
|
169
|
+
assumptions: Schema.array(Schema.string()),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const transformer5 = new JSONTransformer(flexibleSchema, 0.6); // Lower threshold for more fuzzy matching
|
|
173
|
+
const result5 = transformer5.transformMarkdown(flexibleMarkdown);
|
|
174
|
+
|
|
175
|
+
console.log('\n' + '='.repeat(70));
|
|
176
|
+
console.log('EXAMPLE 5: Fuzzy Matching (Typos in Markdown)');
|
|
177
|
+
console.log('='.repeat(70));
|
|
178
|
+
console.log('\nMarkdown has typos: "Short Ans", "Full Ans", "Assumtions"');
|
|
179
|
+
console.log('\nStatus:', result5.status);
|
|
180
|
+
console.log('\nResult:');
|
|
181
|
+
console.log(JSON.stringify(result5.result, null, 2));
|
|
182
|
+
if (result5.fixes) {
|
|
183
|
+
console.log('\nFixes applied:');
|
|
184
|
+
result5.fixes.forEach(fix => console.log(` - ${fix}`));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ============================================================================
|
|
188
|
+
// Quick Usage Guide
|
|
189
|
+
// ============================================================================
|
|
190
|
+
|
|
191
|
+
console.log('\n' + '='.repeat(70));
|
|
192
|
+
console.log('QUICK USAGE GUIDE');
|
|
193
|
+
console.log('='.repeat(70));
|
|
194
|
+
console.log(`
|
|
195
|
+
import { JSONTransformer, Schema } from './markdown-transformer';
|
|
196
|
+
|
|
197
|
+
// 1. Define your desired JSON schema
|
|
198
|
+
const schema = Schema.object({
|
|
199
|
+
title: Schema.string(),
|
|
200
|
+
items: Schema.array(Schema.string()),
|
|
201
|
+
metadata: Schema.object({
|
|
202
|
+
author: Schema.string(),
|
|
203
|
+
date: Schema.string(),
|
|
204
|
+
}),
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// 2. Create transformer
|
|
208
|
+
const transformer = new JSONTransformer(schema);
|
|
209
|
+
|
|
210
|
+
// 3. Transform markdown to JSON
|
|
211
|
+
const result = transformer.transformMarkdown(yourMarkdownText);
|
|
212
|
+
|
|
213
|
+
// 4. Use the result
|
|
214
|
+
console.log(result.status); // 'validated' | 'fixed' | 'failed'
|
|
215
|
+
console.log(result.result); // Your JSON object
|
|
216
|
+
console.log(result.fixes); // Array of fixes applied (if any)
|
|
217
|
+
console.log(result.errors); // Array of errors (if failed)
|
|
218
|
+
|
|
219
|
+
// Also works with plain objects:
|
|
220
|
+
const objResult = transformer.transform({ title: "Test" });
|
|
221
|
+
`);
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nx-md-parser",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Nx Markdown Parser - Transform markdown to JSON with schema validation and auto-fixing",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/src",
|
|
9
|
+
"docs",
|
|
10
|
+
"examples",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"example": "ts-node examples/markdown-example.ts",
|
|
18
|
+
"integration-example": "ts-node examples/integration-example.ts",
|
|
19
|
+
"test": "jest",
|
|
20
|
+
"test:watch": "jest --watch",
|
|
21
|
+
"prepublishOnly": "npm run build && npm test"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"markdown",
|
|
25
|
+
"json",
|
|
26
|
+
"transformer",
|
|
27
|
+
"schema",
|
|
28
|
+
"validation",
|
|
29
|
+
"parser"
|
|
30
|
+
],
|
|
31
|
+
"author": "nx-md-parser contributors",
|
|
32
|
+
"license": "ISC",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/your-org/nx-md-parser"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/your-org/nx-md-parser#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/your-org/nx-md-parser/issues"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=14.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"nx-helpers": "^1.2.7"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/jest": "^29.0.0",
|
|
49
|
+
"@types/node": "^20.0.0",
|
|
50
|
+
"jest": "^29.0.0",
|
|
51
|
+
"ts-jest": "^29.0.0",
|
|
52
|
+
"ts-node": "^10.9.0",
|
|
53
|
+
"typescript": "^5.3.0"
|
|
54
|
+
}
|
|
55
|
+
}
|