@kklab/json2markdown 0.0.25 → 0.0.26

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
- var l = (n, r, t) => r in n ? h(n, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[r] = t;
3
- var u = (n, r, t) => (l(n, typeof r != "symbol" ? r + "" : r, t), t);
2
+ var l = (i, r, t) => r in i ? h(i, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[r] = t;
3
+ var u = (i, r, t) => (l(i, typeof r != "symbol" ? r + "" : r, t), t);
4
4
  const e = {
5
5
  A: "a",
6
6
  BLOCKQUOTE: "blockquote",
@@ -57,7 +57,7 @@ class a {
57
57
 
58
58
  `;
59
59
  case e.LI: {
60
- const s = (i) => i.replaceAll(`
60
+ const s = (n) => n.replaceAll(`
61
61
  `, " ").replace(new RegExp("(?<=^|\\s)(-\\s*|\\d+\\.\\s*)", "g"), (o) => o.trim());
62
62
  return `${" ".repeat(t.indent)}- ${s(t.value)}
63
63
  `;
@@ -73,7 +73,7 @@ ${t.value}
73
73
 
74
74
  `;
75
75
  case e.TD: {
76
- const s = (i) => i.replaceAll("|", "\\|").replaceAll(`
76
+ const s = (n) => n.replaceAll("|", "\\|").replaceAll(`
77
77
  `, "<br>");
78
78
  return `| ${t.values.map(s).join(" | ")} |
79
79
  `;
@@ -95,7 +95,7 @@ ${t.value}
95
95
  return t ? (this.elements.push(t), !0) : !1;
96
96
  }
97
97
  convert(r) {
98
- return r && (this.onConvert = r), Array.isArray(this.data) && this.convertFromArray(this.data), this.convertFromObject(this.data), this;
98
+ return r && (this.onConvert = r), Array.isArray(this.data) ? this.convertFromArray(this.data) : this.convertFromObject(this.data);
99
99
  }
100
100
  convertFromArray(r, t = 0) {
101
101
  if (r == null)
@@ -106,11 +106,11 @@ ${t.value}
106
106
  tag: e.TR,
107
107
  values: Object.keys(s)
108
108
  });
109
- const i = Object.keys(s);
109
+ const n = Object.keys(s);
110
110
  return r.forEach((o) => {
111
111
  this.pushElement({
112
112
  tag: e.TD,
113
- values: i.map((c) => this.formatValue(o[c]))
113
+ values: n.map((c) => this.formatValue(o[c]))
114
114
  });
115
115
  }), this;
116
116
  }
@@ -130,23 +130,23 @@ ${t.value}
130
130
  convertFromObject(r, t = 0) {
131
131
  if (r == null)
132
132
  return this.convertFromPrimitive(r), this;
133
- for (const [s, i] of Object.entries(r))
133
+ for (const [s, n] of Object.entries(r))
134
134
  if (this.pushElement({
135
135
  tag: e.HEADING,
136
136
  value: s,
137
137
  level: t + 1
138
138
  })) {
139
- if (Array.isArray(i)) {
140
- this.convertFromArray(i), this.pushElement({
139
+ if (Array.isArray(n)) {
140
+ this.convertFromArray(n), this.pushElement({
141
141
  tag: e.BR
142
142
  });
143
143
  continue;
144
144
  }
145
- if (typeof i == "object") {
146
- this.convertFromObject(i, t + 1);
145
+ if (typeof n == "object") {
146
+ this.convertFromObject(n, t + 1);
147
147
  continue;
148
148
  }
149
- this.convertFromPrimitive(i);
149
+ this.convertFromPrimitive(n);
150
150
  }
151
151
  return this;
152
152
  }
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,o)=>r in n?h(n,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[r]=o;var c=(n,r,o)=>(f(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})
1
+ (function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s.JSON2Markdown={}))})(this,function(s){"use strict";var h=Object.defineProperty;var f=(s,r,o)=>r in s?h(s,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):s[r]=o;var c=(s,r,o)=>(f(s,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:{const s=i=>i.replaceAll(`
13
- `," ").replace(new RegExp("(?<=^|\\s)(-\\s*|\\d+\\.\\s*)","g"),u=>u.trim());return`${" ".repeat(e.indent)}- ${s(e.value)}
12
+ `;case r.LI:{const n=i=>i.replaceAll(`
13
+ `," ").replace(new RegExp("(?<=^|\\s)(-\\s*|\\d+\\.\\s*)","g"),u=>u.trim());return`${" ".repeat(e.indent)}- ${n(e.value)}
14
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:{const s=i=>i.replaceAll("|","\\|").replaceAll(`
21
- `,"<br>");return`| ${e.values.map(s).join(" | ")} |
20
+ `;case r.TD:{const n=i=>i.replaceAll("|","\\|").replaceAll(`
21
+ `,"<br>");return`| ${e.values.map(n).join(" | ")} |
22
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(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"})});
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)}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 i=Object.keys(n);return t.forEach(u=>{this.pushElement({tag:r.TD,values:i.map(a=>this.formatValue(u[a]))})}),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,i]of Object.entries(t))if(this.pushElement({tag:r.HEADING,value:n,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)}}s.Converter=o,Object.defineProperty(s,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.25",
4
+ "version": "0.0.26",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "scripts": {