From c5a4eae07cd3c2e4063015d127c655bdb6295211 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Tue, 19 May 2020 15:10:48 +0200 Subject: [PATCH] Add types Reviewed-by: Christian Murphy Reviewed-by: Titus Wormer Closes GH-13. --- .prettierignore | 1 + package.json | 12 ++++++++---- types/index.d.ts | 7 +++++++ types/remark-rehype-tests.ts | 10 ++++++++++ types/tsconfig.json | 10 ++++++++++ types/tslint.json | 7 +++++++ 6 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 types/index.d.ts create mode 100644 types/remark-rehype-tests.ts create mode 100644 types/tsconfig.json create mode 100644 types/tslint.json diff --git a/.prettierignore b/.prettierignore index 947ee36..1a5ae74 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ coverage/ remark-rehype.js remark-rehype.min.js +**/*.md diff --git a/package.json b/package.json index e3054f0..e06f110 100644 --- a/package.json +++ b/package.json @@ -27,13 +27,16 @@ "John Otander (https://johno.com)" ], "files": [ - "index.js" + "index.js", + "types/index.d.ts" ], + "types": "types/index.d.ts", "dependencies": { - "mdast-util-to-hast": "^8.0.0" + "mdast-util-to-hast": "^9.1.0" }, "devDependencies": { "browserify": "^16.0.0", + "dtslint": "^3.4.1", "nyc": "^15.0.0", "prettier": "^2.0.0", "rehype-stringify": "^6.0.0", @@ -47,13 +50,14 @@ "xo": "^0.28.0" }, "scripts": { - "format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", + "format": "remark . -qfo && prettier --write . && xo --fix", "build-bundle": "browserify . -s remarkRehype > remark-rehype.js", "build-mangle": "browserify . -s remarkRehype -p tinyify > remark-rehype.min.js", "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/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..2fab5a9 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,7 @@ +// Minimum TypeScript Version: 3.2 +import {Plugin, Processor} from 'unified' +import {Options} from 'mdast-util-to-hast' + +declare const remark2rehype: Plugin<[Options?] | [Processor?, Options?]> + +export = remark2rehype diff --git a/types/remark-rehype-tests.ts b/types/remark-rehype-tests.ts new file mode 100644 index 0000000..3616c54 --- /dev/null +++ b/types/remark-rehype-tests.ts @@ -0,0 +1,10 @@ +import unified = require('unified') +import remark2rehype = require('remark-rehype') + +unified().use(remark2rehype) + +unified().use(remark2rehype, {allowDangerousHtml: true}) + +unified().use(remark2rehype, unified()) + +unified().use(remark2rehype, unified(), {allowDangerousHtml: true}) diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..3884b4e --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "lib": ["es2015"], + "strict": true, + "baseUrl": ".", + "paths": { + "remark-rehype": ["index.d.ts"] + } + } +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..70c4494 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false, + "whitespace": false + } +}