|
1 | 1 | /**
|
2 |
| - * @typedef {import('unist').Node} Node |
3 |
| - * @typedef {import('unist').Parent} Parent |
4 |
| - * @typedef {import('unist').Literal} Literal |
5 |
| - * @typedef {Record<string, unknown>} Props |
6 |
| - * @typedef {Array<Node>|string} ChildrenOrValue |
7 |
| - * |
8 |
| - * @typedef {(<T extends string, P extends Record<string, unknown>, C extends Array<Node>>(type: T, props: P, children: C) => {type: T, children: C} & P)} BuildParentWithProps |
9 |
| - * @typedef {(<T extends string, P extends Record<string, unknown>>(type: T, props: P, value: string) => {type: T, value: string} & P)} BuildLiteralWithProps |
10 |
| - * @typedef {(<T extends string, P extends Record<string, unknown>>(type: T, props: P) => {type: T} & P)} BuildVoidWithProps |
11 |
| - * @typedef {(<T extends string, C extends Array<Node>>(type: T, children: C) => {type: T, children: C})} BuildParent |
12 |
| - * @typedef {(<T extends string>(type: T, value: string) => {type: T, value: string})} BuildLiteral |
13 |
| - * @typedef {(<T extends string>(type: T) => {type: T})} BuildVoid |
| 2 | + * @typedef {import('./lib/index.js').Props} Props |
| 3 | + * @typedef {import('./lib/index.js').ChildrenOrValue} ChildrenOrValue |
14 | 4 | */
|
15 | 5 |
|
16 |
| -/** |
17 |
| - * Build a node. |
18 |
| - * |
19 |
| - * @param type |
20 |
| - * Node type. |
21 |
| - * @param [props] |
22 |
| - * Fields assigned to node. |
23 |
| - * @param [value] |
24 |
| - * Children of node or value of `node` (cast to string). |
25 |
| - * @returns |
26 |
| - * Built node. |
27 |
| - */ |
28 |
| -export const u = /** |
29 |
| - * @type {BuildVoid & BuildVoidWithProps & BuildLiteral & BuildLiteralWithProps & BuildParent & BuildParentWithProps} |
30 |
| - */ ( |
31 |
| - /** |
32 |
| - * @param {string} type |
33 |
| - * @param {Props|ChildrenOrValue} [props] |
34 |
| - * @param {ChildrenOrValue} [value] |
35 |
| - * @returns {Node} |
36 |
| - */ |
37 |
| - function (type, props, value) { |
38 |
| - /** @type {Node} */ |
39 |
| - const node = {type: String(type)} |
40 |
| - |
41 |
| - if ( |
42 |
| - (value === undefined || value === null) && |
43 |
| - (typeof props === 'string' || Array.isArray(props)) |
44 |
| - ) { |
45 |
| - value = props |
46 |
| - } else { |
47 |
| - Object.assign(node, props) |
48 |
| - } |
49 |
| - |
50 |
| - if (Array.isArray(value)) { |
51 |
| - // @ts-expect-error: create a parent. |
52 |
| - node.children = value |
53 |
| - } else if (value !== undefined && value !== null) { |
54 |
| - // @ts-expect-error: create a literal. |
55 |
| - node.value = String(value) |
56 |
| - } |
57 |
| - |
58 |
| - return node |
59 |
| - } |
60 |
| -) |
| 6 | +export {u} from './lib/index.js' |
0 commit comments