@kklab/json2markdown 0.0.19 → 0.0.21

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 CHANGED
@@ -1,6 +1,6 @@
1
- var h = Object.defineProperty;
2
- var c = (n, r, t) => r in n ? h(n, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[r] = t;
3
- var o = (n, r, t) => (c(n, typeof r != "symbol" ? r + "" : r, t), t);
1
+ var f = Object.defineProperty;
2
+ var v = (n, r, t) => r in n ? f(n, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[r] = t;
3
+ var o = (n, r, t) => (v(n, typeof r != "symbol" ? r + "" : r, t), t);
4
4
  const e = {
5
5
  A: "a",
6
6
  BLOCKQUOTE: "blockquote",
@@ -14,7 +14,7 @@ const e = {
14
14
  TD: "td",
15
15
  TR: "tr"
16
16
  };
17
- class a {
17
+ class c {
18
18
  constructor(r) {
19
19
  o(this, "data");
20
20
  o(this, "elements", []);
@@ -25,7 +25,7 @@ class a {
25
25
  * Converts the provided data into Markdown format.
26
26
  */
27
27
  static toMarkdown(r, t) {
28
- return new a(r).toMarkdown(t);
28
+ return new c(r).toMarkdown(t);
29
29
  }
30
30
  /**
31
31
  * Converts the provided data into Markdown format.
@@ -97,13 +97,18 @@ ${t.value}
97
97
  return this.convertFromPrimitive(r), this;
98
98
  if (r.length > 0 && r.every((s) => typeof s == "object" && s !== null && Object.keys(s).length > 0)) {
99
99
  const [s] = r;
100
- return this.pushElement({
100
+ this.pushElement({
101
101
  tag: e.TR,
102
102
  values: Object.keys(s)
103
- }), r.forEach((i) => {
103
+ });
104
+ const i = Object.keys(s);
105
+ return r.forEach((a) => {
104
106
  this.pushElement({
105
107
  tag: e.TD,
106
- values: Object.values(i).map((u) => this.formatValue(u))
108
+ values: i.map((h) => {
109
+ const u = this.formatValue(a[h]);
110
+ return typeof u == "string" ? u.replaceAll("|", "\\|") : u;
111
+ })
107
112
  });
108
113
  }), this;
109
114
  }
@@ -154,5 +159,5 @@ ${t.value}
154
159
  }
155
160
  }
156
161
  export {
157
- a as Converter
162
+ c as Converter
158
163
  };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(n,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(n=typeof globalThis<"u"?globalThis:n||self,r(n.JSON2Markdown={}))})(this,function(n){"use strict";var a=Object.defineProperty;var c=(n,r,s)=>r in n?a(n,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[r]=s;var u=(n,r,s)=>(c(n,typeof r!="symbol"?r+"":r,s),s);const r={A:"a",BLOCKQUOTE:"blockquote",BR:"br",HEADING:"heading",HR:"hr",IMG:"img",LI:"li",P:"p",PRE:"pre",TD:"td",TR:"tr"};class s{constructor(t){u(this,"data");u(this,"elements",[]);u(this,"onConvert",t=>t);this.data=typeof t=="string"?JSON.parse(t):t}static toMarkdown(t,e){return new s(t).toMarkdown(e)}toMarkdown(t){return this.convert(t),this.elements.map(e=>{switch(e.tag){case r.A:return`[${e.value}](${e.href})
1
+ (function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i.JSON2Markdown={}))})(this,function(i){"use strict";var f=Object.defineProperty;var l=(i,r,s)=>r in i?f(i,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[r]=s;var u=(i,r,s)=>(l(i,typeof r!="symbol"?r+"":r,s),s);const r={A:"a",BLOCKQUOTE:"blockquote",BR:"br",HEADING:"heading",HR:"hr",IMG:"img",LI:"li",P:"p",PRE:"pre",TD:"td",TR:"tr"};class s{constructor(t){u(this,"data");u(this,"elements",[]);u(this,"onConvert",t=>t);this.data=typeof t=="string"?JSON.parse(t):t}static toMarkdown(t,e){return new s(t).toMarkdown(e)}toMarkdown(t){return this.convert(t),this.elements.map(e=>{switch(e.tag){case r.A:return`[${e.value}](${e.href})
2
2
 
3
3
  `;case r.BLOCKQUOTE:return`> ${e.value}
4
4
 
@@ -16,8 +16,8 @@
16
16
  ${e.value}
17
17
  \`\`\`
18
18
 
19
- `;case r.TD:return`| ${e.values.map(i=>typeof i=="string"?i.replaceAll(`
20
- `,"<br>"):i).join(" | ")} |
19
+ `;case r.TD:return`| ${e.values.map(n=>typeof n=="string"?n.replaceAll(`
20
+ `,"<br>"):n).join(" | ")} |
21
21
  `;case r.TR:return`| ${e.values.join(" | ")} |
22
22
  | ${e.values.map(()=>"---").join(" | ")} |
23
- `;default:return""}}).join("")}getElements(){return this.elements}pushElement(t){const e=this.onConvert(t);return e?(this.elements.push(e),!0):!1}convert(t){return t&&(this.onConvert=t),Array.isArray(this.data)&&this.convertFromArray(this.data),this.convertFromObject(this.data),this}convertFromArray(t,e=0){if(t==null)return this.convertFromPrimitive(t),this;if(t.length>0&&t.every(i=>typeof i=="object"&&i!==null&&Object.keys(i).length>0)){const[i]=t;return this.pushElement({tag:r.TR,values:Object.keys(i)}),t.forEach(o=>{this.pushElement({tag:r.TD,values:Object.values(o).map(h=>this.formatValue(h))})}),this}for(const i of t){if(Array.isArray(i)){this.convertFromArray(i,e+1);continue}this.pushElement({tag:r.LI,value:this.formatValue(i),indent:e})}return this}convertFromObject(t,e=0){if(t==null)return this.convertFromPrimitive(t),this;for(const[i,o]of Object.entries(t))if(this.pushElement({tag:r.HEADING,value:i,level:e+1})){if(Array.isArray(o)){this.convertFromArray(o),this.pushElement({tag:r.BR});continue}if(typeof o=="object"){this.convertFromObject(o,e+1);continue}this.convertFromPrimitive(o)}return this}convertFromPrimitive(t){return this.pushElement({tag:r.P,value:this.formatValue(t)}),this}formatValue(t){return t==null?"":Array.isArray(t)?t.map(e=>this.formatValue(e)).join(", "):typeof t=="object"?JSON.stringify(t):typeof t=="string"?t.trim():t}}n.Converter=s,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
23
+ `;default:return""}}).join("")}getElements(){return this.elements}pushElement(t){const e=this.onConvert(t);return e?(this.elements.push(e),!0):!1}convert(t){return t&&(this.onConvert=t),Array.isArray(this.data)&&this.convertFromArray(this.data),this.convertFromObject(this.data),this}convertFromArray(t,e=0){if(t==null)return this.convertFromPrimitive(t),this;if(t.length>0&&t.every(n=>typeof n=="object"&&n!==null&&Object.keys(n).length>0)){const[n]=t;this.pushElement({tag:r.TR,values:Object.keys(n)});const o=Object.keys(n);return t.forEach(a=>{this.pushElement({tag:r.TD,values:o.map(h=>{const c=this.formatValue(a[h]);return typeof c=="string"?c.replaceAll("|","\\|"):c})})}),this}for(const n of t){if(Array.isArray(n)){this.convertFromArray(n,e+1);continue}this.pushElement({tag:r.LI,value:this.formatValue(n),indent:e})}return this}convertFromObject(t,e=0){if(t==null)return this.convertFromPrimitive(t),this;for(const[n,o]of Object.entries(t))if(this.pushElement({tag:r.HEADING,value:n,level:e+1})){if(Array.isArray(o)){this.convertFromArray(o),this.pushElement({tag:r.BR});continue}if(typeof o=="object"){this.convertFromObject(o,e+1);continue}this.convertFromPrimitive(o)}return this}convertFromPrimitive(t){return this.pushElement({tag:r.P,value:this.formatValue(t)}),this}formatValue(t){return t==null?"":Array.isArray(t)?t.map(e=>this.formatValue(e)).join(", "):typeof t=="object"?JSON.stringify(t):typeof t=="string"?t.trim():t}}i.Converter=s,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kklab/json2markdown",
3
3
  "private": false,
4
- "version": "0.0.19",
4
+ "version": "0.0.21",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "scripts": {