react-markdown-table-ts 0.1.0 → 0.1.2
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/src/errors.d.ts +6 -0
- package/dist/{types → src}/helpers.d.ts +13 -25
- package/dist/src/index.d.ts +11 -0
- package/dist/src/types.d.ts +61 -0
- package/dist/src/utils.d.ts +44 -0
- package/dist/src/validation.d.ts +7 -0
- package/package.json +1 -1
- package/dist/types/errors.d.ts +0 -13
- package/dist/types/index.d.ts +0 -18
- package/dist/types/types.d.ts +0 -44
- package/dist/types/validation.d.ts +0 -29
@@ -1,46 +1,34 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Contains helper functions for formatting Markdown table syntax and calculating column widths.
|
3
3
|
*/
|
4
|
-
import {TableRow} from './types';
|
4
|
+
import { TableRow } from './types';
|
5
5
|
/**
|
6
6
|
* Calculates the maximum width for each column based on the content.
|
7
7
|
* @param params - The parameters for column width calculation.
|
8
8
|
* @returns An array of maximum widths for each column.
|
9
9
|
*/
|
10
|
-
export declare function calculateColumnWidths({
|
11
|
-
|
12
|
-
|
13
|
-
}: {
|
14
|
-
allRows: readonly TableRow[];
|
15
|
-
maxColumnCount: number;
|
10
|
+
export declare function calculateColumnWidths({ allRows, maxColumnCount, }: {
|
11
|
+
allRows: readonly TableRow[];
|
12
|
+
maxColumnCount: number;
|
16
13
|
}): number[];
|
17
14
|
/**
|
18
15
|
* Formats a single row into a Markdown-formatted string.
|
19
16
|
* @param params - The parameters for row formatting.
|
20
17
|
* @returns The Markdown string for the row.
|
21
18
|
*/
|
22
|
-
export declare function formatMarkdownRow({
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}: {
|
28
|
-
columnCount: number;
|
29
|
-
row: TableRow;
|
30
|
-
columnAlignments?: readonly ('left' | 'right' | 'center' | 'none')[];
|
31
|
-
columnWidths?: readonly number[];
|
19
|
+
export declare function formatMarkdownRow({ columnCount, row, columnAlignments, columnWidths, }: {
|
20
|
+
columnCount: number;
|
21
|
+
row: TableRow;
|
22
|
+
columnAlignments?: readonly ('left' | 'right' | 'center' | 'none')[];
|
23
|
+
columnWidths?: readonly number[];
|
32
24
|
}): string;
|
33
25
|
/**
|
34
26
|
* Generates the alignment row for the Markdown table syntax.
|
35
27
|
* @param params - The parameters for alignment row generation.
|
36
28
|
* @returns The Markdown string for the alignment row.
|
37
29
|
*/
|
38
|
-
export declare function formatAlignmentRow({
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
}: {
|
43
|
-
columnCount: number;
|
44
|
-
columnAlignments?: readonly ('left' | 'right' | 'center' | 'none')[];
|
45
|
-
columnWidths?: readonly number[];
|
30
|
+
export declare function formatAlignmentRow({ columnCount, columnAlignments, columnWidths, }: {
|
31
|
+
columnCount: number;
|
32
|
+
columnAlignments?: readonly ('left' | 'right' | 'center' | 'none')[];
|
33
|
+
columnWidths?: readonly number[];
|
46
34
|
}): string;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { MarkdownTableProps, TableRow } from './types';
|
3
|
+
import { MarkdownTableError } from './errors';
|
4
|
+
/**
|
5
|
+
* React component that generates and displays Markdown table syntax.
|
6
|
+
* @param props - The input parameters for table generation.
|
7
|
+
* @returns A <pre> element containing the Markdown table syntax or an error message.
|
8
|
+
*/
|
9
|
+
export declare const MarkdownTable: React.FC<MarkdownTableProps>;
|
10
|
+
export type { MarkdownTableProps, TableRow };
|
11
|
+
export { MarkdownTableError };
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/**
|
2
|
+
* Represents a single row in a table, consisting of cells.
|
3
|
+
*/
|
4
|
+
export type TableRow = readonly string[];
|
5
|
+
/**
|
6
|
+
* Represents the structure of a Markdown table.
|
7
|
+
*/
|
8
|
+
export interface MarkdownTableData {
|
9
|
+
/**
|
10
|
+
* The header row of the table.
|
11
|
+
*/
|
12
|
+
header: string[];
|
13
|
+
/**
|
14
|
+
* The body rows of the table.
|
15
|
+
*/
|
16
|
+
rows: readonly string[][];
|
17
|
+
}
|
18
|
+
/**
|
19
|
+
* Props for the MarkdownTable component.
|
20
|
+
*/
|
21
|
+
export interface MarkdownTableProps {
|
22
|
+
/**
|
23
|
+
* The entire table data as a two-dimensional array.
|
24
|
+
* If `hasHeader` is true, the first row is treated as the header.
|
25
|
+
*/
|
26
|
+
data: string[][];
|
27
|
+
/**
|
28
|
+
* Indicates whether the first row of `data` is a header.
|
29
|
+
* @default true
|
30
|
+
*/
|
31
|
+
hasHeader?: boolean;
|
32
|
+
/**
|
33
|
+
* Optional array specifying the alignment for each column.
|
34
|
+
* Acceptable values are 'left', 'center', 'right', or 'none'.
|
35
|
+
*/
|
36
|
+
columnAlignments?: readonly ('left' | 'center' | 'right' | 'none')[];
|
37
|
+
/**
|
38
|
+
* Optional flag to provide a compact version of the table with minimal column widths.
|
39
|
+
* When `true`, column widths are not adjusted based on content.
|
40
|
+
* @default false
|
41
|
+
*/
|
42
|
+
isCompact?: boolean;
|
43
|
+
/**
|
44
|
+
* Optional flag to add tabs between columns in the Markdown table.
|
45
|
+
* @default false
|
46
|
+
*/
|
47
|
+
hasTabs?: boolean;
|
48
|
+
/**
|
49
|
+
* Optional CSS class for styling the rendered Markdown table.
|
50
|
+
*/
|
51
|
+
className?: string;
|
52
|
+
/**
|
53
|
+
* Optional flag to replace newlines with <br> tags in table cells.
|
54
|
+
* @default false
|
55
|
+
*/
|
56
|
+
canReplaceNewlines?: boolean;
|
57
|
+
/**
|
58
|
+
* Optional callback function to receive the generated Markdown table string.
|
59
|
+
*/
|
60
|
+
onTableCreate?: (markdownString: string) => void;
|
61
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { TableRow, MarkdownTableData } from './types';
|
2
|
+
/**
|
3
|
+
* Calculates the maximum width for each column based on the content.
|
4
|
+
* @param allRows - All rows (header and body) of the table.
|
5
|
+
* @param maxColumnCount - The maximum number of columns in the table.
|
6
|
+
* @returns An array of maximum widths for each column.
|
7
|
+
*/
|
8
|
+
export declare function calculateColumnWidths(allRows: readonly TableRow[], maxColumnCount: number): number[];
|
9
|
+
/**
|
10
|
+
* Replaces newline characters in a string with <br> tags.
|
11
|
+
* @param cell - The cell content to process.
|
12
|
+
* @returns The processed cell content with newlines replaced.
|
13
|
+
*/
|
14
|
+
export declare function replaceNewlinesInCell(cell: string): string;
|
15
|
+
/**
|
16
|
+
* Formats a single row into a Markdown-formatted string.
|
17
|
+
* @param columnCount - The number of columns in the table.
|
18
|
+
* @param row - The data of the current row.
|
19
|
+
* @param columnAlignments - Alignment settings for each column.
|
20
|
+
* @param columnWidths - Widths of each column.
|
21
|
+
* @param useTabs - Flag to use tabs between columns.
|
22
|
+
* @param replaceNewlines - Flag to replace newlines with <br> tags.
|
23
|
+
* @returns The Markdown string for the row.
|
24
|
+
*/
|
25
|
+
export declare function formatMarkdownRow(columnCount: number, row: TableRow, columnAlignments: readonly ('left' | 'right' | 'center' | 'none')[], columnWidths?: readonly number[], useTabs?: boolean, replaceNewlines?: boolean): string;
|
26
|
+
/**
|
27
|
+
* Generates the alignment row for the Markdown table syntax.
|
28
|
+
* @param columnCount - The number of columns in the table.
|
29
|
+
* @param columnAlignments - Alignment settings for each column.
|
30
|
+
* @param columnWidths - Widths of each column.
|
31
|
+
* @param useTabs - Flag to use tabs between columns.
|
32
|
+
* @returns The Markdown string for the alignment row.
|
33
|
+
*/
|
34
|
+
export declare function formatAlignmentRow(columnCount: number, columnAlignments: readonly ('left' | 'right' | 'center' | 'none')[], columnWidths?: readonly number[], useTabs?: boolean): string;
|
35
|
+
/**
|
36
|
+
* Generates a complete Markdown table string from the provided data.
|
37
|
+
* @param tableData - The table data including headers and rows.
|
38
|
+
* @param columnAlignments - Alignment settings for each column.
|
39
|
+
* @param adjustColumnWidths - Flag to adjust column widths based on content.
|
40
|
+
* @param useTabs - Flag to use tabs between columns.
|
41
|
+
* @param replaceNewlines - Flag to replace newlines with <br> tags.
|
42
|
+
* @returns The complete Markdown table string.
|
43
|
+
*/
|
44
|
+
export declare function generateMarkdownTableString(tableData: MarkdownTableData, columnAlignments: readonly ('left' | 'right' | 'center' | 'none')[], adjustColumnWidths?: boolean, useTabs?: boolean, replaceNewlines?: boolean): string;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { MarkdownTableProps } from './types';
|
2
|
+
/**
|
3
|
+
* Validates the structure of the table data based on the `hasHeader` flag.
|
4
|
+
* Throws an error if validation fails.
|
5
|
+
* @param props - The props to validate.
|
6
|
+
*/
|
7
|
+
export declare function validateMarkdownTableProps(props: MarkdownTableProps): void;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-markdown-table-ts",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.2",
|
4
4
|
"description": "A React component that converts structured data into Markdown table syntax and displays it within a `<pre>` tag.",
|
5
5
|
"main": "dist/index.cjs.js",
|
6
6
|
"module": "dist/index.esm.js",
|
package/dist/types/errors.d.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Defines custom error classes for Markdown table syntax generation.
|
3
|
-
*/
|
4
|
-
/**
|
5
|
-
* Custom error class for handling Markdown table generation errors.
|
6
|
-
*/
|
7
|
-
export declare class MarkdownTableError extends Error {
|
8
|
-
/**
|
9
|
-
* Constructs a new MarkdownTableError.
|
10
|
-
* @param message - The error message.
|
11
|
-
*/
|
12
|
-
constructor(message: string);
|
13
|
-
}
|
package/dist/types/index.d.ts
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
import {CreateMarkdownTableOptions, MarkdownTableProps} from './types';
|
2
|
-
/**
|
3
|
-
* Generates a Markdown-formatted table as a string.
|
4
|
-
* @param options - The parameters for table generation.
|
5
|
-
* @returns The Markdown string for the entire table.
|
6
|
-
* @throws {MarkdownTableError} if input validation fails.
|
7
|
-
*/
|
8
|
-
export declare function generateMarkdownTable({
|
9
|
-
tableData,
|
10
|
-
columnAlignments,
|
11
|
-
adjustColumnWidths,
|
12
|
-
}: CreateMarkdownTableOptions): string;
|
13
|
-
/**
|
14
|
-
* React component that generates and displays Markdown table syntax.
|
15
|
-
* @param props - The input parameters for table generation.
|
16
|
-
* @returns A <pre> element containing the Markdown table syntax or an error message.
|
17
|
-
*/
|
18
|
-
export declare function MarkdownTable(props: MarkdownTableProps): JSX.Element;
|
package/dist/types/types.d.ts
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Defines types and interfaces for generating Markdown table syntax and displaying it in React components.
|
3
|
-
*/
|
4
|
-
/**
|
5
|
-
* Represents a single row in a table, consisting of cells.
|
6
|
-
*/
|
7
|
-
export type TableRow = readonly string[];
|
8
|
-
/**
|
9
|
-
* Represents the structure of a Markdown table.
|
10
|
-
*/
|
11
|
-
export interface MarkdownTableData {
|
12
|
-
/**
|
13
|
-
* The header row of the table.
|
14
|
-
*/
|
15
|
-
readonly header: TableRow;
|
16
|
-
/**
|
17
|
-
* The body rows of the table.
|
18
|
-
*/
|
19
|
-
readonly rows: readonly TableRow[];
|
20
|
-
}
|
21
|
-
/**
|
22
|
-
* Input parameters for creating a Markdown table syntax.
|
23
|
-
*/
|
24
|
-
export interface CreateMarkdownTableOptions {
|
25
|
-
/**
|
26
|
-
* The table data including headers and body rows.
|
27
|
-
*/
|
28
|
-
readonly tableData: MarkdownTableData;
|
29
|
-
/**
|
30
|
-
* Optional flag to adjust column widths based on content.
|
31
|
-
* @default true
|
32
|
-
*/
|
33
|
-
readonly adjustColumnWidths?: boolean;
|
34
|
-
/**
|
35
|
-
* Optional alignment settings for each column.
|
36
|
-
*/
|
37
|
-
readonly columnAlignments?: readonly ('left' | 'right' | 'center' | 'none')[];
|
38
|
-
}
|
39
|
-
/**
|
40
|
-
* Props for the MarkdownTable component.
|
41
|
-
*/
|
42
|
-
export interface MarkdownTableProps extends CreateMarkdownTableOptions {
|
43
|
-
className?: string;
|
44
|
-
}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Provides validation functions for inputs used in Markdown table syntax generation.
|
3
|
-
*/
|
4
|
-
import {MarkdownTableData, CreateMarkdownTableOptions} from './types';
|
5
|
-
/**
|
6
|
-
* Validates the structure of the table data.
|
7
|
-
* Throws an error if validation fails.
|
8
|
-
* @param tableData - The table data to validate.
|
9
|
-
* @throws {MarkdownTableError} if validation fails.
|
10
|
-
*/
|
11
|
-
export declare function validateTableData(tableData: MarkdownTableData): void;
|
12
|
-
/**
|
13
|
-
* Validates the column alignments array.
|
14
|
-
* Throws an error if validation fails.
|
15
|
-
* @param columnAlignments - The alignment settings to validate.
|
16
|
-
* @throws {MarkdownTableError} if validation fails.
|
17
|
-
*/
|
18
|
-
export declare function validateColumnAlignments(
|
19
|
-
columnAlignments?: readonly ('left' | 'right' | 'center' | 'none')[]
|
20
|
-
): void;
|
21
|
-
/**
|
22
|
-
* Validates the input parameters for generating the Markdown table syntax.
|
23
|
-
* Throws an error if validation fails.
|
24
|
-
* @param options - The input parameters to validate.
|
25
|
-
* @throws {MarkdownTableError} if validation fails.
|
26
|
-
*/
|
27
|
-
export declare function validateCreateMarkdownTableOptions(
|
28
|
-
options: CreateMarkdownTableOptions
|
29
|
-
): void;
|