@kklab/json2markdown 0.0.22 → 0.0.23

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
1
  var h = Object.defineProperty;
2
2
  var l = (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) => (l(n, typeof r != "symbol" ? r + "" : r, t), t);
3
+ var u = (n, r, t) => (l(n, typeof r != "symbol" ? r + "" : r, t), t);
4
4
  const e = {
5
5
  A: "a",
6
6
  BLOCKQUOTE: "blockquote",
@@ -16,9 +16,9 @@ const e = {
16
16
  };
17
17
  class a {
18
18
  constructor(r) {
19
- o(this, "data");
20
- o(this, "elements", []);
21
- o(this, "onConvert", (r) => r);
19
+ u(this, "data");
20
+ u(this, "elements", []);
21
+ u(this, "onConvert", (r) => r);
22
22
  this.data = typeof r == "string" ? JSON.parse(r) : r;
23
23
  }
24
24
  /**
@@ -56,10 +56,12 @@ class a {
56
56
  return `![${t.alt}](${t.src})
57
57
 
58
58
  `;
59
- case e.LI:
60
- return `${" ".repeat(t.indent)}- ${t.value.replaceAll(`
61
- `, " ").replace(new RegExp("(?<=^|\\s)(-\\s*|\\d+\\.\\s*)", "g"), (s) => s.trim())}
59
+ case e.LI: {
60
+ const s = (i) => i.replaceAll(`
61
+ `, " ").replace(new RegExp("(?<=^|\\s)(-\\s*|\\d+\\.\\s*)", "g"), (o) => o.trim());
62
+ return `${" ".repeat(t.indent)}- ${s(t.value)}
62
63
  `;
64
+ }
63
65
  case e.P:
64
66
  return `${t.value}
65
67
 
@@ -70,10 +72,12 @@ ${t.value}
70
72
  \`\`\`
71
73
 
72
74
  `;
73
- case e.TD:
74
- return `| ${t.values.map((s) => s.replaceAll(`
75
- `, "<br>").replaceAll("|", "\\|")).join(" | ")} |
75
+ case e.TD: {
76
+ const s = (i) => i.replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("|", "\\|").replaceAll(`
77
+ `, "<br>");
78
+ return `| ${t.values.map(s).join(" | ")} |
76
79
  `;
80
+ }
77
81
  case e.TR:
78
82
  return `| ${t.values.join(" | ")} |
79
83
  | ${t.values.map(() => "---").join(" | ")} |
@@ -103,10 +107,10 @@ ${t.value}
103
107
  values: Object.keys(s)
104
108
  });
105
109
  const i = Object.keys(s);
106
- return r.forEach((u) => {
110
+ return r.forEach((o) => {
107
111
  this.pushElement({
108
112
  tag: e.TD,
109
- values: i.map((c) => this.formatValue(u[c]))
113
+ values: i.map((c) => this.formatValue(o[c]))
110
114
  });
111
115
  }), this;
112
116
  }
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 h=Object.defineProperty;var f=(n,r,s)=>r in n?h(n,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[r]=s;var u=(n,r,s)=>(f(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(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 h=Object.defineProperty;var l=(n,r,o)=>r in n?h(n,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[r]=o;var c=(n,r,o)=>(l(n,typeof r!="symbol"?r+"":r,o),o);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 o{constructor(t){c(this,"data");c(this,"elements",[]);c(this,"onConvert",t=>t);this.data=typeof t=="string"?JSON.parse(t):t}static toMarkdown(t,e){return new o(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
 
@@ -9,16 +9,16 @@
9
9
 
10
10
  `;case r.IMG:return`![${e.alt}](${e.src})
11
11
 
12
- `;case r.LI:return`${" ".repeat(e.indent)}- ${e.value.replaceAll(`
13
- `," ").replace(new RegExp("(?<=^|\\s)(-\\s*|\\d+\\.\\s*)","g"),i=>i.trim())}
14
- `;case r.P:return`${e.value}
12
+ `;case r.LI:{const s=i=>i.replaceAll(`
13
+ `," ").replace(new RegExp("(?<=^|\\s)(-\\s*|\\d+\\.\\s*)","g"),u=>u.trim());return`${" ".repeat(e.indent)}- ${s(e.value)}
14
+ `}case r.P:return`${e.value}
15
15
 
16
16
  `;case r.PRE:return`\`\`\`
17
17
  ${e.value}
18
18
  \`\`\`
19
19
 
20
- `;case r.TD:return`| ${e.values.map(i=>i.replaceAll(`
21
- `,"<br>").replaceAll("|","\\|")).join(" | ")} |
22
- `;case r.TR:return`| ${e.values.join(" | ")} |
20
+ `;case r.TD:{const s=i=>i.replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll("|","\\|").replaceAll(`
21
+ `,"<br>");return`| ${e.values.map(s).join(" | ")} |
22
+ `}case r.TR:return`| ${e.values.join(" | ")} |
23
23
  | ${e.values.map(()=>"---").join(" | ")} |
24
- `;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;this.pushElement({tag:r.TR,values:Object.keys(i)});const o=Object.keys(i);return t.forEach(a=>{this.pushElement({tag:r.TD,values:o.map(c=>this.formatValue(a[c]))})}),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():String(t)}}n.Converter=s,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
24
+ `;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(s=>typeof s=="object"&&s!==null&&Object.keys(s).length>0)){const[s]=t;this.pushElement({tag:r.TR,values:Object.keys(s)});const i=Object.keys(s);return t.forEach(u=>{this.pushElement({tag:r.TD,values:i.map(a=>this.formatValue(u[a]))})}),this}for(const s of t){if(Array.isArray(s)){this.convertFromArray(s,e+1);continue}this.pushElement({tag:r.LI,value:this.formatValue(s),indent:e})}return this}convertFromObject(t,e=0){if(t==null)return this.convertFromPrimitive(t),this;for(const[s,i]of Object.entries(t))if(this.pushElement({tag:r.HEADING,value:s,level:e+1})){if(Array.isArray(i)){this.convertFromArray(i),this.pushElement({tag:r.BR});continue}if(typeof i=="object"){this.convertFromObject(i,e+1);continue}this.convertFromPrimitive(i)}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():String(t)}}n.Converter=o,Object.defineProperty(n,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.22",
4
+ "version": "0.0.23",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "scripts": {