@forsakringskassan/docs-generator 3.3.1 → 3.3.3

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/index.mjs CHANGED
@@ -3,12 +3,12 @@ import { createRequire as $createRequire } from "node:module";
3
3
  const require = $createRequire(import.meta.url);
4
4
 
5
5
  import { ApiItemKind, ApiModel } from '@microsoft/api-extractor-model';
6
- import { t as ts, Z as Ze, M as MarkdownIt, d as dedent, g as closest, h as distance, i as fm, j as isCI, m as moduleImporter, k as cliProgress, l as tinylr, w as watch, n as createInstance, o as fse, p as inter } from './vendor-DjC7coI1.mjs';
6
+ import { t as ts, Z as Ze, M as MarkdownIt, d as dedent, g as closest, h as distance, i as fm, j as isCI, m as moduleImporter, k as cliProgress, l as tinylr, w as watch, n as createInstance, o as fse, p as inter } from './vendor-CjH-H-vc.mjs';
7
7
  import path__default from 'node:path';
8
8
  import crypto from 'node:crypto';
9
9
  import path from 'node:path/posix';
10
10
  import { exec, execSync } from 'node:child_process';
11
- import { g as generateId, f as formatCode, p as parseInfostring, i as isDocumentPage, n as normalizePath, a as getFingerprint, h as hasTag, b as parseImport, d as findTag, e as getOutputFilePath, j as htmlencode, k as filePath, c as createMarkdownRenderer, l as generateExample } from './create-markdown-renderer-39oFx5NW.mjs';
11
+ import { g as generateId, f as formatCode, p as parseInfostring, i as isDocumentPage, n as normalizePath, a as getFingerprint, h as hasTag, b as parseImport, d as findTag, e as getOutputFilePath, j as htmlencode, k as filePath, c as createMarkdownRenderer, l as generateExample } from './create-markdown-renderer-O3H4lWpJ.mjs';
12
12
  import { DocExcerpt } from '@microsoft/tsdoc';
13
13
  import fs from 'node:fs/promises';
14
14
  import util, { promisify, styleText } from 'node:util';
@@ -51,7 +51,7 @@ import 'fs/promises';
51
51
  import 'process';
52
52
  import 'v8';
53
53
  import 'vue';
54
- import './vue3-B3-18vX3.mjs';
54
+ import './vue3-DbJPWpmQ.mjs';
55
55
 
56
56
  function toArray$2(value) {
57
57
  return Array.isArray(value) ? value : [value];
@@ -104,21 +104,21 @@ function fileMatcher(patterns) {
104
104
  const additionalInfo = context ? ` (${context})` : "";
105
105
  const message = `No files matched pattern "${filename}"${additionalInfo}`;
106
106
  throw new Error(message);
107
- } else if (matches.length > 1) {
107
+ }
108
+ if (matches.length > 1) {
108
109
  const additionalInfo = context ? ` (${context})` : "";
109
110
  const message = `Multiple files matched pattern "${filename}"${additionalInfo}. Searched in [${patterns.join(", ")}]`;
110
111
  throw new Error(message);
111
- } else {
112
- return matches[0];
113
112
  }
113
+ return matches[0];
114
114
  });
115
115
  }
116
116
 
117
117
  function formatSize(value) {
118
- const suffices = ["kB", "MB"];
119
118
  if (value < 1e3) {
120
119
  return String(value);
121
120
  }
121
+ const suffices = ["kB", "MB"];
122
122
  for (const suffix of suffices) {
123
123
  value = Math.round(value / 1e3 * 100) / 100;
124
124
  if (value < 1e3) {
@@ -221,9 +221,8 @@ function runCommand(cmd, defaultValue) {
221
221
  const gitCommitHash = memoize((format = "short") => {
222
222
  if (format === "full") {
223
223
  return runCommand(`git rev-parse HEAD`);
224
- } else {
225
- return runCommand(`git rev-parse --short HEAD`);
226
224
  }
225
+ return runCommand(`git rev-parse --short HEAD`);
227
226
  });
228
227
 
229
228
  function haveOutput(doc) {
@@ -315,9 +314,8 @@ function documentation(node) {
315
314
  if (node && isDocumentedItem(node)) {
316
315
  const { tsdocComment } = node;
317
316
  return renderNode(tsdocComment?.summarySection).trim();
318
- } else {
319
- return void 0;
320
317
  }
318
+ return void 0;
321
319
  }
322
320
  function documentationComment(node) {
323
321
  const doc = documentation(node);
@@ -399,11 +397,14 @@ function collectMembers(item, inherit) {
399
397
  const hierarchy = getInheritance(item);
400
398
  const members = /* @__PURE__ */ new Map();
401
399
  for (const iface of hierarchy) {
402
- for (const member of iface.members.filter(isSupported)) {
400
+ for (const member of iface.members) {
401
+ if (!isSupported(member)) {
402
+ continue;
403
+ }
403
404
  members.set(member.name, member);
404
405
  }
405
406
  }
406
- return [...members.values()];
407
+ return members.values().toArray();
407
408
  }
408
409
  function isSupported(item) {
409
410
  return [
@@ -438,7 +439,7 @@ function renderProperties(members) {
438
439
  if (it2.trim() === "") {
439
440
  return "\n";
440
441
  }
441
- const prefix = i === 0 ? ": " : " ";
442
+ const prefix = i === 0 ? ": " : " ".repeat(4);
442
443
  return `${prefix}${it2.trim()}
443
444
  `;
444
445
  }) : [": &dash;\n"];
@@ -534,7 +535,8 @@ function apiExtractorProcessor(options = {}) {
534
535
  const symbols = {
535
536
  interface: []
536
537
  };
537
- for (const filename of await getFilenames(patterns)) {
538
+ const filenames = await getFilenames(patterns);
539
+ for (const filename of filenames) {
538
540
  const apiModel = new ApiModel();
539
541
  const apiPackage = apiModel.loadPackage(filename);
540
542
  walk(apiPackage, {
@@ -613,9 +615,8 @@ function getSuffix(tags) {
613
615
  const relevant = tags.filter((it) => ["nocompile", "nolint"].includes(it));
614
616
  if (relevant.length > 0) {
615
617
  return `-${relevant.join("-")}`;
616
- } else {
617
- return "";
618
618
  }
619
+ return "";
619
620
  }
620
621
  function getExtension(lang) {
621
622
  switch (lang) {
@@ -925,7 +926,13 @@ function htmlRedirectProcessor() {
925
926
  after: "render",
926
927
  async handler(context) {
927
928
  const { docs, outputFolder } = context;
928
- for (const doc of docs.filter(isDocumentPage).filter(haveOutput)) {
929
+ for (const doc of docs) {
930
+ if (!isDocumentPage(doc)) {
931
+ continue;
932
+ }
933
+ if (!haveOutput(doc)) {
934
+ continue;
935
+ }
929
936
  if (doc.format !== "redirect") {
930
937
  continue;
931
938
  }
@@ -1057,12 +1064,11 @@ function isNavigationSection(node) {
1057
1064
  function pathFromDoc({ fileInfo }) {
1058
1065
  if (fileInfo.name === "index") {
1059
1066
  return [fileInfo.path.replaceAll("\\", "/"), true];
1060
- } else {
1061
- return [
1062
- `./${path__default.join(fileInfo.path, fileInfo.name).replaceAll("\\", "/")}`,
1063
- false
1064
- ];
1065
1067
  }
1068
+ return [
1069
+ `./${path__default.join(fileInfo.path, fileInfo.name).replaceAll("\\", "/")}`,
1070
+ false
1071
+ ];
1066
1072
  }
1067
1073
  function getParentKey(name) {
1068
1074
  return name.split("/").slice(0, -1).join("/");
@@ -1110,7 +1116,7 @@ function generateNavtree(docs) {
1110
1116
  let current = parent;
1111
1117
  while (anchestor !== ".") {
1112
1118
  anchestor = getParentKey(anchestor);
1113
- if (section[anchestor]) {
1119
+ if (Object.hasOwn(section, anchestor)) {
1114
1120
  section[anchestor].children.push(current);
1115
1121
  break;
1116
1122
  }
@@ -1204,16 +1210,15 @@ function generateNavtree(docs) {
1204
1210
  const root = section["."];
1205
1211
  if (root) {
1206
1212
  return root;
1207
- } else {
1208
- return {
1209
- key: ".",
1210
- title: "",
1211
- path: "",
1212
- sortorder: Infinity,
1213
- children: [],
1214
- visible: true
1215
- };
1216
1213
  }
1214
+ return {
1215
+ key: ".",
1216
+ title: "",
1217
+ path: "",
1218
+ sortorder: Infinity,
1219
+ children: [],
1220
+ visible: true
1221
+ };
1217
1222
  }
1218
1223
 
1219
1224
  function generateNavigation(entries, navtree) {
@@ -1280,9 +1285,8 @@ async function getGitBranch() {
1280
1285
  );
1281
1286
  if (branch === "HEAD" || branch === "") {
1282
1287
  return "unknown";
1283
- } else {
1284
- return branch;
1285
1288
  }
1289
+ return branch;
1286
1290
  }
1287
1291
  async function getSCMData(pkg, options) {
1288
1292
  const commitHash = await gitCommitHash("full");
@@ -1459,11 +1463,11 @@ class AttributeError extends Error {
1459
1463
  message: suggestion
1460
1464
  });
1461
1465
  return [message, "", codeframe].join("\n");
1462
- } else if (d <= threshold) {
1466
+ }
1467
+ if (d <= threshold) {
1463
1468
  return [message, "", suggestion].join("\n");
1464
- } else {
1465
- return message;
1466
1469
  }
1470
+ return message;
1467
1471
  }
1468
1472
  }
1469
1473
 
@@ -1518,9 +1522,8 @@ function normalizeComponent(value) {
1518
1522
  return {
1519
1523
  name: value
1520
1524
  };
1521
- } else {
1522
- return value;
1523
1525
  }
1526
+ return value;
1524
1527
  }
1525
1528
  function getComponentAlias(value) {
1526
1529
  const { name } = normalizeComponent(value);
@@ -1757,11 +1760,11 @@ function findTranslations(filename, content) {
1757
1760
  const { node } = path;
1758
1761
  if (isTranslateCall(node)) {
1759
1762
  const [name, ...defaultOrParams] = node.arguments;
1760
- const textArgument = defaultOrParams.find(isStringLiteral);
1761
- const paramArgument = defaultOrParams.find(isObjectExpression);
1762
1763
  if (name.type !== "StringLiteral") {
1763
1764
  return;
1764
1765
  }
1766
+ const textArgument = defaultOrParams.find(isStringLiteral);
1767
+ const paramArgument = defaultOrParams.find(isObjectExpression);
1765
1768
  const defaultTranslation = textArgument ? textArgument.value : null;
1766
1769
  const docComment = findDocComment(path, node);
1767
1770
  result.push({
@@ -1816,9 +1819,8 @@ function generateEventTable(slug, events) {
1816
1819
  ${event.properties.map((it) => {
1817
1820
  if (it.description) {
1818
1821
  return `<li><code>${htmlencode(it.name)}: ${htmlencode(it.type)}</code> ${EM_DASH$2} ${renderInline$4(it.description)}</li>`;
1819
- } else {
1820
- return `<li><code>${htmlencode(it.name)}: ${htmlencode(it.type)}</code></li>`;
1821
1822
  }
1823
+ return `<li><code>${htmlencode(it.name)}: ${htmlencode(it.type)}</code></li>`;
1822
1824
  }).join("")}
1823
1825
  ${haveProperties ? `</ul>` : ""}
1824
1826
  ${event.deprecated ? `<p class="docs-api__deprecated docs-deprecated">Deprecated: ${renderInline$4(event.deprecated)}</p>` : ""}
@@ -1963,9 +1965,8 @@ function generateSlotTable(slug, slots) {
1963
1965
  ${slot.bindings.map((it) => {
1964
1966
  if (it.description) {
1965
1967
  return `<li><code>${htmlencode(it.name)}: ${htmlencode(it.type)}</code> ${EM_DASH$1} ${renderInline$1(it.description)}</li>`;
1966
- } else {
1967
- return `<li><code>${htmlencode(it.name)}: ${htmlencode(it.type)}</code></li>`;
1968
1968
  }
1969
+ return `<li><code>${htmlencode(it.name)}: ${htmlencode(it.type)}</code></li>`;
1969
1970
  }).join("")}
1970
1971
  ${haveBindings ? `</ul>` : ""}
1971
1972
  ${slot.deprecated ? `<p class="docs-api__deprecated docs-deprecated">Deprecated: ${renderInline$1(slot.deprecated)}</p>` : ""}
@@ -2015,9 +2016,8 @@ function generateTranslationTable(slug, translations) {
2015
2016
  ${translation.parameters.map((it) => {
2016
2017
  if (it.description) {
2017
2018
  return `<li><code>${htmlencode(it.name)}</code> ${EM_DASH} ${renderInline(it.description)}</li>`;
2018
- } else {
2019
- return `<li><code>${htmlencode(it.name)}</code></li>`;
2020
2019
  }
2020
+ return `<li><code>${htmlencode(it.name)}</code></li>`;
2021
2021
  }).join("")}
2022
2022
  ${haveParameters ? `</ul>` : ""}
2023
2023
  </dd>
@@ -2040,9 +2040,8 @@ function getPropSlotDeprecated(prop) {
2040
2040
  }
2041
2041
  if (tag.description === true) {
2042
2042
  return "";
2043
- } else {
2044
- return tag.description;
2045
2043
  }
2044
+ return tag.description;
2046
2045
  }
2047
2046
  function getEventDeprecated(event) {
2048
2047
  const tags = event.tags;
@@ -2055,9 +2054,8 @@ function getEventDeprecated(event) {
2055
2054
  }
2056
2055
  if (tag.content === true) {
2057
2056
  return "";
2058
- } else {
2059
- return tag.content;
2060
2057
  }
2058
+ return tag.content;
2061
2059
  }
2062
2060
  function isSimpleName(name) {
2063
2061
  return /^[\da-z]+$/i.test(name);
@@ -2078,9 +2076,8 @@ function getPropType(prop) {
2078
2076
  }
2079
2077
  if (isSimpleName(element.name)) {
2080
2078
  return `${element.name}[]`;
2081
- } else {
2082
- return `Array<${element.name}>`;
2083
2079
  }
2080
+ return `Array<${element.name}>`;
2084
2081
  }
2085
2082
  if (type.name === "tuple") {
2086
2083
  const param = type;
@@ -2297,7 +2294,7 @@ async function globAll(pattern) {
2297
2294
  return /* @__PURE__ */ new Set();
2298
2295
  }
2299
2296
  if (!Array.isArray(pattern)) {
2300
- return globAll([pattern]);
2297
+ pattern = [pattern];
2301
2298
  }
2302
2299
  const results = await Promise.all(
2303
2300
  pattern.map((it) => Ze(it, { nodir: true }))
@@ -2333,9 +2330,8 @@ async function getDocumentsForSource(context, src, index) {
2333
2330
  const docs2 = await src.fileReader(it, src.basePath);
2334
2331
  if (transform) {
2335
2332
  return docs2.map((it2) => transform(it2));
2336
- } else {
2337
- return docs2;
2338
2333
  }
2334
+ return docs2;
2339
2335
  });
2340
2336
  const docs = await Promise.all(promises);
2341
2337
  return docs.flat();
@@ -2614,8 +2610,8 @@ function compileProcessorRuntime(generator, distDir, processors) {
2614
2610
  if (processor.enabled === false) {
2615
2611
  continue;
2616
2612
  }
2617
- const { runtime } = processor;
2618
- for (const entry of runtime ?? []) {
2613
+ const { runtime = [] } = processor;
2614
+ for (const entry of runtime) {
2619
2615
  const assetName = [
2620
2616
  "processors",
2621
2617
  processor.name.replace(/-processor/, ""),
@@ -2711,7 +2707,8 @@ function sortNavigationTree(tree) {
2711
2707
  tree.children.sort((a, b) => {
2712
2708
  if (a.sortorder < b.sortorder) {
2713
2709
  return -1;
2714
- } else if (a.sortorder > b.sortorder) {
2710
+ }
2711
+ if (a.sortorder > b.sortorder) {
2715
2712
  return 1;
2716
2713
  }
2717
2714
  const titleA = a.title.toUpperCase();
@@ -2788,7 +2785,7 @@ function findTemplate(folders, from, src, format) {
2788
2785
  const searchPaths = folders.map((it) => {
2789
2786
  return path__default.join(it, template);
2790
2787
  });
2791
- const found = searchPaths.find((it) => fs__default.existsSync(it));
2788
+ const found = searchPaths.some((it) => fs__default.existsSync(it));
2792
2789
  if (!found) {
2793
2790
  throw new MissingTemplateError(from, template, format, folders);
2794
2791
  }
@@ -2863,9 +2860,8 @@ function getActualMessage(message) {
2863
2860
  const match = messageRegex.exec(message);
2864
2861
  if (match) {
2865
2862
  return match[1].trim();
2866
- } else {
2867
- return message;
2868
2863
  }
2864
+ return message;
2869
2865
  }
2870
2866
  class TemplateRenderError extends Error {
2871
2867
  filename;
@@ -2900,23 +2896,22 @@ function fillActiveNavigation(doc, node) {
2900
2896
  const children = node.children.map(
2901
2897
  (it) => fillActiveNavigation(doc, it)
2902
2898
  );
2903
- const active = children.some((it) => it.active);
2899
+ const active2 = children.some((it) => it.active);
2904
2900
  return {
2905
2901
  ...node,
2906
- active,
2902
+ active: active2,
2907
2903
  children
2908
2904
  };
2909
- } else {
2910
- const active = doc.id === node.id;
2911
- return {
2912
- ...node,
2913
- active
2914
- };
2915
2905
  }
2906
+ const active = doc.id === node.id;
2907
+ return {
2908
+ ...node,
2909
+ active
2910
+ };
2916
2911
  }
2917
2912
  function findSidenav(doc, tree) {
2918
2913
  const { path: path2, name } = doc.fileInfo;
2919
- const category = path2 === "." ? name : path2.split("/")[1];
2914
+ const category = path2 === "." ? name : path2.split("/", 2)[1];
2920
2915
  const sidenav = tree.children.filter(isNavigationSection).find((it) => it.key === `./${category}`);
2921
2916
  if (sidenav) {
2922
2917
  return fillActiveNavigation(doc, sidenav);
@@ -2929,9 +2924,8 @@ function cache(cacheFolder, outputFolder) {
2929
2924
  if (existsSync(cacheFile)) {
2930
2925
  copyFileSync(cacheFile, outputFile);
2931
2926
  return false;
2932
- } else {
2933
- return true;
2934
2927
  }
2928
+ return true;
2935
2929
  };
2936
2930
  }
2937
2931
  async function compileExamples(options) {
@@ -2960,11 +2954,12 @@ async function compileExamples(options) {
2960
2954
  };
2961
2955
  return new Promise((resolve, reject) => {
2962
2956
  function onmessage(message2) {
2963
- if (message2.ref === ref) {
2964
- exampleWorker.off("message", onmessage);
2965
- exampleWorker.off("error", onerror);
2966
- resolve();
2957
+ if (message2.ref !== ref) {
2958
+ return;
2967
2959
  }
2960
+ exampleWorker.off("message", onmessage);
2961
+ exampleWorker.off("error", onerror);
2962
+ resolve();
2968
2963
  }
2969
2964
  function onerror(err) {
2970
2965
  reject(err);
@@ -3167,9 +3162,8 @@ async function render(doc, docs, options) {
3167
3162
  const expandedDst = dst.replaceAll(/\[([\s\S]+)\]/g, (match, key) => {
3168
3163
  if (key === "hash") {
3169
3164
  return getFingerprint(doc.body);
3170
- } else {
3171
- return match;
3172
3165
  }
3166
+ return match;
3173
3167
  });
3174
3168
  const writeFile = fs.writeFile(expandedDst, content, "utf8");
3175
3169
  try {
@@ -3343,9 +3337,8 @@ async function importExpress() {
3343
3337
  "docs-generator serve() requires the optional peerDependency express to be installed",
3344
3338
  { cause: err }
3345
3339
  );
3346
- } else {
3347
- throw err;
3348
3340
  }
3341
+ throw err;
3349
3342
  }
3350
3343
  }
3351
3344
  async function serve(options) {
@@ -3433,12 +3426,11 @@ function normalizeVendorDefinition(vendor) {
3433
3426
  package: vendor,
3434
3427
  alias: void 0
3435
3428
  };
3436
- } else {
3437
- return {
3438
- package: vendor.package,
3439
- alias: vendor.alias ?? void 0
3440
- };
3441
3429
  }
3430
+ return {
3431
+ package: vendor.package,
3432
+ alias: vendor.alias ?? void 0
3433
+ };
3442
3434
  }
3443
3435
 
3444
3436
  function getPackageName(vendor) {
@@ -3509,10 +3501,9 @@ async function stage(stage2, context, processors, options) {
3509
3501
  try {
3510
3502
  const prefix = (() => {
3511
3503
  if (verbose) {
3512
- return isLast ? " " : " \u2502 ";
3513
- } else {
3514
- return "";
3504
+ return isLast ? " ".repeat(6) : " \u2502 ";
3515
3505
  }
3506
+ return "";
3516
3507
  })();
3517
3508
  const result = await processor.handler({
3518
3509
  ...context,
@@ -3616,17 +3607,17 @@ function createContext(options) {
3616
3607
  sidenav = root;
3617
3608
  },
3618
3609
  getAllTemplateData() {
3619
- return Object.fromEntries(templateData.entries());
3610
+ return Object.fromEntries(templateData);
3620
3611
  },
3621
3612
  getTemplateData(key, defaultValue) {
3622
3613
  if (templateData.has(key)) {
3623
3614
  return templateData.get(key);
3624
- } else if (defaultValue) {
3615
+ }
3616
+ if (defaultValue) {
3625
3617
  templateData.set(key, defaultValue);
3626
3618
  return defaultValue;
3627
- } else {
3628
- return void 0;
3629
3619
  }
3620
+ return void 0;
3630
3621
  },
3631
3622
  setTemplateData(key, value) {
3632
3623
  templateData.set(key, value);
@@ -3638,9 +3629,8 @@ function getWorkingDir(value) {
3638
3629
  const url = typeof value === "string" ? new URL(value) : value;
3639
3630
  const normalized = normalizePath(fileURLToPath(url));
3640
3631
  return path__default.posix.dirname(normalized);
3641
- } else {
3642
- return normalizePath(process.cwd());
3643
3632
  }
3633
+ return normalizePath(process.cwd());
3644
3634
  }
3645
3635
  class Generator {
3646
3636
  cwd;
@@ -3902,7 +3892,7 @@ function* extractTerms(doc) {
3902
3892
  yield doc.name;
3903
3893
  }
3904
3894
  if (component) {
3905
- for (const name of component.map((it) => it.name)) {
3895
+ for (const { name } of component) {
3906
3896
  yield name;
3907
3897
  }
3908
3898
  }