Skip to content

Commit

Permalink
Add types
Browse files Browse the repository at this point in the history
Closes GH-9.
Closes GH-10.

Reviewed-by: Remco Haszing <remcohaszing@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
ChristianMurphy committed Jul 6, 2020
1 parent 67a1898 commit e21922d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Christian Murphy <christian.murphy.42@gmail.com>"
],
"files": [
"index.js"
"index.js",
"types/index.d.ts"
],
"types": "types/index.d.ts",
"dependencies": {
"@types/hast": "^2.0.0",
"hast-util-from-parse5": "^5.0.0",
"hast-util-to-parse5": "^5.0.0",
"html-void-elements": "^1.0.0",
"parse5": "^5.0.0",
"unist-util-position": "^3.0.0",
"vfile": "^4.0.0",
"web-namespaces": "^1.0.0",
"xtend": "^4.0.0",
"zwitch": "^1.0.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"dtslint": "^3.0.0",
"hastscript": "^5.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
Expand All @@ -59,7 +65,8 @@
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run build && npm run test-coverage"
"test-types": "dtslint types",
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
},
"nyc": {
"check-coverage": true,
Expand Down
12 changes: 12 additions & 0 deletions types/hast-util-raw-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import raw = require('hast-util-raw')
import vFile = require('vfile')

raw({type: 'raw', value: 'example'}) // $ExpectType Node
raw({type: 'element', tagName: 'div', properties: {}, children: []}) // $ExpectType Node
// prettier-ignore
raw({type: 'element', tagName: 'div', properties: {}, children: []}, vFile('test')) // $ExpectType Node

raw() // $ExpectError
raw({}) // $ExpectError
// prettier-ignore
raw({type: 'element', tagName: 'div', properties: {}, children: []}, 'not a vFile') // $ExpectError
13 changes: 13 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Minimum TypeScript Version: 3.2

import {Node} from 'hast'
import {VFile} from 'vfile'

/**
* Given a hast tree and an optional vfile (for positional info), return a new parsed-again hast tree.
* @param tree original hast tree
* @param file positional info
*/
declare function raw(tree: Node, file?: VFile): Node

export = raw
10 changes: 10 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"lib": ["es2015"],
"strict": true,
"baseUrl": ".",
"paths": {
"hast-util-raw": ["index.d.ts"]
}
}
}
8 changes: 8 additions & 0 deletions types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"no-redundant-jsdoc": false,
"semicolon": false,
"whitespace": false
}
}

0 comments on commit e21922d

Please sign in to comment.