@mdgate/csv 0.1.0 → 0.4.1
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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -4
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
|
|
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
|
|
3
|
+
"version": "0.4.1",
|
|
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
|
|
26
|
-
"@mdgate/document": "0.1
|
|
27
|
-
"@mdgate/utils": "0.1
|
|
25
|
+
"@mdgate/core": "0.4.1",
|
|
26
|
+
"@mdgate/document": "0.4.1",
|
|
27
|
+
"@mdgate/utils": "0.4.1"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|