Skip to content

Commit 3c4d4a1

Browse files
shanehandleywooorm
authored andcommitted
Add types
Closes GH-8. Closes GH-9. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent ff7d8bd commit 3c4d4a1

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
1717
],
1818
"files": [
19-
"index.js"
19+
"index.js",
20+
"types/index.d.ts"
2021
],
22+
"types": "types/index.d.ts",
2123
"dependencies": {
2224
"is-empty": "^1.0.0"
2325
},
2426
"devDependencies": {
27+
"@types/unist": "^2.0.3",
2528
"browserify": "^16.0.0",
2629
"chalk": "^2.3.0",
30+
"dtslint": "^1.0.2",
2731
"nyc": "^14.0.0",
2832
"prettier": "^1.0.0",
2933
"remark-cli": "^6.0.0",
@@ -41,7 +45,8 @@
4145
"build": "npm run build-bundle && npm run build-mangle",
4246
"test-api": "node test",
4347
"test-coverage": "nyc --reporter lcov tape test.js",
44-
"test": "npm run format && npm run build && npm run test-coverage"
48+
"test": "npm run format && npm run build && npm run test-coverage",
49+
"dtslint": "dtslint types"
4550
},
4651
"prettier": {
4752
"tabWidth": 2,

types/index.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// TypeScript Version: 3.0
2+
import { Node } from 'unist';
3+
4+
export = inpect;
5+
6+
/*
7+
* Unist utility to inspect the details of a Unist Node
8+
*
9+
* @param node Node to inspect
10+
*/
11+
declare function inpect(node: Node): string;
12+
13+
declare namespace inpect {
14+
/**
15+
* Inspect the given Node and include colors from the results
16+
*
17+
* @param node Node to inspect
18+
*/
19+
function color(node: Node): string;
20+
21+
/**
22+
* Inspect the given Node and exclude colors from the results
23+
*
24+
* @param node Node to inspect
25+
*/
26+
function noColor(node: Node): string;
27+
}

types/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["es2015"],
4+
"strict": true,
5+
"baseUrl": ".",
6+
"paths": {
7+
"unist-util-inspect": ["index.d.ts"]
8+
}
9+
}
10+
}

types/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/unist-util-inspect-tests.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as inspect from 'unist-util-inspect';
2+
3+
const node = {
4+
type: 'node',
5+
data: {
6+
string: 'string',
7+
number: 1,
8+
object: {
9+
key: 'value'
10+
},
11+
array: [],
12+
boolean: true,
13+
null: null
14+
},
15+
position: {
16+
start: {
17+
line: 1,
18+
column: 1,
19+
offset: 0
20+
},
21+
end: {
22+
line: 1,
23+
column: 4,
24+
offset: 0
25+
},
26+
indent: [1]
27+
}
28+
};
29+
30+
const result: string = inspect(node);

0 commit comments

Comments
 (0)