Skip to content

Commit 676f79a

Browse files
committed
Add types
1 parent a9d53ed commit 676f79a

File tree

5 files changed

+86
-3
lines changed

5 files changed

+86
-3
lines changed

index.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Minimum TypeScript Version: 3.0
2+
import {
3+
Buffer,
4+
BufferEncoding,
5+
SyntaxExtension,
6+
Token
7+
} from 'micromark/dist/shared-types'
8+
import {Root} from 'mdast'
9+
import {Type} from 'micromark/dist/constant/types'
10+
11+
export = fromMarkdown
12+
13+
declare namespace fromMarkdown {}
14+
15+
interface MdastExtension {
16+
enter: Record<Type, (token: Token) => void>
17+
exit: Record<Type, (token: Token) => void>
18+
}
19+
20+
interface Options {
21+
extensions?: SyntaxExtension[]
22+
mdastExtensions?: MdastExtension[]
23+
}
24+
25+
declare function fromMarkdown(value: string | Buffer, options?: Options): Root
26+
27+
declare function fromMarkdown(
28+
value: string | Buffer,
29+
encoding?: BufferEncoding,
30+
options?: Options
31+
): Root

mdast-util-from-markdown.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file is for https://github.com/microsoft/dtslint .
2+
// Tests are type-checked, but not run.
3+
4+
import * as formMarkdown from 'mdast-util-from-markdown'
5+
6+
function main() {
7+
const raw = '# text **strong**'
8+
9+
// $ExpectType Root
10+
formMarkdown(raw)
11+
12+
// $ExpectType Root
13+
formMarkdown(Buffer.alloc(8))
14+
15+
// $ExpectType Root
16+
formMarkdown(Buffer.alloc(8), {extensions: []})
17+
18+
// $ExpectType Root
19+
formMarkdown(Buffer.alloc(8), 'utf-8', {mdastExtensions: []})
20+
21+
// $ExpectError
22+
formMarkdown(Buffer.alloc(8), 'utf-8', {allowDangerousHtml: true})
23+
}
24+
25+
main()

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@
2727
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
2828
],
2929
"files": [
30-
"index.js"
30+
"index.js",
31+
"index.d.ts"
3132
],
33+
"types": "index.d.ts",
3234
"dependencies": {
35+
"@types/mdast": "^3.0.0",
3336
"mdast-util-to-string": "^1.0.0",
34-
"micromark": "~2.9.0",
37+
"micromark": "~2.10.0",
3538
"parse-entities": "^2.0.0"
3639
},
3740
"devDependencies": {
3841
"browserify": "^16.0.0",
3942
"commonmark.json": "^0.29.0",
43+
"dtslint": "^4.0.0",
4044
"gzip-size-cli": "^3.0.0",
4145
"hast-util-to-html": "^7.0.0",
4246
"mdast-util-to-hast": "^10.0.0",
@@ -57,7 +61,8 @@
5761
"generate": "npm run generate-size",
5862
"test-api": "node test",
5963
"test-coverage": "nyc --reporter lcov tape test/index.js",
60-
"test": "npm run format && npm run generate && npm run test-coverage"
64+
"test-types": "dtslint .",
65+
"test": "npm run format && npm run generate && npm run test-coverage && npm run test-types"
6166
},
6267
"nyc": {
6368
"check-coverage": true,

tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"moduleResolution": "node",
4+
"lib": [
5+
"ES5"
6+
],
7+
"strict": true,
8+
"baseUrl": ".",
9+
"paths": {
10+
"mdast-util-from-markdown": [
11+
"index.d.ts"
12+
]
13+
}
14+
}
15+
}

tslint.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"semicolon": false,
5+
"whitespace": false
6+
}
7+
}

0 commit comments

Comments
 (0)