@thi.ng/transclude 0.1.51 → 0.1.53

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-03T12:13:31Z
3
+ - **Last updated**: 2023-12-18T13:41:20Z
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
@@ -55,7 +55,7 @@ For Node.js REPL:
55
55
  const transclude = await import("@thi.ng/transclude");
56
56
  ```
57
57
 
58
- Package sizes (brotli'd, pre-treeshake): ESM: 1.86 KB
58
+ Package sizes (brotli'd, pre-treeshake): ESM: 1.84 KB
59
59
 
60
60
  ## Dependencies
61
61
 
package/api.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/transclude",
3
- "version": "0.1.51",
3
+ "version": "0.1.53",
4
4
  "description": "Extensible functional template engine for text document generation, incl. various high-level Markdown features",
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 tpl",
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,17 @@
33
35
  "test": "testament test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.11",
37
- "@thi.ng/checks": "^3.4.11",
38
- "@thi.ng/file-io": "^1.0.4",
39
- "@thi.ng/logger": "^2.0.1",
40
- "@thi.ng/strings": "^3.7.2",
41
- "@thi.ng/transducers": "^8.8.14"
38
+ "@thi.ng/api": "^8.9.13",
39
+ "@thi.ng/checks": "^3.4.13",
40
+ "@thi.ng/file-io": "^1.1.0",
41
+ "@thi.ng/logger": "^2.1.0",
42
+ "@thi.ng/strings": "^3.7.4",
43
+ "@thi.ng/transducers": "^8.8.16"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@microsoft/api-extractor": "^7.38.3",
45
- "@thi.ng/testament": "^0.4.4",
47
+ "@thi.ng/testament": "^0.4.6",
48
+ "esbuild": "^0.19.8",
46
49
  "rimraf": "^5.0.5",
47
50
  "tools": "^0.0.1",
48
51
  "typedoc": "^0.25.4",
@@ -69,7 +72,7 @@
69
72
  "setTimeout": false
70
73
  },
71
74
  "engines": {
72
- "node": ">=14"
75
+ "node": ">=18"
73
76
  },
74
77
  "files": [
75
78
  "./*.js",
@@ -108,5 +111,5 @@
108
111
  "status": "alpha",
109
112
  "year": 2022
110
113
  },
111
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
114
+ "gitHead": "25a42a81fac8603a1e440a7aa8bc343276211ff4\n"
112
115
  }
package/tpl/file.js CHANGED
@@ -1,20 +1,11 @@
1
1
  import { readText } from "@thi.ng/file-io";
2
2
  import { resolve } from "path";
3
- /**
4
- * Parametric template function. Includes file given as template argument:
5
- * `{{include header.md}}`
6
- *
7
- * @param ctx
8
- * @param args
9
- * @param currPath
10
- */
11
- export const includeFile = ({ logger }, args, currPath) => readText(resolve(resolve(currPath, ".."), args[2].trim()), logger);
12
- /**
13
- * Pre-processing stage parametric template function. Includes file given as
14
- * template argument: `<!-- include header.md -->`.
15
- *
16
- * @param ctx
17
- * @param args
18
- * @param currPath
19
- */
20
- export const preincludeFile = ({ logger }, [src], currPath) => src.replace(new RegExp(`<!-- include (.+) -->`, "g"), (_, path) => readText(resolve(resolve(currPath, ".."), path.trim()), logger));
3
+ const includeFile = ({ logger }, args, currPath) => readText(resolve(resolve(currPath, ".."), args[2].trim()), logger);
4
+ const preincludeFile = ({ logger }, [src], currPath) => src.replace(
5
+ new RegExp(`<!-- include (.+) -->`, "g"),
6
+ (_, path) => readText(resolve(resolve(currPath, ".."), path.trim()), logger)
7
+ );
8
+ export {
9
+ includeFile,
10
+ preincludeFile
11
+ };
package/tpl/markdown.js CHANGED
@@ -6,30 +6,43 @@ import { filter } from "@thi.ng/transducers/filter";
6
6
  import { map } from "@thi.ng/transducers/map";
7
7
  import { str } from "@thi.ng/transducers/str";
8
8
  import { transduce } from "@thi.ng/transducers/transduce";
9
- export const image = (url, alt = "") => `![${alt}](${url})`;
10
- export const link = (title, href) => `[${title}](${href})`;
11
- export const list = (items, eol = "\n") => transduce(map((x) => `- ${x}`), str(eol), items);
12
- /**
13
- * Higher order, configurable post-processing template function. Injects a table
14
- * of contents for the first `<!-- toc -->` occurrence. See {@link TOCOpts} for
15
- * config options.
16
- *
17
- * @param opts
18
- */
19
- export const toc = (opts) => ({ src, eol }) => {
20
- const { min, max, match, disable, title } = {
21
- min: 2,
22
- max: 4,
23
- match: "<!-- toc -->",
24
- disable: /<\!-- notoc -->/i,
25
- ...opts,
26
- };
27
- const isHeading = new RegExp(`^#{${min},${max}}\\s`);
28
- const reHeading = new RegExp(`^(#{${min},${max}})\\s(.+)`);
29
- const toc = transduce(comp(filter((line) => isHeading.test(line) && !disable.test(line)), map((hd) => {
30
- const [_, level, title] = reHeading.exec(hd);
31
- const indent = repeat(" ", Math.max(0, level.length - min));
32
- return `${indent}- ${link(title, `#${slugifyGH(title)}`)}`;
33
- })), str(eol), split(src));
34
- return src.replace(match, title ? title + toc : toc);
9
+ const image = (url, alt = "") => `![${alt}](${url})`;
10
+ const link = (title, href) => `[${title}](${href})`;
11
+ const list = (items, eol = "\n") => transduce(
12
+ map((x) => `- ${x}`),
13
+ str(eol),
14
+ items
15
+ );
16
+ const toc = (opts) => ({ src, eol }) => {
17
+ const { min, max, match, disable, title } = {
18
+ min: 2,
19
+ max: 4,
20
+ match: "<!-- toc -->",
21
+ disable: /<\!-- notoc -->/i,
22
+ ...opts
23
+ };
24
+ const isHeading = new RegExp(`^#{${min},${max}}\\s`);
25
+ const reHeading = new RegExp(`^(#{${min},${max}})\\s(.+)`);
26
+ const toc2 = transduce(
27
+ comp(
28
+ filter((line) => isHeading.test(line) && !disable.test(line)),
29
+ map((hd) => {
30
+ const [_, level, title2] = reHeading.exec(hd);
31
+ const indent = repeat(
32
+ " ",
33
+ Math.max(0, level.length - min)
34
+ );
35
+ return `${indent}- ${link(title2, `#${slugifyGH(title2)}`)}`;
36
+ })
37
+ ),
38
+ str(eol),
39
+ split(src)
40
+ );
41
+ return src.replace(match, title ? title + toc2 : toc2);
42
+ };
43
+ export {
44
+ image,
45
+ link,
46
+ list,
47
+ toc
35
48
  };
package/tpl/pkg.js CHANGED
@@ -1,219 +1,180 @@
1
1
  import { isString } from "@thi.ng/checks/is-string";
2
2
  import { link, list } from "./markdown.js";
3
- export const LICENSES = {
4
- "Apache-2.0": {
5
- name: "Apache License 2.0",
6
- url: "https://spdx.org/licenses/Apache-2.0.html",
7
- },
8
- "BSD-2-Clause": {
9
- name: 'BSD 2-Clause "Simplified" License',
10
- url: "https://spdx.org/licenses/BSD-2-Clause.html",
11
- },
12
- "BSD-3-Clause": {
13
- name: 'BSD 3-Clause "New" or "Revised" License',
14
- url: "https://spdx.org/licenses/BSD-3-Clause.html",
15
- },
16
- "CC-BY-4.0": {
17
- name: "Creative Commons Attribution 4.0 International",
18
- url: "https://spdx.org/licenses/CC-BY-4.0.html",
19
- },
20
- "CC-BY-NC-4.0": {
21
- name: "Creative Commons Attribution Non Commercial 4.0 International",
22
- url: "https://spdx.org/licenses/CC-BY-NC-4.0.html",
23
- },
24
- "CC-BY-NC-ND-4.0": {
25
- name: "Creative Commons Attribution Non Commercial No Derivatives 4.0 International",
26
- url: "https://spdx.org/licenses/CC-BY-NC-ND-4.0.html",
27
- },
28
- "CC-BY-NC-SA-4.0": {
29
- name: "Creative Commons Attribution Non Commercial Share Alike 4.0 International",
30
- url: "https://spdx.org/licenses/CC-BY-NC-SA-4.0.html",
31
- },
32
- "CC-BY-ND-4.0": {
33
- name: "Creative Commons Attribution No Derivatives 4.0 International",
34
- url: "https://spdx.org/licenses/CC-BY-ND-4.0.html",
35
- },
36
- "CC-BY-SA-4.0": {
37
- name: "Creative Commons Attribution Share Alike 4.0 International",
38
- url: "https://spdx.org/licenses/CC-BY-SA-4.0.html",
39
- },
40
- "CPAL-1.0": {
41
- name: "Common Public Attribution License 1.0",
42
- url: "https://spdx.org/licenses/CPAL-1.0.html",
43
- },
44
- "CPL-1.0": {
45
- name: "Common Public License 1.0",
46
- url: "https://spdx.org/licenses/CPL-1.0.html",
47
- },
48
- "ECL-2.0": {
49
- name: "Educational Community License v2.0",
50
- url: "https://spdx.org/licenses/ECL-2.0.html",
51
- },
52
- "EPL-2.0": {
53
- name: "Eclipse Public License 2.0",
54
- url: "https://spdx.org/licenses/EPL-2.0.html",
55
- },
56
- EUDatagrid: {
57
- name: "EU DataGrid Software License",
58
- url: "https://spdx.org/licenses/EUDatagrid.html",
59
- },
60
- "EUPL-1.2": {
61
- name: "European Union Public License 1.2",
62
- url: "https://spdx.org/licenses/EUPL-1.2.html",
63
- },
64
- "GFDL-1.3-or-later": {
65
- name: "GNU Free Documentation License v1.3 or later",
66
- url: "https://spdx.org/licenses/GFDL-1.3-or-later.html",
67
- },
68
- "GPL-3.0-or-later": {
69
- name: "GNU General Public License v3.0 or later",
70
- url: "https://spdx.org/licenses/GPL-3.0-or-later.html",
71
- },
72
- ISC: { name: "ISC License", url: "https://spdx.org/licenses/ISC.html" },
73
- "LGPL-3.0-or-later": {
74
- name: "GNU Lesser General Public License v3.0 or later",
75
- url: "https://spdx.org/licenses/LGPL-3.0-or-later.html",
76
- },
77
- MIT: { name: "MIT License", url: "https://spdx.org/licenses/MIT.html" },
78
- "MPL-2.0": {
79
- name: "Mozilla Public License 2.0",
80
- url: "https://spdx.org/licenses/MPL-2.0.html",
81
- },
82
- "OFL-1.1": {
83
- name: "SIL Open Font License 1.1",
84
- url: "https://spdx.org/licenses/OFL-1.1.html",
85
- },
86
- Unlicense: {
87
- name: "The Unlicense",
88
- url: "https://spdx.org/licenses/Unlicense.html",
89
- },
90
- "UPL-1.0": {
91
- name: "Universal Permissive License v1.0",
92
- url: "https://spdx.org/licenses/UPL-1.0.html",
93
- },
94
- Zlib: { name: "zlib License", url: "https://spdx.org/licenses/Zlib.html" },
3
+ const LICENSES = {
4
+ "Apache-2.0": {
5
+ name: "Apache License 2.0",
6
+ url: "https://spdx.org/licenses/Apache-2.0.html"
7
+ },
8
+ "BSD-2-Clause": {
9
+ name: 'BSD 2-Clause "Simplified" License',
10
+ url: "https://spdx.org/licenses/BSD-2-Clause.html"
11
+ },
12
+ "BSD-3-Clause": {
13
+ name: 'BSD 3-Clause "New" or "Revised" License',
14
+ url: "https://spdx.org/licenses/BSD-3-Clause.html"
15
+ },
16
+ "CC-BY-4.0": {
17
+ name: "Creative Commons Attribution 4.0 International",
18
+ url: "https://spdx.org/licenses/CC-BY-4.0.html"
19
+ },
20
+ "CC-BY-NC-4.0": {
21
+ name: "Creative Commons Attribution Non Commercial 4.0 International",
22
+ url: "https://spdx.org/licenses/CC-BY-NC-4.0.html"
23
+ },
24
+ "CC-BY-NC-ND-4.0": {
25
+ name: "Creative Commons Attribution Non Commercial No Derivatives 4.0 International",
26
+ url: "https://spdx.org/licenses/CC-BY-NC-ND-4.0.html"
27
+ },
28
+ "CC-BY-NC-SA-4.0": {
29
+ name: "Creative Commons Attribution Non Commercial Share Alike 4.0 International",
30
+ url: "https://spdx.org/licenses/CC-BY-NC-SA-4.0.html"
31
+ },
32
+ "CC-BY-ND-4.0": {
33
+ name: "Creative Commons Attribution No Derivatives 4.0 International",
34
+ url: "https://spdx.org/licenses/CC-BY-ND-4.0.html"
35
+ },
36
+ "CC-BY-SA-4.0": {
37
+ name: "Creative Commons Attribution Share Alike 4.0 International",
38
+ url: "https://spdx.org/licenses/CC-BY-SA-4.0.html"
39
+ },
40
+ "CPAL-1.0": {
41
+ name: "Common Public Attribution License 1.0",
42
+ url: "https://spdx.org/licenses/CPAL-1.0.html"
43
+ },
44
+ "CPL-1.0": {
45
+ name: "Common Public License 1.0",
46
+ url: "https://spdx.org/licenses/CPL-1.0.html"
47
+ },
48
+ "ECL-2.0": {
49
+ name: "Educational Community License v2.0",
50
+ url: "https://spdx.org/licenses/ECL-2.0.html"
51
+ },
52
+ "EPL-2.0": {
53
+ name: "Eclipse Public License 2.0",
54
+ url: "https://spdx.org/licenses/EPL-2.0.html"
55
+ },
56
+ EUDatagrid: {
57
+ name: "EU DataGrid Software License",
58
+ url: "https://spdx.org/licenses/EUDatagrid.html"
59
+ },
60
+ "EUPL-1.2": {
61
+ name: "European Union Public License 1.2",
62
+ url: "https://spdx.org/licenses/EUPL-1.2.html"
63
+ },
64
+ "GFDL-1.3-or-later": {
65
+ name: "GNU Free Documentation License v1.3 or later",
66
+ url: "https://spdx.org/licenses/GFDL-1.3-or-later.html"
67
+ },
68
+ "GPL-3.0-or-later": {
69
+ name: "GNU General Public License v3.0 or later",
70
+ url: "https://spdx.org/licenses/GPL-3.0-or-later.html"
71
+ },
72
+ ISC: { name: "ISC License", url: "https://spdx.org/licenses/ISC.html" },
73
+ "LGPL-3.0-or-later": {
74
+ name: "GNU Lesser General Public License v3.0 or later",
75
+ url: "https://spdx.org/licenses/LGPL-3.0-or-later.html"
76
+ },
77
+ MIT: { name: "MIT License", url: "https://spdx.org/licenses/MIT.html" },
78
+ "MPL-2.0": {
79
+ name: "Mozilla Public License 2.0",
80
+ url: "https://spdx.org/licenses/MPL-2.0.html"
81
+ },
82
+ "OFL-1.1": {
83
+ name: "SIL Open Font License 1.1",
84
+ url: "https://spdx.org/licenses/OFL-1.1.html"
85
+ },
86
+ Unlicense: {
87
+ name: "The Unlicense",
88
+ url: "https://spdx.org/licenses/Unlicense.html"
89
+ },
90
+ "UPL-1.0": {
91
+ name: "Universal Permissive License v1.0",
92
+ url: "https://spdx.org/licenses/UPL-1.0.html"
93
+ },
94
+ Zlib: { name: "zlib License", url: "https://spdx.org/licenses/Zlib.html" }
95
+ };
96
+ const shortName = (name) => {
97
+ const idx = name.indexOf("/");
98
+ return idx > 0 ? name.substring(idx + 1) : name;
95
99
  };
96
- /**
97
- * Returns the unscoped name of a package, i.e. the name without the package's
98
- * group ID (if any).
99
- *
100
- * @param name
101
- */
102
- export const shortName = (name) => {
103
- const idx = name.indexOf("/");
104
- return idx > 0 ? name.substring(idx + 1) : name;
100
+ const author = (author2) => isString(author2) ? author2.split(/\s*[<\(]/)[0] : author2.name;
101
+ const authorLink = (author2) => {
102
+ if (isString(author2)) {
103
+ const [name, a, b] = author2.split(/\s*[<\(]/);
104
+ const href = b ? b[b.length - 1] == ")" ? b : a : a ? a : "";
105
+ return href.length && href[href.length - 1] === ")" ? link(name, href.substring(0, href.length - 1)) : name;
106
+ }
107
+ return author2.url ? link(author2.name, author2.url) : author2.name;
105
108
  };
106
- /**
107
- * Returns name of the author, given in any format supported by NPM.
108
- *
109
- * @param author
110
- */
111
- export const author = (author) => isString(author) ? author.split(/\s*[<\(]/)[0] : author.name;
112
- /**
113
- * Similar to {@link author}, but if an URL is available, returns a Markdown
114
- * link to the author's URL, else just the name.
115
- *
116
- * @param author
117
- */
118
- export const authorLink = (author) => {
119
- if (isString(author)) {
120
- const [name, a, b] = author.split(/\s*[<\(]/);
121
- const href = b ? (b[b.length - 1] == ")" ? b : a) : a ? a : "";
122
- return href.length && href[href.length - 1] === ")"
123
- ? link(name, href.substring(0, href.length - 1))
124
- : name;
125
- }
126
- return author.url ? link(author.name, author.url) : author.name;
109
+ const contributors = (people, eol = "\n") => list(people.map(author), eol);
110
+ const contributorLinks = (people, eol = "\n") => list(people.map(authorLink), eol);
111
+ const license = (spdxID) => LICENSES[spdxID].name || `${spdxID} license`;
112
+ const licenseLink = (spdxID) => {
113
+ const license2 = LICENSES[spdxID];
114
+ return license2 ? link(license2.name, license2.url) : `${spdxID} license`;
127
115
  };
128
- /**
129
- * Formats the {@link Package.contributors} as Markdown list.
130
- *
131
- * @param people
132
- * @param eol
133
- */
134
- export const contributors = (people, eol = "\n") => list(people.map(author), eol);
135
- /**
136
- * Similar to {@link contributors}, but formatted as list of links.
137
- *
138
- * @param people
139
- * @param eol
140
- */
141
- export const contributorLinks = (people, eol = "\n") => list(people.map(authorLink), eol);
142
- /**
143
- * Returns the name for given SPDX license ID (only those in
144
- * {@link LICENSES} are supported).
145
- *
146
- * @param spdxID
147
- */
148
- export const license = (spdxID) => LICENSES[spdxID].name || `${spdxID} license`;
149
- /**
150
- * Similar to {@link license}, but returns Markdown link to license.
151
- *
152
- * @param spdxID
153
- */
154
- export const licenseLink = (spdxID) => {
155
- const license = LICENSES[spdxID];
156
- return license ? link(license.name, license.url) : `${spdxID} license`;
116
+ const packageTemplates = (pkg, opts) => {
117
+ const $opts = {
118
+ hdContributors: "### Contributors\n\n",
119
+ ...opts
120
+ };
121
+ const tpls = {
122
+ "pkg.name": ({ user }) => pkg(user).name,
123
+ "pkg.shortName": ({ user }) => shortName(pkg(user).name),
124
+ "pkg.version": ({ user }) => "v" + pkg(user).version,
125
+ "pkg.description": ({ user }) => pkg(user).description,
126
+ "pkg.link": ({ user }) => link(pkg(user).name, pkg(user).homepage),
127
+ "pkg.author": ({ user }) => author(pkg(user).author),
128
+ "pkg.authorLink": ({ user }) => authorLink(pkg(user).author),
129
+ "pkg.contributors": ({ user, eol }) => {
130
+ const people = pkg(user).contributors;
131
+ return people ? $opts.hdContributors + contributors(people, eol) : "";
132
+ },
133
+ "pkg.contributorLinks": ({ user, eol }) => {
134
+ const people = pkg(user).contributors;
135
+ return people ? $opts.hdContributors + contributorLinks(people, eol) : "";
136
+ },
137
+ "pkg.allAuthors": ({ user, eol }) => {
138
+ const $pkg = pkg(user);
139
+ const $author = author($pkg.author);
140
+ const res = [];
141
+ if ($pkg.contributors) {
142
+ res.push(
143
+ $author + " (Main author)",
144
+ ...$pkg.contributors.map(author)
145
+ );
146
+ } else {
147
+ res.push($author);
148
+ }
149
+ return list(res, eol);
150
+ },
151
+ "pkg.allAuthorLinks": ({ user, eol }) => {
152
+ const $pkg = pkg(user);
153
+ const $author = authorLink($pkg.author);
154
+ const res = [];
155
+ if ($pkg.contributors) {
156
+ res.push(
157
+ $author + " (Main author)",
158
+ ...$pkg.contributors.map(authorLink)
159
+ );
160
+ } else {
161
+ res.push($author);
162
+ }
163
+ return list(res, eol);
164
+ },
165
+ "pkg.license": ({ user }) => license(pkg(user).license),
166
+ "pkg.licenseLink": ({ user }) => licenseLink(pkg(user).license)
167
+ };
168
+ return tpls;
157
169
  };
158
- /**
159
- * Higher order function returning various useful NPM package.json related
160
- * templates. The user provided `pkg` function is used to look up the loaded
161
- * {@link Package} data within the {@link TranscludeCtx.user} object.
162
- *
163
- * @param pkg
164
- * @param opts
165
- */
166
- export const packageTemplates = (pkg, opts) => {
167
- const $opts = {
168
- hdContributors: "### Contributors\n\n",
169
- ...opts,
170
- };
171
- const tpls = {
172
- "pkg.name": ({ user }) => pkg(user).name,
173
- "pkg.shortName": ({ user }) => shortName(pkg(user).name),
174
- "pkg.version": ({ user }) => "v" + pkg(user).version,
175
- "pkg.description": ({ user }) => pkg(user).description,
176
- "pkg.link": ({ user }) => link(pkg(user).name, pkg(user).homepage),
177
- "pkg.author": ({ user }) => author(pkg(user).author),
178
- "pkg.authorLink": ({ user }) => authorLink(pkg(user).author),
179
- "pkg.contributors": ({ user, eol }) => {
180
- const people = pkg(user).contributors;
181
- return people
182
- ? $opts.hdContributors + contributors(people, eol)
183
- : "";
184
- },
185
- "pkg.contributorLinks": ({ user, eol }) => {
186
- const people = pkg(user).contributors;
187
- return people
188
- ? $opts.hdContributors + contributorLinks(people, eol)
189
- : "";
190
- },
191
- "pkg.allAuthors": ({ user, eol }) => {
192
- const $pkg = pkg(user);
193
- const $author = author($pkg.author);
194
- const res = [];
195
- if ($pkg.contributors) {
196
- res.push($author + " (Main author)", ...$pkg.contributors.map(author));
197
- }
198
- else {
199
- res.push($author);
200
- }
201
- return list(res, eol);
202
- },
203
- "pkg.allAuthorLinks": ({ user, eol }) => {
204
- const $pkg = pkg(user);
205
- const $author = authorLink($pkg.author);
206
- const res = [];
207
- if ($pkg.contributors) {
208
- res.push($author + " (Main author)", ...$pkg.contributors.map(authorLink));
209
- }
210
- else {
211
- res.push($author);
212
- }
213
- return list(res, eol);
214
- },
215
- "pkg.license": ({ user }) => license(pkg(user).license),
216
- "pkg.licenseLink": ({ user }) => licenseLink(pkg(user).license),
217
- };
218
- return tpls;
170
+ export {
171
+ LICENSES,
172
+ author,
173
+ authorLink,
174
+ contributorLinks,
175
+ contributors,
176
+ license,
177
+ licenseLink,
178
+ packageTemplates,
179
+ shortName
219
180
  };
package/tpl/whitespace.js CHANGED
@@ -1,17 +1,9 @@
1
- /**
2
- * Post-processing stage template function. Replaces all leading tabs (per line
3
- * indentation) with `size` spaces.
4
- *
5
- * @param size
6
- */
7
- export const tabsToSpaces = (size = 4) => {
8
- const indent = " ".repeat(size);
9
- return ({ src }) => src.replace(/^\t+/gm, (x) => indent.repeat(x.length));
1
+ const tabsToSpaces = (size = 4) => {
2
+ const indent = " ".repeat(size);
3
+ return ({ src }) => src.replace(/^\t+/gm, (x) => indent.repeat(x.length));
4
+ };
5
+ const compactEmptyLines = ({ src, eol }) => src.replace(/(\r?\n){2,}/g, eol.repeat(2)).trim() + eol;
6
+ export {
7
+ compactEmptyLines,
8
+ tabsToSpaces
10
9
  };
11
- /**
12
- * Post-processing stage template function. Compacts successive empty lines to a
13
- * max. of 1 empty line.
14
- *
15
- * @param ctx
16
- */
17
- export const compactEmptyLines = ({ src, eol }) => src.replace(/(\r?\n){2,}/g, eol.repeat(2)).trim() + eol;
package/transclude.js CHANGED
@@ -2,37 +2,40 @@ import { readText } from "@thi.ng/file-io/text";
2
2
  import { ConsoleLogger } from "@thi.ng/logger";
3
3
  import { resolve } from "path";
4
4
  const DEFAULT_LOGGER = new ConsoleLogger("transclude");
5
- export const transclude = (ctx, path) => {
6
- const $ctx = {
7
- logger: DEFAULT_LOGGER,
8
- match: /\{\{([a-z0-9.]+)([^}]*)\}\}/gi,
9
- pre: [],
10
- post: [],
11
- eol: "\n",
12
- ...ctx,
13
- };
14
- $ctx.pre.reduce((acc, fn) => ($ctx.src = fn($ctx, [acc], path)), $ctx.src);
15
- $ctx.src = $ctx.src.replace($ctx.match, (...xs) => {
16
- const [orig, id] = xs;
17
- const tpl = $ctx.templates[id];
18
- if (tpl !== undefined) {
19
- return typeof tpl === "function" ? tpl($ctx, xs, path) : tpl;
20
- }
21
- else {
22
- $ctx.logger.warn(`skipping unknown tpl ID: "${id}"`);
23
- return orig;
24
- }
25
- });
26
- $ctx.post.reduce((acc, fn) => ($ctx.src = fn($ctx, [acc], path)), $ctx.src);
27
- return $ctx;
5
+ const transclude = (ctx, path) => {
6
+ const $ctx = {
7
+ logger: DEFAULT_LOGGER,
8
+ match: /\{\{([a-z0-9.]+)([^}]*)\}\}/gi,
9
+ pre: [],
10
+ post: [],
11
+ eol: "\n",
12
+ ...ctx
13
+ };
14
+ $ctx.pre.reduce((acc, fn) => $ctx.src = fn($ctx, [acc], path), $ctx.src);
15
+ $ctx.src = $ctx.src.replace($ctx.match, (...xs) => {
16
+ const [orig, id] = xs;
17
+ const tpl = $ctx.templates[id];
18
+ if (tpl !== void 0) {
19
+ return typeof tpl === "function" ? tpl($ctx, xs, path) : tpl;
20
+ } else {
21
+ $ctx.logger.warn(`skipping unknown tpl ID: "${id}"`);
22
+ return orig;
23
+ }
24
+ });
25
+ $ctx.post.reduce((acc, fn) => $ctx.src = fn($ctx, [acc], path), $ctx.src);
26
+ return $ctx;
28
27
  };
29
- export const transcludeFile = (path, ctx) => {
30
- const $ctx = {
31
- logger: DEFAULT_LOGGER,
32
- src: "",
33
- ...ctx,
34
- };
35
- path = resolve(path);
36
- $ctx.src = readText(path, $ctx.logger);
37
- return transclude($ctx, path);
28
+ const transcludeFile = (path, ctx) => {
29
+ const $ctx = {
30
+ logger: DEFAULT_LOGGER,
31
+ src: "",
32
+ ...ctx
33
+ };
34
+ path = resolve(path);
35
+ $ctx.src = readText(path, $ctx.logger);
36
+ return transclude($ctx, path);
37
+ };
38
+ export {
39
+ transclude,
40
+ transcludeFile
38
41
  };