From 8f3df5575934476dda87ccf1c6caee851a61a842 Mon Sep 17 00:00:00 2001 From: Stefan Probst Date: Sun, 11 Oct 2020 20:59:39 +0200 Subject: [PATCH 1/2] feat: add types --- package.json | 11 ++++++++--- types/index.d.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++ types/test.ts | 8 ++++++++ types/tsconfig.json | 12 ++++++++++++ types/tslint.json | 7 +++++++ 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 types/index.d.ts create mode 100644 types/test.ts create mode 100644 types/tsconfig.json create mode 100644 types/tslint.json diff --git a/package.json b/package.json index a26b322..2a614a2 100644 --- a/package.json +++ b/package.json @@ -26,11 +26,14 @@ "Ohtake Tomohiro " ], "files": [ - "index.js" + "index.js", + "types/index.d.ts" ], + "types": "types", "dependencies": {}, "devDependencies": { "browserify": "^16.0.0", + "dtslint": "^4.0.0", "nyc": "^15.0.0", "prettier": "^2.0.0", "remark": "^13.0.0-alpha.0", @@ -48,7 +51,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, @@ -72,7 +76,8 @@ "unicorn/prefer-includes": "off" }, "ignores": [ - "strip-markdown.js" + "strip-markdown.js", + "types/index.d.ts" ] }, "remarkConfig": { diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..05574a2 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,47 @@ +// TypeScript Version: 3.0 + +import {Transformer} from 'unified' + +declare namespace strip { + interface Options { + /** + * List of node types to leave unchanged. + */ + keep?: Array< + | 'heading' + | 'text' + | 'inlineCode' + | 'image' + | 'imageReference' + | 'break' + | 'blockquote' + | 'list' + | 'listItem' + | 'strong' + | 'emphasis' + | 'delete' + | 'link' + | 'linkReference' + | 'code' + | 'horizontalRule' + | 'thematicBreak' + | 'html' + | 'table' + | 'tableCell' + | 'definition' + | 'yaml' + | 'toml' + > + } +} + +/** + * Remark plugin to remove Markdown formatting. + * + * Removes `html`, `code`, `horizontalRule`, `table`, `yaml`, `toml` nodes and their content, + * everything else is rendered as simple paragraphs without formatting. + * Uses `alt` text for images. + */ +declare function strip(options?: strip.Options): Transformer + +export = strip diff --git a/types/test.ts b/types/test.ts new file mode 100644 index 0000000..2c4b72d --- /dev/null +++ b/types/test.ts @@ -0,0 +1,8 @@ +import remark = require('remark') +import strip = require('strip-markdown') + +remark().use(strip) +remark().use(strip, {keep: []}) +remark().use(strip, {keep: [`table`]}) + +remark().use(strip, {keep: [`typo`]}) // $ExpectError diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..08ebe63 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es2015"], + "strict": true, + "noEmit": true, + "baseUrl": ".", + "paths": { + "strip-markdown": ["."] + } + } +} 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 + } +} From 84e9d1b9b8fd28e4bbcf2128109e96a40d1f6c63 Mon Sep 17 00:00:00 2001 From: Stefan Probst Date: Mon, 12 Oct 2020 18:52:31 +0200 Subject: [PATCH 2/2] fix: use unified.Plugin instead of Transformer --- types/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 05574a2..72986c2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,6 +1,6 @@ // TypeScript Version: 3.0 -import {Transformer} from 'unified' +import {Plugin} from 'unified' declare namespace strip { interface Options { @@ -42,6 +42,6 @@ declare namespace strip { * everything else is rendered as simple paragraphs without formatting. * Uses `alt` text for images. */ -declare function strip(options?: strip.Options): Transformer +declare const strip: Plugin<[strip.Options?]> export = strip