@kklab/json2markdown 0.0.20 → 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 c = Object.defineProperty;
2
- var f = (n, r, t) => r in n ? c(n, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[r] = t;
3
- var o = (n, r, t) => (f(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 h {
17
+ class c {
18
18
  constructor(r) {
19
19
  o(this, "data");
20
20
  o(this, "elements", []);
@@ -25,7 +25,7 @@ class h {
25
25
  * Converts the provided data into Markdown format.
26
26
  */
27
27
  static toMarkdown(r, t) {
28
- return new h(r).toMarkdown(t);
28
+ return new c(r).toMarkdown(t);
29
29
  }
30
30
  /**
31
31
  * Converts the provided data into Markdown format.
@@ -102,10 +102,13 @@ ${t.value}
102
102
  values: Object.keys(s)
103
103
  });
104
104
  const i = Object.keys(s);
105
- return r.forEach((u) => {
105
+ return r.forEach((a) => {
106
106
  this.pushElement({
107
107
  tag: e.TD,
108
- values: i.map((a) => this.formatValue(u[a]))
108
+ values: i.map((h) => {
109
+ const u = this.formatValue(a[h]);
110
+ return typeof u == "string" ? u.replaceAll("|", "\\|") : u;
111
+ })
109
112
  });
110
113
  }), this;
111
114
  }
@@ -156,5 +159,5 @@ ${t.value}
156
159
  }
157
160
  }
158
161
  export {
159
- h as Converter
162
+ c as Converter
160
163
  };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
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 a=Object.defineProperty;var f=(i,r,s)=>r in i?a(i,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[r]=s;var u=(i,r,s)=>(f(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})
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
 
@@ -20,4 +20,4 @@ ${e.value}
20
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(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(c=>{this.pushElement({tag:r.TD,values:o.map(h=>this.formatValue(c[h]))})}),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"})});
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.20",
4
+ "version": "0.0.21",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "scripts": {