Skip to content

Commit 635ad84

Browse files
BarryThePenguinwooorm
authored andcommitted
Add types
Related GH-28. Closes GH-29. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Junyoung Choi <fluke8259@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent 2385f87 commit 635ad84

File tree

6 files changed

+68
-4
lines changed

6 files changed

+68
-4
lines changed

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@
2828
"Jonathan Haines <jonno.haines@gmail.com>",
2929
"Robin Millette <robin@millette.info>"
3030
],
31+
"types": "types/index.d.ts",
3132
"files": [
33+
"types/index.d.ts",
3234
"index.js"
3335
],
3436
"dependencies": {
35-
"mdast-util-toc": "^4.0.0"
37+
"@types/unist": "^2.0.3",
38+
"mdast-util-toc": "^5.0.0"
3639
},
3740
"devDependencies": {
3841
"browserify": "^16.0.0",
42+
"dtslint": "^2.0.0",
3943
"is-hidden": "^1.1.0",
4044
"negate": "^1.0.0",
4145
"nyc": "^14.0.0",
@@ -45,7 +49,7 @@
4549
"remark-preset-wooorm": "^6.0.0",
4650
"tape": "^4.0.0",
4751
"tinyify": "^2.0.0",
48-
"xo": "^0.24.0"
52+
"xo": "^0.25.0"
4953
},
5054
"scripts": {
5155
"format": "remark *.md -qfo && prettier --write \"**/*.js\" && xo --fix",
@@ -54,7 +58,8 @@
5458
"build": "npm run build-bundle && npm run build-mangle",
5559
"test-api": "node test",
5660
"test-coverage": "nyc --reporter lcov tape test/index.js",
57-
"test": "npm run format && npm run build && npm run test-coverage"
61+
"test-types": "dtslint types",
62+
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
5863
},
5964
"prettier": {
6065
"tabWidth": 2,

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test('Fixtures', function(t) {
4242

4343
try {
4444
config = JSON.parse(read(join(filepath, 'config.json')))
45-
} catch (error) {
45+
} catch (_) {
4646
config = {}
4747
}
4848

types/index.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Minimum TypeScript Version: 3.2
2+
3+
import {Node} from 'unist'
4+
import {TOCOptions} from 'mdast-util-toc'
5+
6+
declare namespace remarkToc {
7+
type TOCSettings = Pick<TOCOptions, 'heading' | 'maxDepth' | 'tight' | 'skip'>;
8+
}
9+
10+
/**
11+
* Generate a Table of Contents.
12+
*
13+
* @param settings configuration for generating the table of contents
14+
*/
15+
declare function remarkToc(
16+
settings?: remarkToc.TOCSettings
17+
): (node: Node) => void
18+
19+
export = remarkToc

types/remark-toc-tests.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import remark = require('remark')
2+
3+
import toc = require('remark-toc')
4+
5+
remark().use(toc)
6+
7+
remark().use(toc, {})
8+
9+
remark().use(toc, {
10+
heading: 'heading'
11+
})
12+
13+
remark().use(toc, {
14+
maxDepth: 2
15+
})
16+
17+
remark().use(toc, {
18+
tight: true
19+
})
20+
21+
remark().use(toc, {
22+
skip: 'skip-heading'
23+
})

types/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["es2015"],
4+
"strict": true,
5+
"baseUrl": ".",
6+
"paths": {
7+
"remark-toc": ["index.d.ts"]
8+
}
9+
}
10+
}

types/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)