@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.
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/package.json +88 -0
- package/shiki.config.mjs +50 -0
- package/src/caching.mjs +183 -0
- package/src/generators/ast/README.md +8 -0
- package/src/generators/ast/constants.mjs +1 -0
- package/src/generators/ast/generate.mjs +125 -0
- package/src/generators/ast/index.mjs +20 -0
- package/src/generators/ast/types.d.ts +7 -0
- package/src/generators/ast-js/README.md +8 -0
- package/src/generators/ast-js/generate.mjs +56 -0
- package/src/generators/ast-js/index.mjs +24 -0
- package/src/generators/ast-js/types.d.ts +5 -0
- package/src/generators/index.mjs +48 -0
- package/src/generators/json-simple/README.md +9 -0
- package/src/generators/json-simple/generate.mjs +33 -0
- package/src/generators/json-simple/index.mjs +23 -0
- package/src/generators/json-simple/types.d.ts +6 -0
- package/src/generators/loader.mjs +96 -0
- package/src/generators/metadata/README.md +8 -0
- package/src/generators/metadata/constants.mjs +68 -0
- package/src/generators/metadata/generate.mjs +40 -0
- package/src/generators/metadata/index.mjs +21 -0
- package/src/generators/metadata/maps/builtin.json +16 -0
- package/src/generators/metadata/maps/mdn.json +1114 -0
- package/src/generators/metadata/types.d.ts +145 -0
- package/src/generators/metadata/utils/parse.mjs +160 -0
- package/src/generators/metadata/utils/resolveTypes.mjs +204 -0
- package/src/generators/metadata/utils/slugger.mjs +39 -0
- package/src/generators/metadata/utils/transformers.mjs +109 -0
- package/src/generators/metadata/utils/visitors.mjs +134 -0
- package/src/generators/metadata/utils/yaml.mjs +58 -0
- package/src/generators/types.d.ts +129 -0
- package/src/generators.mjs +145 -0
- package/src/logger/constants.mjs +34 -0
- package/src/logger/index.mjs +27 -0
- package/src/logger/logger.mjs +177 -0
- package/src/logger/transports/console.mjs +54 -0
- package/src/logger/transports/github.mjs +42 -0
- package/src/logger/transports/index.mjs +11 -0
- package/src/logger/types.d.ts +29 -0
- package/src/logger/utils/colors.mjs +18 -0
- package/src/logger/utils/time.mjs +21 -0
- package/src/parsers/markdown.mjs +49 -0
- package/src/parsers/types.d.ts +7 -0
- package/src/threading/chunk-worker.mjs +23 -0
- package/src/threading/index.mjs +27 -0
- package/src/threading/parallel.mjs +140 -0
- package/src/utils/array.mjs +7 -0
- package/src/utils/configuration/index.mjs +263 -0
- package/src/utils/configuration/templates.mjs +21 -0
- package/src/utils/configuration/types.d.ts +64 -0
- package/src/utils/file.mjs +20 -0
- package/src/utils/generators.mjs +71 -0
- package/src/utils/highlighter.mjs +198 -0
- package/src/utils/html-minifier.mjs +12 -0
- package/src/utils/loaders.mjs +48 -0
- package/src/utils/misc.mjs +72 -0
- package/src/utils/queries/constants.mjs +3 -0
- package/src/utils/queries/index.mjs +93 -0
- package/src/utils/queries/utils.mjs +45 -0
- package/src/utils/remark.mjs +97 -0
- package/src/utils/signature/constants.mjs +12 -0
- package/src/utils/signature/parseList.mjs +133 -0
- package/src/utils/signature/parseSignature.mjs +208 -0
- package/src/utils/signature/types.d.ts +66 -0
- package/src/utils/swc.mjs +34 -0
- package/src/utils/type-annotations/hast.mjs +115 -0
- package/src/utils/type-annotations/mdast.mjs +75 -0
- package/src/utils/type-annotations/remark.mjs +24 -0
- package/src/utils/type-annotations/syntax.mjs +188 -0
- package/src/utils/unist.mjs +75 -0
- 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, '<').replace(/>/g, '>');
|
|
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
|
+
};
|