@mdgate/csv 0.1.0 → 0.4.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 CHANGED
@@ -3,7 +3,7 @@
3
3
  Convert CSV files to Markdown tables. Outputs GitHub-Flavored Markdown. Works in Node, Edge, and
4
4
  browsers. No native addons.
5
5
 
6
- Handles: `.csv` (comma, semicolon, or tab separated; UTF-8/UTF-16)
6
+ Handles: `.csv`, `.tsv`, `.tab` (comma, semicolon, or tab separated; UTF-8/UTF-16)
7
7
 
8
8
  ## Usage
9
9
 
package/dist/index.js CHANGED
@@ -1 +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};
1
+ import{ConvertError as S}from"@mdgate/core";import{documentToMarkdown as i}from"@mdgate/document";import{fileExtension as s}from"@mdgate/utils";import{emptyDocument as F,PLAIN as b,resolveHeaderRows as I,tableFromRows as l}from"@mdgate/document";import{cleanText as T}from"@mdgate/utils";var d=[",",";","\t","|"],_=20,g=34,r="€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ",A=0,p=1,Q=2,U=3,h=4,M=5,q=6,w=7,f=8,B=9,W=10;function L(z){let Y=n(R(z)),H=E(Y),$=a(Y,H),V=Array($.length);for(let X=0;X<$.length;X+=1){let G=$[X],K=Array(G.length);for(let k=0;k<G.length;k+=1)K[k]={blocks:[{type:"paragraph",inlines:[{type:"text",text:o(G[k]),style:b}]}],colSpan:1,rowSpan:1};V[X]=K}let J=F(),j=l(V,0,"data");if(j.headerRows=I(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 D(Y)}}function D(z){let Y="";for(let H=0;H<z.length;H+=1){let $=z[H];if($<128||$>=160)Y+=String.fromCharCode($);else Y+=r[$-128]}return Y}function n(z){return z.charCodeAt(0)===65279?z.slice(1):z}function o(z){let Y=z.length;for(let H=0;H<Y;H+=1){let $=z.charCodeAt(H);if($<32||$>126)return T(z)}return z}function E(z){let Y=",",H=0;for(let $ of d){let V=c(z,$.charCodeAt(0),_);if(V.length===0)continue;let J=new Map;for(let K of V)J.set(K,(J.get(K)??0)+1);let j=0,X=0;for(let[K,k]of J)if(k>X||k===X&&K>j)X=k,j=K;if(j<2)continue;let G=X*1000+Math.min(j,500);if(G>H)Y=$,H=G}return Y}function v(z){return z===10||z===13}function c(z,Y,H){let $=[],V=0,J=p,j=z.length,X=0;while(X<j){let G=z.charCodeAt(X),K=2;switch(J){case A:K=2;break;case p:if(v(G))K=2;else J=Q,K=0;break;case B:J=p,K=0;break;case Q:if(G===g)J=h,K=2;else if(G===Y)J=q,K=2;else if(v(G))J=w,K=0;else J=U,K=1;break;case q:J=Q,K=0;break;case w:J=f,K=0;break;case U:if(G===Y)J=q,K=2;else if(v(G))J=w,K=0;else K=1;break;case h:if(G===g)J=M,K=2;else K=1;break;case M:if(G===g)J=h,K=1;else if(G===Y)J=q,K=2;else if(v(G))J=w,K=0;else J=U,K=1;break;case f:if(G===13)J=W,K=2;else J=B,K=2;break;case W:if(G===10)J=p,K=2;else J=p,K=0;break;default:J=A,K=2;break}if(K===0){if(J===q||J===B||J===W)V+=1;if(J===B||J===W)$.push(V),V=0;continue}if(X+=1,J===q||J===B||J===W)V+=1;if(J===B||J===W)$.push(V),V=0;if($.length>=H)return $}if(J=N(J),J===B)V+=1,$.push(V);return $}function a(z,Y,H){let $=Y.charCodeAt(0),V=[],J=[],j="",X=-1,G=p,K=z.length,k=0,x=(P)=>{if(X<0)return;let Z=z.slice(X,P);j=j.length===0?Z:j+Z,X=-1},m=()=>{x(k),J.push(j),j=""},y=()=>{V.push(J),J=[]},C=(P)=>{if(P===q||P===B||P===W)m();if(P===B||P===W)y()};while(k<K){let P=z.charCodeAt(k),Z=2;switch(G){case A:Z=2;break;case p:if(v(P))Z=2;else G=Q,Z=0;break;case B:G=p,Z=0;break;case Q:if(P===g)G=h,Z=2;else if(P===$)G=q,Z=2;else if(v(P))G=w,Z=0;else G=U,Z=1;break;case q:G=Q,Z=0;break;case w:G=f,Z=0;break;case U:if(P===$)G=q,Z=2;else if(v(P))G=w,Z=0;else Z=1;break;case h:if(P===g)G=M,Z=2;else Z=1;break;case M:if(P===g)G=h,Z=1;else if(P===$)G=q,Z=2;else if(v(P))G=w,Z=0;else G=U,Z=1;break;case f:if(P===13)G=W,Z=2;else G=B,Z=2;break;case W:if(P===10)G=p,Z=2;else G=p,Z=0;break;default:G=A,Z=2;break}if(Z===0){x(k),C(G);continue}if(Z===1){if(X<0)X=k}else x(k);if(k+=1,C(G),H!==void 0&&V.length>=H)return V}if(G=N(G),G===B)m(),y();return V}function N(z){if(z===A||z===p||z===B||z===W)return A;return B}var e=new Set(["csv","tsv","tab"]);function O(){return{id:"csv",sniff(z,Y){return Y?.path!==void 0&&e.has(s(Y.path)??"")?1:0},convert(z){return t(z),{markdown:i(L(z))}}}}function t(z){if(u(z,[37,80,68,70,45]))throw S.unsupported("pdf");if(u(z,[208,207,17,224,161,177,26,225]))throw S.unsupported("ole");if(u(z,[80,75,3,4]))throw S.unsupported("zip")}function u(z,Y){if(z.length<Y.length)return!1;for(let H=0;H<Y.length;H+=1)if(z[H]!==Y[H])return!1;return!0}import{create as zz}from"@mdgate/core";var Gz=zz([O()]);function Jz(z,Y){return Gz(z,Y)}export{Jz as toMarkdown,O as csv};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgate/csv",
3
- "version": "0.1.0",
3
+ "version": "0.4.0",
4
4
  "description": "mdgate CSV converter",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,9 +22,9 @@
22
22
  "prepublishOnly": "bun run build"
23
23
  },
24
24
  "dependencies": {
25
- "@mdgate/core": "0.1.3",
26
- "@mdgate/document": "0.1.0",
27
- "@mdgate/utils": "0.1.2"
25
+ "@mdgate/core": "0.4.0",
26
+ "@mdgate/document": "0.4.0",
27
+ "@mdgate/utils": "0.4.0"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"