diff --git a/package.json b/package.json index a78869f..c63c352 100644 --- a/package.json +++ b/package.json @@ -21,23 +21,29 @@ }, "author": "Titus Wormer (https://wooorm.com)", "contributors": [ - "Titus Wormer (https://wooorm.com)" + "Titus Wormer (https://wooorm.com)", + "Christian Murphy " ], "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", @@ -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, diff --git a/types/hast-util-raw-test.ts b/types/hast-util-raw-test.ts new file mode 100644 index 0000000..dbc1b6b --- /dev/null +++ b/types/hast-util-raw-test.ts @@ -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 diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..41c4e57 --- /dev/null +++ b/types/index.d.ts @@ -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 diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..5c7afd5 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "lib": ["es2015"], + "strict": true, + "baseUrl": ".", + "paths": { + "hast-util-raw": ["index.d.ts"] + } + } +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..759caa0 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,8 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "no-redundant-jsdoc": false, + "semicolon": false, + "whitespace": false + } +}