Skip to content

Add types #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]> (https://wooorm.com)",
"contributors": [
"Titus Wormer <[email protected]> (https://wooorm.com)"
"Titus Wormer <[email protected]> (https://wooorm.com)",
"Christian Murphy <[email protected]>"
],
"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
}
}