@thi.ng/markdown-table 0.3.82 → 0.3.84
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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +0 -1
- package/package.json +12 -10
- package/table.js +55 -89
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/api.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/markdown-table",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.84",
|
|
4
4
|
"description": "Markdown table formatter/generator with support for column alignments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,16 +35,16 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/checks": "^3.4.
|
|
38
|
-
"@thi.ng/compose": "^2.1.
|
|
39
|
-
"@thi.ng/errors": "^2.4.
|
|
40
|
-
"@thi.ng/strings": "^3.7.
|
|
41
|
-
"@thi.ng/transducers": "^8.8.
|
|
38
|
+
"@thi.ng/api": "^8.9.12",
|
|
39
|
+
"@thi.ng/checks": "^3.4.12",
|
|
40
|
+
"@thi.ng/compose": "^2.1.51",
|
|
41
|
+
"@thi.ng/errors": "^2.4.6",
|
|
42
|
+
"@thi.ng/strings": "^3.7.3",
|
|
43
|
+
"@thi.ng/transducers": "^8.8.15"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@microsoft/api-extractor": "^7.38.3",
|
|
45
|
-
"
|
|
47
|
+
"esbuild": "^0.19.8",
|
|
46
48
|
"rimraf": "^5.0.5",
|
|
47
49
|
"tools": "^0.0.1",
|
|
48
50
|
"typedoc": "^0.25.4",
|
|
@@ -86,5 +88,5 @@
|
|
|
86
88
|
],
|
|
87
89
|
"year": 2021
|
|
88
90
|
},
|
|
89
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
90
92
|
}
|
package/table.js
CHANGED
|
@@ -17,96 +17,62 @@ import { repeatedly } from "@thi.ng/transducers/repeatedly";
|
|
|
17
17
|
import { scan } from "@thi.ng/transducers/scan";
|
|
18
18
|
import { transduce } from "@thi.ng/transducers/transduce";
|
|
19
19
|
const PADS = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
c: center,
|
|
21
|
+
l: padRight,
|
|
22
|
+
r: padLeft
|
|
23
23
|
};
|
|
24
24
|
const SEPS = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
c: (x) => `:${repeat("-", x)}:`,
|
|
26
|
+
l: (x) => `:${repeat("-", x + 1)}`,
|
|
27
|
+
r: (x) => `${repeat("-", x + 1)}:`
|
|
28
28
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
29
|
+
const table = (header, rows, opts = {}) => {
|
|
30
|
+
const numColumns = header.length;
|
|
31
|
+
const align = opts.align || [...$repeat("l", numColumns)];
|
|
32
|
+
assert(align.length === numColumns, `invalid/missing column alignments`);
|
|
33
|
+
opts.bold && (header = header.map(wrap("**")));
|
|
34
|
+
const body = [header, ...rows];
|
|
35
|
+
const widths = transduce(
|
|
36
|
+
multiplex(
|
|
37
|
+
...[
|
|
38
|
+
...repeatedly(
|
|
39
|
+
(i) => comp(
|
|
40
|
+
map(
|
|
41
|
+
(row) => row[i] != null ? String(row[i]).length : 0
|
|
42
|
+
),
|
|
43
|
+
scan(max())
|
|
44
|
+
),
|
|
45
|
+
numColumns
|
|
46
|
+
)
|
|
47
|
+
]
|
|
48
|
+
),
|
|
49
|
+
last(),
|
|
50
|
+
body
|
|
51
|
+
);
|
|
52
|
+
const pads = widths.map((w, i) => PADS[align[i]](w));
|
|
53
|
+
const colIDs = [...range(numColumns)];
|
|
54
|
+
const result = body.map(
|
|
55
|
+
(row) => colIDs.map((i) => `| ${pads[i](str(row[i]))} `).join("") + "|"
|
|
56
|
+
);
|
|
57
|
+
result.splice(
|
|
58
|
+
1,
|
|
59
|
+
0,
|
|
60
|
+
widths.map((w, i) => `|${SEPS[align[i]](w)}`).join("") + "|"
|
|
61
|
+
);
|
|
62
|
+
return result.join("\n");
|
|
63
|
+
};
|
|
64
|
+
const tableKeys = (headers, keys, items, opts) => table(
|
|
65
|
+
headers,
|
|
66
|
+
map(
|
|
67
|
+
juxt(
|
|
68
|
+
...keys.map((k) => isString(k) ? (x) => str(x[k]) : k)
|
|
69
|
+
),
|
|
70
|
+
items
|
|
71
|
+
),
|
|
72
|
+
opts
|
|
73
|
+
);
|
|
74
|
+
const str = (x) => x != null ? String(x) : "";
|
|
75
|
+
export {
|
|
76
|
+
table,
|
|
77
|
+
tableKeys
|
|
76
78
|
};
|
|
77
|
-
/**
|
|
78
|
-
* Similar to {@link table}, however accepts rows as objects and looks up column
|
|
79
|
-
* values using given `keys` array.
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```ts
|
|
83
|
-
* tableKeys(
|
|
84
|
-
* ["ID", "Actor", "Comment"],
|
|
85
|
-
* ["id", "name", (x) => x.hint],
|
|
86
|
-
* [
|
|
87
|
-
* { id: 1, name: "Alice" },
|
|
88
|
-
* { id: 201, name: "Bob", hint: "(foe)" },
|
|
89
|
-
* { id: 3003, name: "Charlie" },
|
|
90
|
-
* { id: 44, name: "Dora", hint: "(recipient)" },
|
|
91
|
-
* ],
|
|
92
|
-
* { bold: true, align: ["r", "c", "l"] }
|
|
93
|
-
* )
|
|
94
|
-
*
|
|
95
|
-
* // | **ID** | **Actor** | **Comment** |
|
|
96
|
-
* // |-------:|:---------:|:------------|
|
|
97
|
-
* // | 1 | Alice | |
|
|
98
|
-
* // | 201 | Bob | (foe) |
|
|
99
|
-
* // | 3003 | Charlie | |
|
|
100
|
-
* // | 44 | Dora | (recipient) |
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* @param headers -
|
|
104
|
-
* @param keys -
|
|
105
|
-
* @param items -
|
|
106
|
-
* @param opts -
|
|
107
|
-
*/
|
|
108
|
-
export const tableKeys = (headers, keys, items, opts) => table(headers, map(juxt(
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
...keys.map((k) => (isString(k) ? (x) => str(x[k]) : k))), items), opts);
|
|
111
|
-
/** @internal */
|
|
112
|
-
const str = (x) => (x != null ? String(x) : "");
|