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
package/docs/SUMMARY.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Markdown to JSON Transformer - Complete TypeScript Solution
|
|
2
|
+
|
|
3
|
+
## ๐ฆ What You Got
|
|
4
|
+
|
|
5
|
+
A complete, production-ready TypeScript library that:
|
|
6
|
+
|
|
7
|
+
โ
Parses markdown text into structured JSON
|
|
8
|
+
โ
Validates against a desired schema
|
|
9
|
+
โ
Auto-fixes typos, case mismatches, and type errors
|
|
10
|
+
โ
Integrates seamlessly with nx-helpers
|
|
11
|
+
โ
Handles nested objects of unlimited depth
|
|
12
|
+
โ
Includes comprehensive tests and examples
|
|
13
|
+
|
|
14
|
+
## ๐ Files Overview
|
|
15
|
+
|
|
16
|
+
| File | Purpose |
|
|
17
|
+
|------|---------|
|
|
18
|
+
| `markdown-transformer.ts` | Main library - all transformation logic |
|
|
19
|
+
| `markdown-example.ts` | Examples including your exact use case |
|
|
20
|
+
| `integration-example.ts` | Real-world integration patterns |
|
|
21
|
+
| `markdown-transformer.test.ts` | Comprehensive test suite |
|
|
22
|
+
| `package.json` | NPM dependencies and scripts |
|
|
23
|
+
| `tsconfig.json` | TypeScript configuration |
|
|
24
|
+
| `jest.config.js` | Test configuration |
|
|
25
|
+
| `README.md` | Full documentation |
|
|
26
|
+
| `QUICKSTART.md` | Quick start with your example |
|
|
27
|
+
|
|
28
|
+
## ๐ Quick Setup
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# 1. Install dependencies
|
|
32
|
+
npm install
|
|
33
|
+
|
|
34
|
+
# 2. Run examples (see your exact use case)
|
|
35
|
+
npm run example
|
|
36
|
+
|
|
37
|
+
# 3. Run tests
|
|
38
|
+
npm test
|
|
39
|
+
|
|
40
|
+
# 4. Build
|
|
41
|
+
npm run build
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## ๐ก Your Exact Use Case - Working Solution
|
|
45
|
+
|
|
46
|
+
### Input (Markdown)
|
|
47
|
+
```markdown
|
|
48
|
+
### Short Answer
|
|
49
|
+
The asset is a server named server1 with private IP 192.168.1.1...
|
|
50
|
+
|
|
51
|
+
### Full Answer
|
|
52
|
+
The input specifies a single asset...
|
|
53
|
+
|
|
54
|
+
### Assumptions
|
|
55
|
+
- The asset is intended to be tracked...
|
|
56
|
+
- The IP 192.168.1.1 is an internal address...
|
|
57
|
+
|
|
58
|
+
### Evidence
|
|
59
|
+
1. Asset details provided: assetType = "server"...
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Code
|
|
63
|
+
```typescript
|
|
64
|
+
import { JSONTransformer, Schema } from './markdown-transformer';
|
|
65
|
+
|
|
66
|
+
const schema = Schema.object({
|
|
67
|
+
shortAnswer: Schema.string(),
|
|
68
|
+
fullAnswer: Schema.string(),
|
|
69
|
+
assumptions: Schema.array(Schema.string()),
|
|
70
|
+
unknowns: Schema.array(Schema.string()),
|
|
71
|
+
evidence: Schema.array(Schema.string()),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const transformer = new JSONTransformer(schema);
|
|
75
|
+
const result = transformer.transformMarkdown(yourMarkdown);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Output
|
|
79
|
+
```typescript
|
|
80
|
+
{
|
|
81
|
+
status: "fixed", // or "validated" or "failed"
|
|
82
|
+
result: {
|
|
83
|
+
shortAnswer: "The asset is a server...",
|
|
84
|
+
fullAnswer: "The input specifies...",
|
|
85
|
+
assumptions: ["The asset is intended...", "The IP is internal..."],
|
|
86
|
+
unknowns: ["Operating system...", "Physical vs virtual..."],
|
|
87
|
+
evidence: ["Asset details provided...", "The IP address is..."]
|
|
88
|
+
},
|
|
89
|
+
fixes: ["root: Mapped key 'evidence' -> 'evidence'", ...]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## ๐ฏ Key Features Demonstrated
|
|
94
|
+
|
|
95
|
+
### 1. Schema Definition (TypeScript-native)
|
|
96
|
+
```typescript
|
|
97
|
+
const schema = Schema.object({
|
|
98
|
+
user: Schema.object({
|
|
99
|
+
name: Schema.string(),
|
|
100
|
+
age: Schema.number(),
|
|
101
|
+
tags: Schema.array(Schema.string())
|
|
102
|
+
})
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 2. Markdown Parsing
|
|
107
|
+
- **Sections** โ Object properties (camelCased)
|
|
108
|
+
- **Lists** (`- item`) โ Arrays
|
|
109
|
+
- **Numbered lists** (`1. item`) โ Arrays
|
|
110
|
+
- **Key-value pairs** (`key: value`) โ Nested objects
|
|
111
|
+
- **Plain text** โ Strings
|
|
112
|
+
|
|
113
|
+
### 3. Smart Auto-Fixing
|
|
114
|
+
```typescript
|
|
115
|
+
// Input with errors
|
|
116
|
+
{
|
|
117
|
+
"usr": { // Typo
|
|
118
|
+
"age": "25", // Wrong type
|
|
119
|
+
"Active": "yes" // Wrong case + wrong type
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Automatically fixed to match schema
|
|
124
|
+
{
|
|
125
|
+
"user": {
|
|
126
|
+
"age": 25,
|
|
127
|
+
"active": true
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 4. nx-helpers Integration
|
|
133
|
+
```typescript
|
|
134
|
+
import { mergeNoRedundancy } from 'nx-helpers';
|
|
135
|
+
|
|
136
|
+
const merged = mergeNoRedundancy(baseConfig, newConfig);
|
|
137
|
+
// - Arrays: merged as UNION (deduplicated)
|
|
138
|
+
// - Objects: deep-merged recursively
|
|
139
|
+
// - Primitives: newConfig wins
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## ๐ง Advanced Usage Patterns
|
|
143
|
+
|
|
144
|
+
### Pattern 1: Multi-Source Data Aggregation
|
|
145
|
+
```typescript
|
|
146
|
+
// Aggregate from multiple markdown files
|
|
147
|
+
const data = aggregateProjectData({
|
|
148
|
+
requirements: requirementsMd,
|
|
149
|
+
risks: risksMd,
|
|
150
|
+
metadata: metadataMd
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Pattern 2: Incremental Updates
|
|
155
|
+
```typescript
|
|
156
|
+
// Merge new markdown data into existing config
|
|
157
|
+
const updated = incrementalConfigUpdate(
|
|
158
|
+
currentConfig,
|
|
159
|
+
updateMarkdown,
|
|
160
|
+
schema
|
|
161
|
+
);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Pattern 3: Validation Pipeline
|
|
165
|
+
```typescript
|
|
166
|
+
const result = validateAndTransform(markdown, schema, {
|
|
167
|
+
requireValidation: true, // Only accept perfect matches
|
|
168
|
+
logFixes: true // Log all transformations
|
|
169
|
+
});
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## ๐ What Gets Fixed Automatically
|
|
173
|
+
|
|
174
|
+
| Input Error | Auto-Fix |
|
|
175
|
+
|-------------|----------|
|
|
176
|
+
| `"cats"` (typo) | `"cat"` (fuzzy match) |
|
|
177
|
+
| `"Color"` (wrong case) | `"color"` |
|
|
178
|
+
| `"25"` (string) | `25` (number) |
|
|
179
|
+
| `"true"` (string) | `true` (boolean) |
|
|
180
|
+
| Flat object | Nested structure |
|
|
181
|
+
| Missing field | Default value |
|
|
182
|
+
| Single value | Wrapped in array |
|
|
183
|
+
|
|
184
|
+
## ๐งช Testing
|
|
185
|
+
|
|
186
|
+
Comprehensive test suite included:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
npm test
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Coverage includes:
|
|
193
|
+
- โ
Markdown parsing (sections, lists, content)
|
|
194
|
+
- โ
Type conversions (string/number/boolean)
|
|
195
|
+
- โ
Fuzzy matching (typos, case)
|
|
196
|
+
- โ
Nested transformations
|
|
197
|
+
- โ
Array handling
|
|
198
|
+
- โ
Missing properties
|
|
199
|
+
- โ
Full markdown-to-JSON pipeline
|
|
200
|
+
|
|
201
|
+
## ๐ Documentation
|
|
202
|
+
|
|
203
|
+
- **README.md**: Complete API reference and features
|
|
204
|
+
- **QUICKSTART.md**: Get started with your exact use case
|
|
205
|
+
- **markdown-example.ts**: 5 comprehensive examples
|
|
206
|
+
- **integration-example.ts**: Real-world patterns
|
|
207
|
+
- Inline TypeScript documentation for IDE support
|
|
208
|
+
|
|
209
|
+
## ๐ Learning Path
|
|
210
|
+
|
|
211
|
+
1. **Start here**: `QUICKSTART.md` - Your exact example
|
|
212
|
+
2. **See more examples**: `markdown-example.ts`
|
|
213
|
+
3. **Learn patterns**: `integration-example.ts`
|
|
214
|
+
4. **Deep dive**: `README.md`
|
|
215
|
+
5. **Understand internals**: `markdown-transformer.ts`
|
|
216
|
+
|
|
217
|
+
## ๐ Dependencies
|
|
218
|
+
|
|
219
|
+
Only one dependency:
|
|
220
|
+
- `nx-helpers`: For intelligent object merging
|
|
221
|
+
|
|
222
|
+
All other functionality is self-contained.
|
|
223
|
+
|
|
224
|
+
## โก Performance
|
|
225
|
+
|
|
226
|
+
- Lightweight: ~500 lines of TypeScript
|
|
227
|
+
- No heavy dependencies
|
|
228
|
+
- Efficient fuzzy matching (Levenshtein distance)
|
|
229
|
+
- Suitable for high-throughput pipelines
|
|
230
|
+
|
|
231
|
+
## ๐จ Customization
|
|
232
|
+
|
|
233
|
+
Easily customizable:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
// Adjust fuzzy matching sensitivity
|
|
237
|
+
new JSONTransformer(schema, 0.6); // More permissive
|
|
238
|
+
|
|
239
|
+
// Add custom type conversions
|
|
240
|
+
// Extend SchemaType with your own types
|
|
241
|
+
|
|
242
|
+
// Custom parsers
|
|
243
|
+
MarkdownParser.parseContent() // Override this
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## ๐ License
|
|
247
|
+
|
|
248
|
+
ISC
|
|
249
|
+
|
|
250
|
+
## ๐ค Contributing
|
|
251
|
+
|
|
252
|
+
The code is fully typed and well-documented. Easy to extend:
|
|
253
|
+
|
|
254
|
+
- Add new schema types
|
|
255
|
+
- Customize markdown parsing rules
|
|
256
|
+
- Add transformation strategies
|
|
257
|
+
- Extend nx-helpers integration
|
|
258
|
+
|
|
259
|
+
## โจ Summary
|
|
260
|
+
|
|
261
|
+
You now have a complete, tested, documented TypeScript solution that:
|
|
262
|
+
|
|
263
|
+
1. โ
Converts markdown โ JSON (your primary need)
|
|
264
|
+
2. โ
Uses schema definitions (type-safe, clean API)
|
|
265
|
+
3. โ
Auto-fixes common errors (typos, types, structure)
|
|
266
|
+
4. โ
Integrates with nx-helpers (your existing tooling)
|
|
267
|
+
5. โ
Works with your exact example (demonstrated)
|
|
268
|
+
6. โ
Production-ready (tests, docs, examples)
|
|
269
|
+
|
|
270
|
+
**Ready to use in your NX project!** ๐
|