@kklab/json2markdown 0.0.2 → 0.0.3

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,8 +1,8 @@
1
- const c = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i, f = (u) => u.replace(/[_-]/g, " ").split(" ").map((n, i) => i === 0 || !c.test(n) ? `${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()}` : n.toLowerCase()).join(" ");
2
- class p {
3
- static toMarkdown(n) {
1
+ const c = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i, f = (u) => u.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/[_-]/g, " ").split(" ").map((r, i) => r === r.toUpperCase() ? r : i === 0 || !c.test(r) ? `${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()}` : r.toLowerCase()).join(" ");
2
+ class s {
3
+ static toMarkdown(r) {
4
4
  const i = Array.from({ length: 6 }, (t, a) => `h${a + 1}`);
5
- return p.toMarkdownSchema(n).map((t) => {
5
+ return s.toMarkdownSchema(r).map((t) => {
6
6
  const a = i.findIndex((o) => t[o]);
7
7
  return a !== -1 ? `${"#".repeat(a + 1)} ${f(t[i[a]])}
8
8
 
@@ -15,35 +15,35 @@ class p {
15
15
  `;
16
16
  }).join("");
17
17
  }
18
- static toMarkdownSchema(n, i = 1, t = []) {
19
- if (!n)
18
+ static toMarkdownSchema(r, i = 1, t = []) {
19
+ if (!r)
20
20
  return [];
21
21
  const a = `h${Math.min(i, 6)}`;
22
- for (let [o, r] of Object.entries(n))
22
+ for (let [o, n] of Object.entries(r))
23
23
  if (!o.startsWith("_")) {
24
- if (o = o.trim(), typeof r == "string" && (r = r.trim().replaceAll("\\n", `
25
- `)), t.push({ [a]: o }), Array.isArray(r)) {
26
- const [e] = r;
27
- if (Array.isArray(e) && e.length > 0) {
28
- t.push({ ul: r.map((s) => JSON.stringify(s)) });
24
+ if (o = o.trim(), typeof n == "string" && (n = n.trim().replaceAll("\\n", `
25
+ `)), t.push({ [a]: o }), Array.isArray(n)) {
26
+ const [p] = n;
27
+ if (Array.isArray(p) && p.length > 0) {
28
+ t.push({ ul: n.map((e) => JSON.stringify(e)) });
29
29
  continue;
30
30
  }
31
- if (typeof e == "object") {
32
- p.toMarkdownSchema(e, i + 1, t);
31
+ if (typeof p == "object") {
32
+ s.toMarkdownSchema(p, i + 1, t);
33
33
  continue;
34
34
  }
35
- t.push({ ul: r.map((s) => typeof s == "string" ? s : JSON.stringify(s)) });
35
+ t.push({ ul: n.map((e) => typeof e == "string" ? e : JSON.stringify(e)) });
36
36
  continue;
37
37
  }
38
- if (typeof r == "object") {
39
- p.toMarkdownSchema(r, i + 1, t);
38
+ if (typeof n == "object") {
39
+ s.toMarkdownSchema(n, i + 1, t);
40
40
  continue;
41
41
  }
42
- t.push({ p: r });
42
+ t.push({ p: n });
43
43
  }
44
44
  return t;
45
45
  }
46
46
  }
47
47
  export {
48
- p as Converter
48
+ s as Converter
49
49
  };
package/dist/index.umd.js CHANGED
@@ -1,10 +1,10 @@
1
- (function(f,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(f=typeof globalThis<"u"?globalThis:f||self,s(f.JSON2MD={}))})(this,function(f){"use strict";const s=/^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i,c=y=>y.replace(/[_-]/g," ").split(" ").map((i,o)=>o===0||!s.test(i)?`${i.charAt(0).toUpperCase()}${i.slice(1).toLowerCase()}`:i.toLowerCase()).join(" ");class a{static toMarkdown(i){const o=Array.from({length:6},(t,r)=>`h${r+1}`);return a.toMarkdownSchema(i).map(t=>{const r=o.findIndex(e=>t[e]);return r!==-1?`${"#".repeat(r+1)} ${c(t[o[r]])}
1
+ (function(a,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(a=typeof globalThis<"u"?globalThis:a||self,f(a.JSON2MD={}))})(this,function(a){"use strict";const f=/^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i,c=y=>y.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replace(/[_-]/g," ").split(" ").map((n,i)=>n===n.toUpperCase()?n:i===0||!f.test(n)?`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()}`:n.toLowerCase()).join(" ");class s{static toMarkdown(n){const i=Array.from({length:6},(t,o)=>`h${o+1}`);return s.toMarkdownSchema(n).map(t=>{const o=i.findIndex(r=>t[r]);return o!==-1?`${"#".repeat(o+1)} ${c(t[i[o]])}
2
2
 
3
- `:t.ul?`${t.ul.map(e=>`- ${e}
3
+ `:t.ul?`${t.ul.map(r=>`- ${r}
4
4
  `).join("")}
5
5
  `:typeof t.p=="boolean"?`${c(String(t.p))}
6
6
 
7
7
  `:`${t.p}
8
8
 
9
- `}).join("")}static toMarkdownSchema(i,o=1,t=[]){if(!i)return[];const r=`h${Math.min(o,6)}`;for(let[e,n]of Object.entries(i))if(!e.startsWith("_")){if(e=e.trim(),typeof n=="string"&&(n=n.trim().replaceAll("\\n",`
10
- `)),t.push({[r]:e}),Array.isArray(n)){const[p]=n;if(Array.isArray(p)&&p.length>0){t.push({ul:n.map(u=>JSON.stringify(u))});continue}if(typeof p=="object"){a.toMarkdownSchema(p,o+1,t);continue}t.push({ul:n.map(u=>typeof u=="string"?u:JSON.stringify(u))});continue}if(typeof n=="object"){a.toMarkdownSchema(n,o+1,t);continue}t.push({p:n})}return t}}f.Converter=a,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
9
+ `}).join("")}static toMarkdownSchema(n,i=1,t=[]){if(!n)return[];const o=`h${Math.min(i,6)}`;for(let[r,e]of Object.entries(n))if(!r.startsWith("_")){if(r=r.trim(),typeof e=="string"&&(e=e.trim().replaceAll("\\n",`
10
+ `)),t.push({[o]:r}),Array.isArray(e)){const[u]=e;if(Array.isArray(u)&&u.length>0){t.push({ul:e.map(p=>JSON.stringify(p))});continue}if(typeof u=="object"){s.toMarkdownSchema(u,i+1,t);continue}t.push({ul:e.map(p=>typeof p=="string"?p:JSON.stringify(p))});continue}if(typeof e=="object"){s.toMarkdownSchema(e,i+1,t);continue}t.push({p:e})}return t}}a.Converter=s,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kklab/json2markdown",
3
3
  "private": false,
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "scripts": {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes