@mdgate/csv 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/README.md +26 -0
- package/dist/csv.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/to-markdown.d.ts +6 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @mdgate/csv
|
|
2
|
+
|
|
3
|
+
Convert CSV files to Markdown tables. Outputs GitHub-Flavored Markdown. Works in Node, Edge, and
|
|
4
|
+
browsers. No native addons.
|
|
5
|
+
|
|
6
|
+
Handles: `.csv` (comma, semicolon, or tab separated; UTF-8/UTF-16)
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { toMarkdown } from '@mdgate/csv';
|
|
12
|
+
|
|
13
|
+
const markdown = await toMarkdown(bytes);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Compose with other converters:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { create } from '@mdgate/core';
|
|
20
|
+
import { csv } from '@mdgate/csv';
|
|
21
|
+
|
|
22
|
+
const convert = create([csv()]);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Part of [mdgate converters](https://github.com/mdgate/converters); install
|
|
26
|
+
`@mdgate/converters` for every format at once.
|
package/dist/csv.d.ts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{documentToMarkdown as c}from"@mdgate/document";import{fileExtension as i}from"@mdgate/utils";import{emptyDocument as C,PLAIN as L,resolveHeaderRows as F,tableFromRows as N}from"@mdgate/document";import{cleanText as I}from"@mdgate/utils";var T=[",",";","\t","|"],l=20,w=34,d="€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ",A=0,g=1,Q=2,h=3,U=4,M=5,B=6,p=7,f=8,k=9,q=10;function m(z){let Y=R(r(z)),V=n(Y),Z=E(Y,V),H=Array(Z.length);for(let P=0;P<Z.length;P+=1){let G=Z[P],K=Array(G.length);for(let W=0;W<G.length;W+=1)K[W]={blocks:[{type:"paragraph",inlines:[{type:"text",text:D(G[W]),style:L}]}],colSpan:1,rowSpan:1};H[P]=K}let J=C(),j=N(H,0,"data");if(j.headerRows=F(j,0),j.grid.length>0)J.blocks.push({type:"table",table:j});return J}function r(z){if(z.length>=2&&z[0]===255&&z[1]===254)return new TextDecoder("utf-16le").decode(z);if(z.length>=2&&z[0]===254&&z[1]===255)return new TextDecoder("utf-16be").decode(z);let Y=z.length>=3&&z[0]===239&&z[1]===187&&z[2]===191?z.subarray(3):z;try{return new TextDecoder("utf-8",{fatal:!0}).decode(Y)}catch{return _(Y)}}function _(z){let Y="";for(let V=0;V<z.length;V+=1){let Z=z[V];if(Z<128||Z>=160)Y+=String.fromCharCode(Z);else Y+=d[Z-128]}return Y}function R(z){return z.charCodeAt(0)===65279?z.slice(1):z}function D(z){let Y=z.length;for(let V=0;V<Y;V+=1){let Z=z.charCodeAt(V);if(Z<32||Z>126)return I(z)}return z}function n(z){let Y=",",V=0;for(let Z of T){let H=o(z,Z.charCodeAt(0),l);if(H.length===0)continue;let J=new Map;for(let K of H)J.set(K,(J.get(K)??0)+1);let j=0,P=0;for(let[K,W]of J)if(W>P||W===P&&K>j)P=W,j=K;if(j<2)continue;let G=P*1000+Math.min(j,500);if(G>V)Y=Z,V=G}return Y}function v(z){return z===10||z===13}function o(z,Y,V){let Z=[],H=0,J=g,j=z.length,P=0;while(P<j){let G=z.charCodeAt(P),K=2;switch(J){case A:K=2;break;case g:if(v(G))K=2;else J=Q,K=0;break;case k:J=g,K=0;break;case Q:if(G===w)J=U,K=2;else if(G===Y)J=B,K=2;else if(v(G))J=p,K=0;else J=h,K=1;break;case B:J=Q,K=0;break;case p:J=f,K=0;break;case h:if(G===Y)J=B,K=2;else if(v(G))J=p,K=0;else K=1;break;case U:if(G===w)J=M,K=2;else K=1;break;case M:if(G===w)J=U,K=1;else if(G===Y)J=B,K=2;else if(v(G))J=p,K=0;else J=h,K=1;break;case f:if(G===13)J=q,K=2;else J=k,K=2;break;case q:if(G===10)J=g,K=2;else J=g,K=0;break;default:J=A,K=2;break}if(K===0){if(J===B||J===k||J===q)H+=1;if(J===k||J===q)Z.push(H),H=0;continue}if(P+=1,J===B||J===k||J===q)H+=1;if(J===k||J===q)Z.push(H),H=0;if(Z.length>=V)return Z}if(J=b(J),J===k)H+=1,Z.push(H);return Z}function E(z,Y,V){let Z=Y.charCodeAt(0),H=[],J=[],j="",P=-1,G=g,K=z.length,W=0,x=($)=>{if(P<0)return;let X=z.slice(P,$);j=j.length===0?X:j+X,P=-1},u=()=>{x(W),J.push(j),j=""},y=()=>{H.push(J),J=[]},O=($)=>{if($===B||$===k||$===q)u();if($===k||$===q)y()};while(W<K){let $=z.charCodeAt(W),X=2;switch(G){case A:X=2;break;case g:if(v($))X=2;else G=Q,X=0;break;case k:G=g,X=0;break;case Q:if($===w)G=U,X=2;else if($===Z)G=B,X=2;else if(v($))G=p,X=0;else G=h,X=1;break;case B:G=Q,X=0;break;case p:G=f,X=0;break;case h:if($===Z)G=B,X=2;else if(v($))G=p,X=0;else X=1;break;case U:if($===w)G=M,X=2;else X=1;break;case M:if($===w)G=U,X=1;else if($===Z)G=B,X=2;else if(v($))G=p,X=0;else G=h,X=1;break;case f:if($===13)G=q,X=2;else G=k,X=2;break;case q:if($===10)G=g,X=2;else G=g,X=0;break;default:G=A,X=2;break}if(X===0){x(W),O(G);continue}if(X===1){if(P<0)P=W}else x(W);if(W+=1,O(G),V!==void 0&&H.length>=V)return H}if(G=b(G),G===k)u(),y();return H}function b(z){if(z===A||z===g||z===k||z===q)return A;return k}function S(){return{id:"csv",sniff(z,Y){return Y?.path!==void 0&&i(Y.path)==="csv"?1:0},convert(z){return{markdown:c(m(z))}}}}import{create as a}from"@mdgate/core";var s=a([S()]);function e(z,Y){return s(z,Y)}export{e as toMarkdown,S as csv};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ConvertHint } from '@mdgate/core';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a single file's bytes to Markdown with the csv converter.
|
|
4
|
+
* `hint.path` is only a sniff hint; it is never read from disk.
|
|
5
|
+
*/
|
|
6
|
+
export declare function toMarkdown(bytes: Uint8Array, hint?: ConvertHint): Promise<string>;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdgate/csv",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "mdgate CSV converter",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/**/*.js",
|
|
18
|
+
"dist/**/*.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "bun ../../scripts/build-package.ts",
|
|
22
|
+
"prepublishOnly": "bun run build"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@mdgate/core": "0.1.3",
|
|
26
|
+
"@mdgate/document": "0.1.0",
|
|
27
|
+
"@mdgate/utils": "0.1.2"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"mdgate",
|
|
37
|
+
"markdown",
|
|
38
|
+
"csv"
|
|
39
|
+
]
|
|
40
|
+
}
|