Skip to content

Commit 8e69f1d

Browse files
committed
chore: adds typescript type definition
1 parent 85d4df4 commit 8e69f1d

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/index.d.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
declare namespace render {
2+
type Options = {
3+
/**
4+
* Custom single tags (selfClosing).
5+
*
6+
* @default []
7+
*/
8+
singleTags: string[] | RegExp[];
9+
10+
/**
11+
* Closing format for single tag.
12+
*
13+
* Formats:
14+
*
15+
* tag: `<br></br>`, slash: `<br />`, default: `<br>`
16+
*
17+
*/
18+
closingSingleTag: "tag" | "slash";
19+
20+
/**
21+
* If all attributes should be quoted.
22+
* Otherwise attributes will be unquoted when allowed.
23+
*
24+
* @default true
25+
*/
26+
quoteAllAttributes: boolean;
27+
};
28+
29+
// PostHTML Tree
30+
type Tree = Node[];
31+
type Node = NodeText | NodeTag;
32+
type NodeText = string;
33+
type NodeTag = {
34+
tag: string;
35+
attrs?: Attributes;
36+
content?: Node[];
37+
};
38+
39+
type Attributes = Record<string, string>;
40+
}
41+
42+
/**
43+
* Render PostHTML Tree to HTML
44+
* @param tree PostHTML Tree
45+
* @param options Render options
46+
* @returns HTML
47+
*/
48+
declare function render(
49+
tree: render.Tree,
50+
options?: Partial<render.Options>
51+
): string;
52+
53+
export = render;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "Ivan Voischev <voischev.ivan@ya.ru>",
66
"license": "MIT",
77
"main": "lib/index.js",
8+
"types": "lib/index.d.ts",
89
"engines": {
910
"node": ">=8"
1011
},

0 commit comments

Comments
 (0)