@mdgate/data 0.6.7 → 0.6.9
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/README.md +141 -10
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,28 +1,159 @@
|
|
|
1
1
|
# @mdgate/data
|
|
2
2
|
|
|
3
|
-
Convert JSON, JSONL, XML, and YAML
|
|
4
|
-
Node, Edge, and browsers. No native addons.
|
|
3
|
+
**Convert JSON, JSONL, XML, and YAML to Markdown in TypeScript.**
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[`@mdgate/data`](https://github.com/mdgate/converters/tree/main/packages/data) reads `.json`, `.jsonl`, `.xml`, `.yaml`, and `.yml` files directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, or an extra parser stack.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mdgate/data
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { toMarkdown } from '@mdgate/data';
|
|
15
|
+
|
|
16
|
+
const markdown = await toMarkdown(bytes, {
|
|
17
|
+
path: 'config.yaml',
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`bytes` is a `Uint8Array`, so the file can come from a file upload, object storage, an HTTP request, a browser file picker, or anywhere else your application gets bytes.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Why [`@mdgate/data`](https://github.com/mdgate/converters/tree/main/packages/data)
|
|
26
|
+
|
|
27
|
+
Structured data files are already text, but they are not Markdown. Agents and search indexes work better with a heading-and-list shape than with a raw dump.
|
|
28
|
+
|
|
29
|
+
[`@mdgate/data`](https://github.com/mdgate/converters/tree/main/packages/data) is a data reader written for the same runtime as your application:
|
|
30
|
+
|
|
31
|
+
* **Pure TypeScript**
|
|
32
|
+
* **JSON / XML / YAML → Markdown locally**
|
|
33
|
+
* **No Python runtime**
|
|
34
|
+
* **No native addons**
|
|
35
|
+
* **No WASM runtime**
|
|
36
|
+
* **Zero third-party runtime dependencies**
|
|
37
|
+
* **Works with raw `Uint8Array` input**
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## What it extracts
|
|
42
|
+
|
|
43
|
+
* JSON objects and arrays as nested Markdown structure
|
|
44
|
+
* JSONL as one record after another
|
|
45
|
+
* YAML mappings and sequences
|
|
46
|
+
* XML as nested headings and text
|
|
47
|
+
|
|
48
|
+
XML is never claimed by content signature alone. Flat ODF and many office parts start with `<?xml`, so XML needs a path hint (`.xml`) when composed with other converters.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Node.js
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { readFile } from 'node:fs/promises';
|
|
56
|
+
import { toMarkdown } from '@mdgate/data';
|
|
57
|
+
|
|
58
|
+
const bytes = new Uint8Array(await readFile('records.jsonl'));
|
|
59
|
+
const markdown = await toMarkdown(bytes, {
|
|
60
|
+
path: 'records.jsonl',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
console.log(markdown);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Browser
|
|
11
69
|
|
|
12
70
|
```ts
|
|
13
71
|
import { toMarkdown } from '@mdgate/data';
|
|
14
72
|
|
|
15
|
-
const
|
|
73
|
+
const file = input.files![0];
|
|
74
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
75
|
+
|
|
76
|
+
const markdown = await toMarkdown(bytes, {
|
|
77
|
+
path: file.name,
|
|
78
|
+
});
|
|
16
79
|
```
|
|
17
80
|
|
|
18
|
-
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Cloudflare Workers and Edge runtimes
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { toMarkdown } from '@mdgate/data';
|
|
87
|
+
|
|
88
|
+
export default {
|
|
89
|
+
async fetch(request: Request) {
|
|
90
|
+
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
91
|
+
const markdown = await toMarkdown(bytes, {
|
|
92
|
+
path: request.headers.get('x-filename') ?? undefined,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return new Response(markdown, {
|
|
96
|
+
headers: {
|
|
97
|
+
'content-type': 'text/markdown; charset=utf-8',
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Format detection
|
|
107
|
+
|
|
108
|
+
JSON can often be identified from the bytes. XML and YAML should be named with `path`.
|
|
109
|
+
|
|
110
|
+
The path is never used to read a file from disk.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Compose it with other file readers
|
|
115
|
+
|
|
116
|
+
[`@mdgate/data`](https://github.com/mdgate/converters/tree/main/packages/data) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
|
|
19
117
|
|
|
20
118
|
```ts
|
|
21
119
|
import { create } from '@mdgate/core';
|
|
22
120
|
import { data } from '@mdgate/data';
|
|
121
|
+
import { csv } from '@mdgate/csv';
|
|
122
|
+
import { text } from '@mdgate/text';
|
|
23
123
|
|
|
24
|
-
const
|
|
124
|
+
const read = create([
|
|
125
|
+
data(),
|
|
126
|
+
csv(),
|
|
127
|
+
text(),
|
|
128
|
+
]);
|
|
25
129
|
```
|
|
26
130
|
|
|
27
|
-
|
|
28
|
-
|
|
131
|
+
The application still uses one reading interface while each format remains independently installable.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Need more than data files?
|
|
136
|
+
|
|
137
|
+
If your application needs to read many different file types, use the complete converter set:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npm install @mdgate/converters
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
import { toMarkdown } from '@mdgate/converters';
|
|
145
|
+
|
|
146
|
+
const markdown = await toMarkdown(bytes, {
|
|
147
|
+
path: filename,
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
[`@mdgate/data`](https://github.com/mdgate/converters/tree/main/packages/data) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
|
|
152
|
+
|
|
153
|
+
For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/data",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "mdgate JSON, JSONL, XML, and YAML converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://convert.mdgate.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/mdgate/converters.git",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"prepublishOnly": "bun run build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mdgate/core": "0.6.
|
|
32
|
-
"@mdgate/document": "0.6.
|
|
33
|
-
"@mdgate/utils": "0.6.
|
|
31
|
+
"@mdgate/core": "0.6.9",
|
|
32
|
+
"@mdgate/document": "0.6.9",
|
|
33
|
+
"@mdgate/utils": "0.6.9"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|