@mdgate/data 0.5.3 → 0.5.5
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/dist/index.js +5 -5
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{ConvertError as
|
|
2
|
-
`),r=[];for(let
|
|
3
|
-
`)){let
|
|
4
|
-
`)){let
|
|
5
|
-
`)}function
|
|
1
|
+
import{ConvertError as h}from"@mdgate/core";import{documentToMarkdown as g}from"@mdgate/document";import{fileExtension as v}from"@mdgate/utils";import{ConvertError as s}from"@mdgate/core";var w=[208,207,17,224,161,177,26,225];function $(n){let u=0;if(n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191)u=3;while(u<n.length){let r=n[u];if(r!==9&&r!==10&&r!==13&&r!==32)break;u+=1}return u}function J(n){let u=$(n);return d(n,"%PDF-",u)}function e(n){return n.length>=4&&n[0]===80&&n[1]===75&&n[2]===3&&n[3]===4}function L(n){if(n.length<w.length)return!1;for(let u=0;u<w.length;u+=1)if(n[u]!==w[u])return!1;return!0}function O(n){let u=$(n);return d(n,"{\\rtf",u)}function I(n){return J(n)||e(n)||L(n)||O(n)}function K(n){let u=$(n);if(u>=n.length)return!1;let r=n[u];if(r===123)return y(n,u+1);if(r===91)return b(n,u+1);return!1}function z(n,u){while(u<n.length){let r=n[u];if(r!==9&&r!==10&&r!==13&&r!==32)break;u+=1}return u}function y(n,u){let r=z(n,u);if(r>=n.length)return!0;let o=n[r];return o===34||o===125}function b(n,u){let r=z(n,u);if(r>=n.length)return!0;let o=n[r];if(o===93||o===123||o===91||o===34)return!0;if(o===116)return d(n,"true",r);if(o===102)return d(n,"false",r);if(o===110)return d(n,"null",r);if(o===45||o>=48&&o<=57)return nn(n,r);return!1}function nn(n,u){let r=u;if(n[r]===45)r+=1;if(r>=n.length||n[r]<48||n[r]>57)return!1;if(n[r]===48)r+=1;else while(r<n.length&&n[r]>=48&&n[r]<=57)r+=1;if(n[r]===46){if(r+=1,r>=n.length||n[r]<48||n[r]>57)return!1;while(r<n.length&&n[r]>=48&&n[r]<=57)r+=1}let o=n[r];if(o===101||o===69){if(r+=1,n[r]===43||n[r]===45)r+=1;if(r>=n.length||n[r]<48||n[r]>57)return!1;while(r<n.length&&n[r]>=48&&n[r]<=57)r+=1}if(r=z(n,r),r>=n.length)return!0;let c=n[r];return c===44||c===93}function R(n){let u=$(n);if(d(n,"<?xml",u))return!0;if(u>=n.length||n[u]!==60)return!1;let r=n[u+1];return r!==void 0&&rn(r)}function Z(n){if(n.length>=2&&n[0]===255&&n[1]===254)return C(new TextDecoder("utf-16le").decode(n));if(n.length>=2&&n[0]===254&&n[1]===255)return C(new TextDecoder("utf-16be").decode(n));let u=n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191?n.subarray(3):n;try{return new TextDecoder("utf-8",{fatal:!0}).decode(u)}catch{throw s.malformed("invalid utf-8")}}function G(n){let u=n.split(/[/\\]/).pop()??"",r=u.lastIndexOf("."),o=r<=0?u:u.slice(0,r);return o.length>0?o:void 0}function C(n){return n.charCodeAt(0)===65279?n.slice(1):n}function d(n,u,r){if(r+u.length>n.length)return!1;for(let o=0;o<u.length;o+=1)if(n[r+o]!==u.charCodeAt(o))return!1;return!0}function rn(n){return n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122||n===45||n===95||n===58}import{ConvertError as F}from"@mdgate/core";import{cleanText as ln}from"@mdgate/utils";import{emptyDocument as P,heading as un,plain as _,tableFromRows as on}from"@mdgate/document";import{cleanText as cn}from"@mdgate/utils";function p(n,u){let r=P();return r.blocks.push({type:"codeBlock",lang:n,text:u}),r}function i(n,u){let r=P();if(n!==void 0&&n.length>0)r.blocks.push(un(1,[_(cn(n))]));return u(r),r}function B(n){return n.map((u)=>({blocks:[{type:"paragraph",inlines:[_(u)]}],checked:void 0,markerLabel:void 0}))}function M(n){return{blocks:[{type:"paragraph",inlines:[_(n)]}],colSpan:1,rowSpan:1}}function N(n,u){let r=[n.map(M),...u.map((o)=>n.map((c,l)=>M(o[l]??"")))];return{type:"table",table:on(r,1,"data")}}var fn=24,T=50,W=12;function Q(n,u){let r;try{r=JSON.parse(n)}catch(c){throw F.malformed(c instanceof Error?c.message:"invalid json")}return mn(r,u)??p("json",JSON.stringify(r,null,2))}function U(n,u){let r=dn(n);if(r.length===0)throw F.malformed("empty jsonl");if(r.length<=T&&r.every(Y)){let c=E(r);if(c!==void 0&&c.length>0&&c.length<=W)return i(u,(l)=>{l.blocks.push(N(c,r.map((f)=>c.map((m)=>q(f[m])))))})}let o=i(u,()=>{return});for(let c=0;c<r.length;c+=1)o.blocks.push({type:"codeBlock",lang:"json",text:JSON.stringify(r[c],null,2)});return o}function x(n,u){try{return Q(n,u)}catch(r){if(gn(n))return U(n,u);throw r}}function dn(n){let u=n.split(`
|
|
2
|
+
`),r=[];for(let o=0;o<u.length;o+=1){let c=u[o];if(c.endsWith("\r"))c=c.slice(0,-1);let l=c.trim();if(l.length===0)continue;try{r.push(JSON.parse(l))}catch(f){throw F.malformed(f instanceof Error?`jsonl line ${o+1}: ${f.message}`:`jsonl line ${o+1}`)}}return r}function gn(n){let u=0;for(let r of n.split(`
|
|
3
|
+
`)){let o=(r.endsWith("\r")?r.slice(0,-1):r).trim();if(o.length===0)continue;try{JSON.parse(o)}catch{return!1}if(u+=1,u>=2)return!0}return!1}function mn(n,u){if(Y(n)){let r=Object.keys(n);if(r.length===0||r.length>fn)return;return i(u,(o)=>{o.blocks.push({type:"list",list:{marker:"bullet",start:1,items:B(r.map((c)=>`${c}: ${q(n[c])}`))}})})}if(Array.isArray(n)&&n.length>0&&n.length<=T){if(!n.every(Y))return;let r=E(n);if(r===void 0||r.length===0||r.length>W)return;return i(u,(o)=>{o.blocks.push(N(r,n.map((c)=>r.map((l)=>q(c[l])))))})}return}function E(n){let u=Object.keys(n[0]),r=new Set(u);for(let o=1;o<n.length;o+=1){let c=Object.keys(n[o]);if(c.length!==r.size)return;for(let l of c)if(!r.has(l))return}return u}function Y(n){if(n===null||typeof n!=="object"||Array.isArray(n))return!1;for(let u of Object.values(n))if(!pn(u))return!1;return!0}function pn(n){return n===null||typeof n==="string"||typeof n==="number"||typeof n==="boolean"}function q(n){if(n===null||n===void 0)return"";if(typeof n==="string")return ln(n);if(typeof n==="number"&&Number.isFinite(n))return String(n);if(typeof n==="boolean")return n?"true":"false";return""}function A(n){return p("xml",hn(n))}function t(n){return p("yaml",n.trimEnd())}function hn(n){let u=n.trim();if(u.length===0)return"";let r=Dn(u),o=[],c=0;for(let l=0;l<r.length;l+=1){let f=r[l],m=V(f);if(m==="text"){let D=f.trim();if(D.length===0)continue;let S=r[l+1],k=r[l-1];if(S!==void 0&&k!==void 0&&V(k)==="open"&&V(S)==="close"&&!D.includes(`
|
|
4
|
+
`)){let j=o.pop();o.push(`${j??`${a(c)}${k}`}${D}${S}`),l+=1,c=Math.max(0,c-1);continue}for(let j of D.split(/\r?\n/)){let X=j.trim();if(X.length>0)o.push(`${a(c)}${X}`)}continue}if(m==="close"){c=Math.max(0,c-1),o.push(`${a(c)}${f}`);continue}if(o.push(`${a(c)}${f}`),m==="open")c+=1}return o.join(`
|
|
5
|
+
`)}function Dn(n){let u=[],r=0;while(r<n.length){if(n.charCodeAt(r)!==60){let l=n.indexOf("<",r),f=l<0?n.length:l;u.push(n.slice(r,f)),r=f;continue}if(n.startsWith("<!--",r)){let l=n.indexOf("-->",r+4),f=l<0?n.length:l+3;u.push(n.slice(r,f)),r=f;continue}if(n.startsWith("<![CDATA[",r)){let l=n.indexOf("]]>",r+9),f=l<0?n.length:l+3;u.push(n.slice(r,f)),r=f;continue}let o=n.indexOf(">",r+1),c=o<0?n.length:o+1;u.push(n.slice(r,c)),r=c}return u}function V(n){if(n.charCodeAt(0)!==60)return"text";if(n.startsWith("</"))return"close";if(n.startsWith("<?")||n.startsWith("<!"))return"misc";if(n.endsWith("/>"))return"empty";return"open"}function a(n){return" ".repeat(n)}var $n=new Set(["json","jsonl"]),an=new Set(["xml","yaml","yml"]);function H(){return{id:"data",sniff(n,u){if(I(n))return 0;let r=u?.path!==void 0?v(u.path):void 0;if(r!==void 0&&$n.has(r))return 2;if(!R(n)&&K(n))return 2;if(r!==void 0&&an.has(r))return 1;return 0},convert(n,u){Sn(n);let r=u?.path!==void 0?v(u.path):void 0,o=u?.path!==void 0?G(u.path):void 0,c=Z(n);if(r==="jsonl")return{markdown:g(U(c,o))};if(r==="json")return{markdown:g(Q(c,o))};if(r==="xml")return{markdown:g(A(c))};if(r==="yaml"||r==="yml")return{markdown:g(t(c))};if(K(n))return{markdown:g(x(c,o))};if(R(n))return{markdown:g(A(c))};throw h.unsupported("data")}}}function Sn(n){if(J(n))throw h.unsupported("pdf");if(L(n))throw h.unsupported("ole");if(e(n))throw h.unsupported("zip");if(O(n))throw h.unsupported("rtf")}import{create as kn}from"@mdgate/core";var jn=kn([H()]);function wn(n,u){return jn(n,u)}export{wn as toMarkdown,H as data};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/data",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "mdgate JSON, JSONL, XML, and YAML 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.5.
|
|
26
|
-
"@mdgate/document": "0.5.
|
|
27
|
-
"@mdgate/utils": "0.5.
|
|
25
|
+
"@mdgate/core": "0.5.5",
|
|
26
|
+
"@mdgate/document": "0.5.5",
|
|
27
|
+
"@mdgate/utils": "0.5.5"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|