@doc-kit/core 0.0.0

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/README.md +36 -0
  4. package/package.json +88 -0
  5. package/shiki.config.mjs +50 -0
  6. package/src/caching.mjs +183 -0
  7. package/src/generators/ast/README.md +8 -0
  8. package/src/generators/ast/constants.mjs +1 -0
  9. package/src/generators/ast/generate.mjs +125 -0
  10. package/src/generators/ast/index.mjs +20 -0
  11. package/src/generators/ast/types.d.ts +7 -0
  12. package/src/generators/ast-js/README.md +8 -0
  13. package/src/generators/ast-js/generate.mjs +56 -0
  14. package/src/generators/ast-js/index.mjs +24 -0
  15. package/src/generators/ast-js/types.d.ts +5 -0
  16. package/src/generators/index.mjs +48 -0
  17. package/src/generators/json-simple/README.md +9 -0
  18. package/src/generators/json-simple/generate.mjs +33 -0
  19. package/src/generators/json-simple/index.mjs +23 -0
  20. package/src/generators/json-simple/types.d.ts +6 -0
  21. package/src/generators/loader.mjs +96 -0
  22. package/src/generators/metadata/README.md +8 -0
  23. package/src/generators/metadata/constants.mjs +68 -0
  24. package/src/generators/metadata/generate.mjs +40 -0
  25. package/src/generators/metadata/index.mjs +21 -0
  26. package/src/generators/metadata/maps/builtin.json +16 -0
  27. package/src/generators/metadata/maps/mdn.json +1114 -0
  28. package/src/generators/metadata/types.d.ts +145 -0
  29. package/src/generators/metadata/utils/parse.mjs +160 -0
  30. package/src/generators/metadata/utils/resolveTypes.mjs +204 -0
  31. package/src/generators/metadata/utils/slugger.mjs +39 -0
  32. package/src/generators/metadata/utils/transformers.mjs +109 -0
  33. package/src/generators/metadata/utils/visitors.mjs +134 -0
  34. package/src/generators/metadata/utils/yaml.mjs +58 -0
  35. package/src/generators/types.d.ts +129 -0
  36. package/src/generators.mjs +145 -0
  37. package/src/logger/constants.mjs +34 -0
  38. package/src/logger/index.mjs +27 -0
  39. package/src/logger/logger.mjs +177 -0
  40. package/src/logger/transports/console.mjs +54 -0
  41. package/src/logger/transports/github.mjs +42 -0
  42. package/src/logger/transports/index.mjs +11 -0
  43. package/src/logger/types.d.ts +29 -0
  44. package/src/logger/utils/colors.mjs +18 -0
  45. package/src/logger/utils/time.mjs +21 -0
  46. package/src/parsers/markdown.mjs +49 -0
  47. package/src/parsers/types.d.ts +7 -0
  48. package/src/threading/chunk-worker.mjs +23 -0
  49. package/src/threading/index.mjs +27 -0
  50. package/src/threading/parallel.mjs +140 -0
  51. package/src/utils/array.mjs +7 -0
  52. package/src/utils/configuration/index.mjs +263 -0
  53. package/src/utils/configuration/templates.mjs +21 -0
  54. package/src/utils/configuration/types.d.ts +64 -0
  55. package/src/utils/file.mjs +20 -0
  56. package/src/utils/generators.mjs +71 -0
  57. package/src/utils/highlighter.mjs +198 -0
  58. package/src/utils/html-minifier.mjs +12 -0
  59. package/src/utils/loaders.mjs +48 -0
  60. package/src/utils/misc.mjs +72 -0
  61. package/src/utils/queries/constants.mjs +3 -0
  62. package/src/utils/queries/index.mjs +93 -0
  63. package/src/utils/queries/utils.mjs +45 -0
  64. package/src/utils/remark.mjs +97 -0
  65. package/src/utils/signature/constants.mjs +12 -0
  66. package/src/utils/signature/parseList.mjs +133 -0
  67. package/src/utils/signature/parseSignature.mjs +208 -0
  68. package/src/utils/signature/types.d.ts +66 -0
  69. package/src/utils/swc.mjs +34 -0
  70. package/src/utils/type-annotations/hast.mjs +115 -0
  71. package/src/utils/type-annotations/mdast.mjs +75 -0
  72. package/src/utils/type-annotations/remark.mjs +24 -0
  73. package/src/utils/type-annotations/syntax.mjs +188 -0
  74. package/src/utils/unist.mjs +75 -0
  75. package/src/utils/url.mjs +27 -0
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ import { pointEnd, pointStart } from 'unist-util-position';
4
+
5
+ /**
6
+ * Escapes HTML entities ("<" and ">") in a string
7
+ * @param {string} string The string
8
+ */
9
+ const escapeHTMLEntities = string =>
10
+ string.replace(/</g, '&lt;').replace(/>/g, '&gt;');
11
+
12
+ /**
13
+ * Extracts text content from a node recursively
14
+ *
15
+ * @param {import('unist').Node} node The Node to be transformed into a string
16
+ * @param {boolean} [escape] Escape HTML entities ("<", ">")?
17
+ * @returns {string} The transformed Node as a string
18
+ */
19
+ export const transformNodeToString = (node, escape) => {
20
+ switch (node.type) {
21
+ case 'inlineCode':
22
+ return `\`${escape ? escapeHTMLEntities(node.value) : node.value}\``;
23
+ case 'typeAnnotation':
24
+ return `{${escape ? escapeHTMLEntities(node.value) : node.value}}`;
25
+ case 'strong':
26
+ return `**${transformNodesToString(node.children, escape)}**`;
27
+ case 'emphasis':
28
+ return `_${transformNodesToString(node.children, escape)}_`;
29
+ default: {
30
+ if (node.children) {
31
+ return transformNodesToString(node.children, escape);
32
+ }
33
+
34
+ const string = node.value?.replace(/\n/g, ' ') || '';
35
+
36
+ // Replace line breaks (\n) with spaces to keep text in a single line
37
+ return escape ? escapeHTMLEntities(string) : string;
38
+ }
39
+ }
40
+ };
41
+
42
+ /**
43
+ * This utility allows us to join children Nodes into one
44
+ * and transfor them back to what their source would look like
45
+ *
46
+ * @param {Array<import('unist').Parent & import('unist').Literal>} nodes Nodes to parsed and joined
47
+ * @param {boolean} [escape] Escape HTML entities ("<", ">")?
48
+ * @returns {string} The parsed and joined nodes as a string
49
+ */
50
+ export const transformNodesToString = (nodes, escape) => {
51
+ const mappedChildren = nodes.map(node => transformNodeToString(node, escape));
52
+
53
+ return mappedChildren.join('');
54
+ };
55
+
56
+ /**
57
+ * This method is an utility that allows us to conditionally invoke/call a callback
58
+ * based on test conditions related to a Node's position relative to another one
59
+ * being before or not the other Node
60
+ *
61
+ * NOTE: Not yet used, but probably going to be used by the JSON generator.
62
+ *
63
+ * @param {import('unist').Node | undefined} nodeA The Node to be used as a position reference to check against
64
+ * the other Node. If the other Node is before this one, the callback will be called.
65
+ * @param {import('unist').Node | undefined} nodeB The Node to be checked against the position of the first Node
66
+ * @param {(nodeA: import('unist').Node, nodeB: import('unist').Node) => void} callback The callback to be called
67
+ */
68
+ export const callIfBefore = (nodeA, nodeB, callback) => {
69
+ const positionA = pointEnd(nodeA);
70
+ const positionB = pointStart(nodeB);
71
+
72
+ if (positionA && positionB && positionA.line > positionB.line) {
73
+ callback(nodeA, nodeB);
74
+ }
75
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Kind of like `path.posix.relative`, however, this functions more like a URL resolution
3
+ * @param {string} to
4
+ * @param {string} from
5
+ * @returns {string}
6
+ */
7
+ export const relative = (to, from) => {
8
+ if (to.includes('://')) {
9
+ return to;
10
+ }
11
+
12
+ const a = to.split('/').filter(Boolean);
13
+ const b = from.split('/').slice(0, -1).filter(Boolean);
14
+
15
+ // The last segment of `to` is the target itself, not a directory; it must
16
+ // never be consumed as a common prefix (`/generators` from `/generators/web`
17
+ // is `../generators`, not `.`).
18
+ const file = a.pop();
19
+
20
+ while (a[0] !== undefined && a[0] === b[0]) {
21
+ a.shift();
22
+ b.shift();
23
+ }
24
+
25
+ const rel = [...b.map(() => '..'), ...a, ...(file ? [file] : [])].join('/');
26
+ return rel || '.';
27
+ };