@kklab/json2markdown 0.0.1 → 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/README.md +1 -9
- package/dist/index.js +19 -19
- package/dist/index.umd.js +4 -4
- package/dist/lib/Converter.test.d.ts +1 -0
- package/dist/lib/utils/toTitleCase.test.d.ts +1 -0
- package/package.json +6 -2
- /package/dist/{Converter.d.ts → lib/Converter.d.ts} +0 -0
- /package/dist/{index.d.ts → lib/index.d.ts} +0 -0
- /package/dist/{types → lib/types}/MarkdownSchema.d.ts +0 -0
- /package/dist/{types → lib/types}/index.d.ts +0 -0
- /package/dist/{utils → lib/utils}/index.d.ts +0 -0
- /package/dist/{utils → lib/utils}/toTitleCase.d.ts +0 -0
package/README.md
CHANGED
|
@@ -2,14 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
A simple JSON to Markdown converter that transforms JSON data into easily readable text.
|
|
4
4
|
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
To install the package, run:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install @memochou1993/json2markdown
|
|
11
|
-
```
|
|
12
|
-
|
|
13
5
|
## Usage
|
|
14
6
|
|
|
15
7
|
### Using with ES Modules
|
|
@@ -17,7 +9,7 @@ npm install @memochou1993/json2markdown
|
|
|
17
9
|
Import the converter and use it in your code:
|
|
18
10
|
|
|
19
11
|
```js
|
|
20
|
-
import { Converter } from '@
|
|
12
|
+
import { Converter } from '@kklab/json2markdown';
|
|
21
13
|
|
|
22
14
|
const markdown = Converter.toMarkdown({
|
|
23
15
|
title: 'Hello, World!',
|
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"})});
|
|
@@ -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.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
@@ -33,5 +33,9 @@
|
|
|
33
33
|
"import": "./dist/index.js",
|
|
34
34
|
"require": "./dist/index.umd.js"
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"json",
|
|
39
|
+
"markdown"
|
|
40
|
+
]
|
|
37
41
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|