Skip to content
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

feat: add types #21

Merged
merged 3 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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": "^16.0.0",
"dtslint": "^4.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark": "^13.0.0-alpha.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"
stefanprobst marked this conversation as resolved.
Show resolved Hide resolved
]
},
"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 {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'
wooorm marked this conversation as resolved.
Show resolved Hide resolved
>
}
}

/**
* 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
stefanprobst marked this conversation as resolved.
Show resolved Hide resolved

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
}
}