Skip to content

Commit

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

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
stefanprobst authored Oct 18, 2020
1 parent d714e93 commit ba3a801
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
"Ohtake Tomohiro <ohtake.tomohiro@jp.fujitsu.com>"
],
"files": [
"index.js"
"index.js",
"types/index.d.ts"
],
"types": "types",
"dependencies": {},
"devDependencies": {
"browserify": "^17.0.0",
"dtslint": "^4.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark": "^13.0.0",
Expand All @@ -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,
Expand All @@ -72,7 +76,8 @@
"unicorn/prefer-includes": "off"
},
"ignores": [
"strip-markdown.js"
"strip-markdown.js",
"types/index.d.ts"
]
},
"remarkConfig": {
Expand Down
47 changes: 47 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// TypeScript Version: 3.0

import {Plugin} 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 const strip: Plugin<[strip.Options?]>

export = strip
8 changes: 8 additions & 0 deletions types/test.ts
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es2015"],
"strict": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"strip-markdown": ["."]
}
}
}
7 changes: 7 additions & 0 deletions types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"semicolon": false,
"whitespace": false
}
}

0 comments on commit ba3a801

Please sign in to comment.