@kklab/json2markdown 0.0.4 → 0.0.5
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 +6 -10
- package/dist/converter/Converter.d.ts +20 -0
- package/dist/index.js +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,13 +12,11 @@ Import the converter and use it in your code:
|
|
|
12
12
|
import { Converter } from '@kklab/json2markdown';
|
|
13
13
|
|
|
14
14
|
const markdown = Converter.toMarkdown({
|
|
15
|
-
|
|
15
|
+
'Hello, World!': 'It works!',
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
// Output:
|
|
19
|
-
// #
|
|
20
|
-
//
|
|
21
|
-
// Hello, World!
|
|
18
|
+
// Output:
|
|
19
|
+
// # Hello, World!\n\nIt works!\n\n
|
|
22
20
|
```
|
|
23
21
|
|
|
24
22
|
### Using with UMD Modules
|
|
@@ -27,13 +25,11 @@ Include the UMD script in your HTML file and use it:
|
|
|
27
25
|
|
|
28
26
|
```js
|
|
29
27
|
const markdown = window.JSON2MD.Converter.toMarkdown({
|
|
30
|
-
|
|
28
|
+
'Hello, World!': 'It works!',
|
|
31
29
|
});
|
|
32
30
|
|
|
33
|
-
// Output:
|
|
34
|
-
// #
|
|
35
|
-
//
|
|
36
|
-
// Hello, World!
|
|
31
|
+
// Output:
|
|
32
|
+
// # Hello, World!\n\nIt works!\n\n
|
|
37
33
|
```
|
|
38
34
|
|
|
39
35
|
## Development
|
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
import { MarkdownSchema } from '../types';
|
|
2
2
|
declare class Converter {
|
|
3
|
+
/**
|
|
4
|
+
* Converts a given data object into a Markdown string.
|
|
5
|
+
*
|
|
6
|
+
* This method processes the data and identifies headings, unordered lists,
|
|
7
|
+
* and paragraph elements, formatting them according to Markdown syntax.
|
|
8
|
+
*
|
|
9
|
+
* @param data - A record representing the input data to be converted.
|
|
10
|
+
* @returns A string formatted in Markdown based on the input data.
|
|
11
|
+
*/
|
|
3
12
|
static toMarkdown(data: Record<string, unknown>): string;
|
|
13
|
+
/**
|
|
14
|
+
* Constructs a Markdown schema from a given data object.
|
|
15
|
+
*
|
|
16
|
+
* This method recursively traverses the data object to build a schema that
|
|
17
|
+
* identifies headings, lists, and paragraphs, which will later be converted to Markdown.
|
|
18
|
+
*
|
|
19
|
+
* @param data - A record representing the input data.
|
|
20
|
+
* @param level - The current heading level (default is 1).
|
|
21
|
+
* @param schema - An array that accumulates the schema entries (default is an empty array).
|
|
22
|
+
* @returns An array representing the schema for the Markdown conversion.
|
|
23
|
+
*/
|
|
4
24
|
static toMarkdownSchema(data: Record<string, unknown>, level?: number, schema?: MarkdownSchema[]): MarkdownSchema[];
|
|
5
25
|
}
|
|
6
26
|
export default Converter;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
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
2
|
class s {
|
|
3
|
+
/**
|
|
4
|
+
* Converts a given data object into a Markdown string.
|
|
5
|
+
*
|
|
6
|
+
* This method processes the data and identifies headings, unordered lists,
|
|
7
|
+
* and paragraph elements, formatting them according to Markdown syntax.
|
|
8
|
+
*
|
|
9
|
+
* @param data - A record representing the input data to be converted.
|
|
10
|
+
* @returns A string formatted in Markdown based on the input data.
|
|
11
|
+
*/
|
|
3
12
|
static toMarkdown(r) {
|
|
4
13
|
const i = Array.from({ length: 6 }, (t, a) => `h${a + 1}`);
|
|
5
14
|
return s.toMarkdownSchema(r).map((t) => {
|
|
@@ -15,6 +24,17 @@ class s {
|
|
|
15
24
|
`;
|
|
16
25
|
}).join("");
|
|
17
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Constructs a Markdown schema from a given data object.
|
|
29
|
+
*
|
|
30
|
+
* This method recursively traverses the data object to build a schema that
|
|
31
|
+
* identifies headings, lists, and paragraphs, which will later be converted to Markdown.
|
|
32
|
+
*
|
|
33
|
+
* @param data - A record representing the input data.
|
|
34
|
+
* @param level - The current heading level (default is 1).
|
|
35
|
+
* @param schema - An array that accumulates the schema entries (default is an empty array).
|
|
36
|
+
* @returns An array representing the schema for the Markdown conversion.
|
|
37
|
+
*/
|
|
18
38
|
static toMarkdownSchema(r, i = 1, t = []) {
|
|
19
39
|
if (!r)
|
|
20
40
|
return [];
|