Skip to content

Commit 9bc66f8

Browse files
committed
refactor(types): moved to root
1 parent b46caeb commit 9bc66f8

File tree

8 files changed

+38
-39
lines changed

8 files changed

+38
-39
lines changed
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// TypeScript Version: 3.3
22

33
import * as React from 'react';
4+
import { DomElement } from 'domhandler';
5+
6+
export { DomElement };
47

58
export as namespace HTMLReactParser;
69

@@ -10,12 +13,12 @@ type ReactElement = React.DetailedReactHTMLElement<{}, HTMLElement>;
1013

1114
export interface HTMLReactParserOptions {
1215
// TODO: Replace `object` by type for objects like `{ type: 'h1', props: { children: 'Heading' } }`
13-
replace(domNode: DomNode): React.ReactElement | object | undefined | false;
16+
replace(domNode: DomElement): React.ReactElement | object | undefined | false;
1417
}
1518

1619
/**
1720
* Convert HTML string to React elements.
18-
*
21+
*
1922
* @param - Raw string of HTML to parse.
2023
* @param options - Options to use when converting to react.
2124
* @returns ReactElement on successful parse or string when `html` cannot be
@@ -25,19 +28,3 @@ declare function HTMLReactParser(
2528
html: string,
2629
options?: HTMLReactParserOptions
2730
): ReactElement | ReactElement[] | string;
28-
29-
/** domhandler node */
30-
export interface DomNode {
31-
type: 'tag' | 'text' | 'directive' | 'comment' | 'script' | 'style';
32-
name: string;
33-
data?: string;
34-
attribs?: {
35-
[attributeName: string]: string;
36-
};
37-
children?: DomNode[];
38-
parent?: DomNode;
39-
prev?: DomNode;
40-
next?: DomNode;
41-
startIndex?: number;
42-
endIndex?: number;
43-
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// TypeScript Version: 3.3
2+
13
import * as React from 'react';
2-
import { DomNode, HTMLReactParserOptions } from 'html-react-parser';
4+
import { HTMLReactParserOptions } from '..';
5+
import { DomElement } from 'domhandler';
36

47
/**
58
* Converts DOM nodes to React elements.
@@ -9,6 +12,6 @@ import { DomNode, HTMLReactParserOptions } from 'html-react-parser';
912
* @returns ReactElement or and array of ReactElements.
1013
*/
1114
export default function domToReact(
12-
nodes: DomNode[],
15+
nodes: DomElement[],
1316
options?: HTMLReactParserOptions
1417
): React.ReactElement | React.ReactElement[];

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "An HTML to React parser.",
55
"author": "Mark <mark@remarkablemark.org>",
66
"main": "index.js",
7-
"types": "types",
87
"scripts": {
98
"benchmark": "node benchmark",
109
"build": "npm run clean && npm run build:min && npm run build:unmin",
@@ -15,7 +14,7 @@
1514
"coveralls": "cat coverage/lcov.info | coveralls",
1615
"lint": "eslint --ignore-path .gitignore .",
1716
"lint:fix": "npm run lint -- --fix",
18-
"dtslint": "dtslint types",
17+
"dtslint": "dtslint .",
1918
"prepublishOnly": "npm run build",
2019
"release": "standard-version --no-verify",
2120
"test": "mocha"
@@ -35,6 +34,7 @@
3534
"converter"
3635
],
3736
"dependencies": {
37+
"@types/domhandler": "2.4.1",
3838
"html-dom-parser": "0.2.0",
3939
"react-dom-core": "0.0.4",
4040
"style-to-object": "0.2.2"
@@ -67,8 +67,7 @@
6767
"files": [
6868
"dist",
6969
"lib",
70-
"types/index.d.ts",
71-
"types/lib"
70+
"index.d.ts"
7271
],
7372
"license": "MIT"
7473
}
File renamed without changes.

tsconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": ["es6"],
5+
"noImplicitAny": true,
6+
"noImplicitThis": true,
7+
"strictNullChecks": true,
8+
"strictFunctionTypes": true,
9+
"baseUrl": ".",
10+
"types": [],
11+
"noEmit": true,
12+
"forceConsistentCasingInFileNames": true,
13+
"paths": { "html-react-parser": ["."], "html-react-parser/lib/*": ["./lib/*"] },
14+
"jsx": "react"
15+
},
16+
"files": [
17+
"index.d.ts",
18+
"lib/dom-to-react.d.ts",
19+
"test/types/index.test.tsx",
20+
"test/types/lib/dom-to-react.test.tsx"
21+
]
22+
}

tslint.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "dtslint/dtslint.json"
3+
}

types/tsconfig.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)