@kklab/json2markdown 0.0.17 → 0.0.18

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 a = (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) => (a(n, typeof r != "symbol" ? r + "" : r, t), t);
2
+ var a = (s, r, t) => r in s ? h(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t;
3
+ var o = (s, r, t) => (a(s, typeof r != "symbol" ? r + "" : r, t), t);
4
4
  const e = {
5
5
  A: "a",
6
6
  BR: "br",
@@ -16,7 +16,7 @@ class c {
16
16
  constructor(r, t = {}) {
17
17
  o(this, "elements", []);
18
18
  o(this, "onConvert");
19
- this.onConvert = t.onConvert ?? ((i) => i), r && this.convert(r);
19
+ this.onConvert = t.onConvert ?? ((n) => n), r && this.convert(r);
20
20
  }
21
21
  /**
22
22
  * Converts the provided data into Markdown format.
@@ -59,7 +59,8 @@ ${r.value}
59
59
 
60
60
  `;
61
61
  case e.TD:
62
- return `| ${r.values.join(" | ")} |
62
+ return `| ${r.values.map((t) => typeof t == "string" ? t.replaceAll(`
63
+ `, "<br>") : t).join(" | ")} |
63
64
  `;
64
65
  case e.TR:
65
66
  return `| ${r.values.join(" | ")} |
@@ -87,26 +88,26 @@ ${r.value}
87
88
  convertFromArray(r, t = 0) {
88
89
  if (r == null)
89
90
  return this.convertFromPrimitive(r), this;
90
- if (r.length > 0 && r.every((i) => typeof i == "object" && i !== null && Object.keys(i).length > 0)) {
91
- const [i] = r;
91
+ if (r.length > 0 && r.every((n) => typeof n == "object" && n !== null && Object.keys(n).length > 0)) {
92
+ const [n] = r;
92
93
  return this.pushElement({
93
94
  tag: e.TR,
94
- values: Object.keys(i)
95
- }), r.forEach((s) => {
95
+ values: Object.keys(n)
96
+ }), r.forEach((i) => {
96
97
  this.pushElement({
97
98
  tag: e.TD,
98
- values: Object.values(s).map((u) => this.formatValue(u))
99
+ values: Object.values(i).map((u) => this.formatValue(u))
99
100
  });
100
101
  }), this;
101
102
  }
102
- for (const i of r) {
103
- if (Array.isArray(i)) {
104
- this.convertFromArray(i, t + 1);
103
+ for (const n of r) {
104
+ if (Array.isArray(n)) {
105
+ this.convertFromArray(n, t + 1);
105
106
  continue;
106
107
  }
107
108
  this.pushElement({
108
109
  tag: e.LI,
109
- value: this.formatValue(i),
110
+ value: this.formatValue(n),
110
111
  indent: t
111
112
  });
112
113
  }
@@ -115,23 +116,23 @@ ${r.value}
115
116
  convertFromObject(r, t = 0) {
116
117
  if (r == null)
117
118
  return this.convertFromPrimitive(r), this;
118
- for (const [i, s] of Object.entries(r))
119
+ for (const [n, i] of Object.entries(r))
119
120
  if (this.pushElement({
120
121
  tag: e.HEADING,
121
- value: i,
122
+ value: n,
122
123
  level: t + 1
123
124
  })) {
124
- if (Array.isArray(s)) {
125
- this.convertFromArray(s), this.pushElement({
125
+ if (Array.isArray(i)) {
126
+ this.convertFromArray(i), this.pushElement({
126
127
  tag: e.BR
127
128
  });
128
129
  continue;
129
130
  }
130
- if (typeof s == "object") {
131
- this.convertFromObject(s, t + 1);
131
+ if (typeof i == "object") {
132
+ this.convertFromObject(i, t + 1);
132
133
  continue;
133
134
  }
134
- this.convertFromPrimitive(s);
135
+ this.convertFromPrimitive(i);
135
136
  }
136
137
  return this;
137
138
  }
package/dist/index.umd.js CHANGED
@@ -12,7 +12,8 @@
12
12
  ${r.value}
13
13
  \`\`\`
14
14
 
15
- `;case t.TD:return`| ${r.values.join(" | ")} |
15
+ `;case t.TD:return`| ${r.values.map(e=>typeof e=="string"?e.replaceAll(`
16
+ `,"<br>"):e).join(" | ")} |
16
17
  `;case t.TR:return`| ${r.values.join(" | ")} |
17
18
  | ${r.values.map(()=>"---").join(" | ")} |
18
19
  `;default:return""}}).join("")}getElements(){return this.elements}pushElement(r){const e=this.onConvert(r);return e?(this.elements.push(e),!0):!1}convert(r){if(Array.isArray(r)){this.convertFromArray(r);return}this.convertFromObject(r)}convertFromArray(r,e=0){if(r==null)return this.convertFromPrimitive(r),this;if(r.length>0&&r.every(n=>typeof n=="object"&&n!==null&&Object.keys(n).length>0)){const[n]=r;return this.pushElement({tag:t.TR,values:Object.keys(n)}),r.forEach(o=>{this.pushElement({tag:t.TD,values:Object.values(o).map(c=>this.formatValue(c))})}),this}for(const n of r){if(Array.isArray(n)){this.convertFromArray(n,e+1);continue}this.pushElement({tag:t.LI,value:this.formatValue(n),indent:e})}return this}convertFromObject(r,e=0){if(r==null)return this.convertFromPrimitive(r),this;for(const[n,o]of Object.entries(r))if(this.pushElement({tag:t.HEADING,value:n,level:e+1})){if(Array.isArray(o)){this.convertFromArray(o),this.pushElement({tag:t.BR});continue}if(typeof o=="object"){this.convertFromObject(o,e+1);continue}this.convertFromPrimitive(o)}return this}convertFromPrimitive(r){return this.pushElement({tag:t.P,value:this.formatValue(r)}),this}formatValue(r){return r==null?"":Array.isArray(r)?r.map(e=>this.formatValue(e)).join(", "):typeof r=="object"?JSON.stringify(r):typeof r=="string"?r.trim():r}}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.17",
4
+ "version": "0.0.18",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -9,11 +9,13 @@
9
9
  "build": "tsc -p ./tsconfig.build.json && vite build",
10
10
  "preview": "vite preview",
11
11
  "lint": "eslint .",
12
- "test": "vitest"
12
+ "test": "npm run test:unit -- --run",
13
+ "test:unit": "vitest",
14
+ "release": "npm run test && npm run build && npm publish --access public"
13
15
  },
14
16
  "devDependencies": {
15
17
  "@eslint/js": "^9.11.0",
16
- "@kklab/stryle": "^0.0.2",
18
+ "@kklab/stryle": "^0.0.10",
17
19
  "@stylistic/eslint-plugin": "^2.9.0",
18
20
  "@types/eslint__js": "^8.42.3",
19
21
  "@types/node": "^22.5.5",