@thi.ng/markdown-table 0.3.83 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-09T19:12:03Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -56,7 +56,7 @@ For Node.js REPL:
56
56
  const markdownTable = await import("@thi.ng/markdown-table");
57
57
  ```
58
58
 
59
- Package sizes (brotli'd, pre-treeshake): ESM: 622 bytes
59
+ Package sizes (brotli'd, pre-treeshake): ESM: 613 bytes
60
60
 
61
61
  ## Dependencies
62
62
 
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.83",
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 clean && tsc --declaration",
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,15 +35,16 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.11",
37
- "@thi.ng/checks": "^3.4.11",
38
- "@thi.ng/compose": "^2.1.50",
39
- "@thi.ng/errors": "^2.4.5",
40
- "@thi.ng/strings": "^3.7.2",
41
- "@thi.ng/transducers": "^8.8.14"
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",
47
+ "esbuild": "^0.19.8",
45
48
  "rimraf": "^5.0.5",
46
49
  "tools": "^0.0.1",
47
50
  "typedoc": "^0.25.4",
@@ -85,5 +88,5 @@
85
88
  ],
86
89
  "year": 2021
87
90
  },
88
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
91
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
89
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
- c: center,
21
- l: padRight,
22
- r: padLeft,
20
+ c: center,
21
+ l: padRight,
22
+ r: padLeft
23
23
  };
24
24
  const SEPS = {
25
- c: (x) => `:${repeat("-", x)}:`,
26
- l: (x) => `:${repeat("-", x + 1)}`,
27
- r: (x) => `${repeat("-", x + 1)}:`,
25
+ c: (x) => `:${repeat("-", x)}:`,
26
+ l: (x) => `:${repeat("-", x + 1)}`,
27
+ r: (x) => `${repeat("-", x + 1)}:`
28
28
  };
29
- /**
30
- * Takes an array of column titles, an iterable of `rows` and (optional) table
31
- * options (e.g. column alignments). Returns string of formatted Markdown table.
32
- *
33
- * @remarks
34
- * Each `row` is a string array. Nullish cells/columns are allowed. Rows
35
- * can also be empty. By default all columns are left-aligned.
36
- *
37
- * @example
38
- * ```ts
39
- * markdownTable(
40
- * ["ID", "Actor", "Comment"],
41
- * [
42
- * [1, "Alice"],
43
- * [201, "Bob", "(foe)"],
44
- * [3003, "Charlie", null],
45
- * [44, "Dora", "(recipient)"],
46
- * ],
47
- * { bold: true, align: ["r", "c", "l"] }
48
- * );
49
- *
50
- * // | **ID** | **Actor** | **Comment** |
51
- * // |-------:|:---------:|:------------|
52
- * // | 1 | Alice | |
53
- * // | 201 | Bob | (foe) |
54
- * // | 3003 | Charlie | |
55
- * // | 44 | Dora | (recipient) |
56
- * ```
57
- *
58
- * @param header -
59
- * @param rows -
60
- * @param opts -
61
- */
62
- export const table = (header, rows, opts = {}) => {
63
- const numColumns = header.length;
64
- const align = opts.align || [...$repeat("l", numColumns)];
65
- assert(align.length === numColumns, `invalid/missing column alignments`);
66
- opts.bold && (header = header.map(wrap("**")));
67
- const body = [header, ...rows];
68
- const widths = transduce(multiplex(...[
69
- ...repeatedly((i) => comp(map((row) => row[i] != null ? String(row[i]).length : 0), scan(max())), numColumns),
70
- ]), last(), body);
71
- const pads = widths.map((w, i) => PADS[align[i]](w));
72
- const colIDs = [...range(numColumns)];
73
- const result = body.map((row) => colIDs.map((i) => `| ${pads[i](str(row[i]))} `).join("") + "|");
74
- result.splice(1, 0, widths.map((w, i) => `|${SEPS[align[i]](w)}`).join("") + "|");
75
- return result.join("\n");
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) : "");