@kklab/json2markdown 0.0.2 → 0.0.4
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarkdownSchema } from '
|
|
1
|
+
import { MarkdownSchema } from '../types';
|
|
2
2
|
declare class Converter {
|
|
3
3
|
static toMarkdown(data: Record<string, unknown>): string;
|
|
4
4
|
static toMarkdownSchema(data: Record<string, unknown>, level?: number, schema?: MarkdownSchema[]): MarkdownSchema[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { default as Converter } from './
|
|
1
|
+
import { default as Converter } from './converter';
|
|
2
2
|
export { Converter, };
|
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((
|
|
2
|
-
class
|
|
3
|
-
static toMarkdown(
|
|
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
|
|
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(
|
|
19
|
-
if (!
|
|
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,
|
|
22
|
+
for (let [o, n] of Object.entries(r))
|
|
23
23
|
if (!o.startsWith("_")) {
|
|
24
|
-
if (o = o.trim(), typeof
|
|
25
|
-
`)), t.push({ [a]: o }), Array.isArray(
|
|
26
|
-
const [
|
|
27
|
-
if (Array.isArray(
|
|
28
|
-
t.push({ ul:
|
|
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
|
|
32
|
-
|
|
31
|
+
if (typeof p == "object") {
|
|
32
|
+
s.toMarkdownSchema(p, i + 1, t);
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
|
-
t.push({ ul:
|
|
35
|
+
t.push({ ul: n.map((e) => typeof e == "string" ? e : JSON.stringify(e)) });
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
|
-
if (typeof
|
|
39
|
-
|
|
38
|
+
if (typeof n == "object") {
|
|
39
|
+
s.toMarkdownSchema(n, i + 1, t);
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
|
-
t.push({ p:
|
|
42
|
+
t.push({ p: n });
|
|
43
43
|
}
|
|
44
44
|
return t;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
export {
|
|
48
|
-
|
|
48
|
+
s as Converter
|
|
49
49
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(f
|
|
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(
|
|
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
|
|
10
|
-
`)),t.push({[
|
|
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"})});
|