Skip to content

Commit 196bf74

Browse files
types: add typescript typings
resolves #9
1 parent 67a1898 commit 196bf74

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,29 @@
2121
},
2222
"author": "Titus Wormer <[email protected]> (https://wooorm.com)",
2323
"contributors": [
24-
"Titus Wormer <[email protected]> (https://wooorm.com)"
24+
"Titus Wormer <[email protected]> (https://wooorm.com)",
25+
"Christian Murphy <[email protected]>"
2526
],
2627
"files": [
27-
"index.js"
28+
"index.js",
29+
"types/index.d.ts"
2830
],
31+
"types": "types/index.d.ts",
2932
"dependencies": {
33+
"@types/hast": "^2.0.0",
3034
"hast-util-from-parse5": "^5.0.0",
3135
"hast-util-to-parse5": "^5.0.0",
3236
"html-void-elements": "^1.0.0",
3337
"parse5": "^5.0.0",
3438
"unist-util-position": "^3.0.0",
39+
"vfile": "^4.0.0",
3540
"web-namespaces": "^1.0.0",
3641
"xtend": "^4.0.0",
3742
"zwitch": "^1.0.0"
3843
},
3944
"devDependencies": {
4045
"browserify": "^16.0.0",
46+
"dtslint": "^3.0.0",
4147
"hastscript": "^5.0.0",
4248
"nyc": "^15.0.0",
4349
"prettier": "^2.0.0",
@@ -59,7 +65,8 @@
5965
"build": "npm run build-bundle && npm run build-mangle",
6066
"test-api": "node test",
6167
"test-coverage": "nyc --reporter lcov tape test.js",
62-
"test": "npm run format && npm run build && npm run test-coverage"
68+
"test-types": "dtslint types",
69+
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
6370
},
6471
"nyc": {
6572
"check-coverage": true,

types/hast-util-raw-test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import raw = require('hast-util-raw')
2+
import vFile = require('vfile')
3+
4+
raw({type: 'raw', value: 'example'}) // $ExpectType Node
5+
raw({type: 'element', tagName: 'div', properties: {}, children: []}) // $ExpectType Node
6+
// prettier-ignore
7+
raw({type: 'element', tagName: 'div', properties: {}, children: []}, vFile('test')) // $ExpectType Node
8+
9+
raw() // $ExpectError
10+
raw({}) // $ExpectError
11+
// prettier-ignore
12+
raw({type: 'element', tagName: 'div', properties: {}, children: []}, 'not a vFile') // $ExpectError

types/index.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Minimum TypeScript Version: 3.2
2+
3+
import {Node} from 'hast'
4+
import {VFile} from 'vfile'
5+
6+
/**
7+
* Given a hast tree and an optional vfile (for positional info), return a new parsed-again hast tree.
8+
* @param tree original hast tree
9+
* @param file positional info
10+
*/
11+
declare function raw(tree: Node, file?: VFile): Node
12+
13+
export = raw

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+
"hast-util-raw": ["index.d.ts"]
8+
}
9+
}
10+
}

types/tslint.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"no-redundant-jsdoc": false,
5+
"semicolon": false,
6+
"whitespace": false
7+
}
8+
}

0 commit comments

Comments
 (0)