@mdgate/csv 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.
Files changed (2) hide show
  1. package/README.md +147 -9
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,26 +1,164 @@
1
1
  # @mdgate/csv
2
2
 
3
- Convert CSV files to Markdown tables. Outputs GitHub-Flavored Markdown. Works in Node, Edge, and
4
- browsers. No native addons.
3
+ **Convert CSV files to Markdown in TypeScript.**
5
4
 
6
- Handles: `.csv`, `.tsv`, `.tab` (comma, semicolon, or tab separated; UTF-8/UTF-16)
5
+ [`@mdgate/csv`](https://github.com/mdgate/converters/tree/main/packages/csv) reads `.csv`, `.tsv`, and `.tab` files directly in JavaScript and converts them into GitHub-Flavored Markdown tables, without Python, native addons, or a spreadsheet runtime.
7
6
 
8
- ## Usage
7
+ Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
8
+
9
+ ```bash
10
+ npm install @mdgate/csv
11
+ ```
12
+
13
+ ```ts
14
+ import { toMarkdown } from '@mdgate/csv';
15
+
16
+ const markdown = await toMarkdown(bytes, {
17
+ path: 'records.csv',
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/csv`](https://github.com/mdgate/converters/tree/main/packages/csv)
26
+
27
+ CSV has no file signature. A bytes-only sniffer cannot tell it from other text. This converter exists so CSV can join the same `toMarkdown(bytes)` interface as Word and PDF.
28
+
29
+ * **Pure TypeScript**
30
+ * **CSV to Markdown tables locally**
31
+ * **No Python runtime**
32
+ * **No native addons**
33
+ * **No WASM runtime**
34
+ * **Zero third-party runtime dependencies**
35
+ * **Works with raw `Uint8Array` input**
36
+ * **Needs a path hint, because CSV has no reliable content signature**
37
+
38
+ ---
39
+
40
+ ## What it extracts
41
+
42
+ [`@mdgate/csv`](https://github.com/mdgate/converters/tree/main/packages/csv) parses comma, semicolon, or tab-separated text (UTF-8 or UTF-16) and rebuilds a Markdown table.
43
+
44
+ The converter handles CSV-specific concerns including:
45
+
46
+ * quoted fields
47
+ * comma, semicolon, and tab delimiters
48
+ * UTF-8 and UTF-16
49
+ * `.csv`, `.tsv`, and `.tab`
50
+
51
+ Excel workbooks are a different format. Use [`@mdgate/xlsx`](https://github.com/mdgate/converters/tree/main/packages/xlsx) for those.
52
+
53
+ ---
54
+
55
+ ## Node.js
56
+
57
+ ```ts
58
+ import { readFile } from 'node:fs/promises';
59
+ import { toMarkdown } from '@mdgate/csv';
60
+
61
+ const bytes = new Uint8Array(await readFile('records.csv'));
62
+ const markdown = await toMarkdown(bytes, {
63
+ path: 'records.csv',
64
+ });
65
+
66
+ console.log(markdown);
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Browser
72
+
73
+ ```ts
74
+ import { toMarkdown } from '@mdgate/csv';
75
+
76
+ const file = input.files![0];
77
+ const bytes = new Uint8Array(await file.arrayBuffer());
78
+
79
+ const markdown = await toMarkdown(bytes, {
80
+ path: file.name,
81
+ });
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Cloudflare Workers and Edge runtimes
9
87
 
10
88
  ```ts
11
89
  import { toMarkdown } from '@mdgate/csv';
12
90
 
13
- const markdown = await toMarkdown(bytes);
91
+ export default {
92
+ async fetch(request: Request) {
93
+ const bytes = new Uint8Array(await request.arrayBuffer());
94
+ const markdown = await toMarkdown(bytes, {
95
+ path: request.headers.get('x-filename') ?? 'upload.csv',
96
+ });
97
+
98
+ return new Response(markdown, {
99
+ headers: {
100
+ 'content-type': 'text/markdown; charset=utf-8',
101
+ },
102
+ });
103
+ },
104
+ };
14
105
  ```
15
106
 
16
- Compose with other converters:
107
+ ---
108
+
109
+ ## Path hint
110
+
111
+ CSV cannot be identified from a magic number. Pass `path` so the converter can claim the file when it is composed with others.
112
+
113
+ The path is never used to read a file from disk.
114
+
115
+ ---
116
+
117
+ ## Compose it with other file readers
118
+
119
+ [`@mdgate/csv`](https://github.com/mdgate/converters/tree/main/packages/csv) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
17
120
 
18
121
  ```ts
19
122
  import { create } from '@mdgate/core';
20
123
  import { csv } from '@mdgate/csv';
124
+ import { xlsx } from '@mdgate/xlsx';
125
+
126
+ const read = create([
127
+ csv(),
128
+ xlsx(),
129
+ ]);
21
130
 
22
- const convert = create([csv()]);
131
+ const markdown = await read(bytes, {
132
+ path: 'records.csv',
133
+ });
23
134
  ```
24
135
 
25
- Part of [mdgate converters](https://github.com/mdgate/converters); install
26
- `@mdgate/converters` for every format at once.
136
+ The application still uses one reading interface while each format remains independently installable.
137
+
138
+ ---
139
+
140
+ ## Need more than CSV?
141
+
142
+ If your application needs to read many different file types, use the complete converter set:
143
+
144
+ ```bash
145
+ npm install @mdgate/converters
146
+ ```
147
+
148
+ ```ts
149
+ import { toMarkdown } from '@mdgate/converters';
150
+
151
+ const markdown = await toMarkdown(bytes, {
152
+ path: filename,
153
+ });
154
+ ```
155
+
156
+ [`@mdgate/csv`](https://github.com/mdgate/converters/tree/main/packages/csv) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
157
+
158
+ For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
159
+
160
+ ---
161
+
162
+ ## License
163
+
164
+ MIT
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mdgate/csv",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "description": "mdgate CSV converter",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "homepage": "https://demo.mdgate.dev",
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.7",
32
- "@mdgate/document": "0.6.7",
33
- "@mdgate/utils": "0.6.7"
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"