Skip to content

Commit 8e28095

Browse files
authored
Add types
Closes GH-5. 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 80cd92d commit 8e28095

7 files changed

+70
-9
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
coverage/
22
mdast-util-definitions.js
33
mdast-util-definitions.min.js
4+
*.md

package.json

+10-7
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,30 @@
3030
"index.js"
3131
],
3232
"dependencies": {
33+
"@types/mdast": "^3.0.3",
3334
"unist-util-visit": "^2.0.0"
3435
},
3536
"devDependencies": {
3637
"browserify": "^16.0.0",
38+
"dtslint": "^3.4.2",
3739
"nyc": "^15.0.0",
38-
"prettier": "^1.0.0",
39-
"remark": "^11.0.0",
40-
"remark-cli": "^7.0.0",
41-
"remark-preset-wooorm": "^6.0.0",
40+
"prettier": "^2.0.5",
41+
"remark": "^12.0.0",
42+
"remark-cli": "^8.0.0",
43+
"remark-preset-wooorm": "^7.0.0",
4244
"tape": "^4.0.0",
4345
"tinyify": "^2.0.0",
44-
"xo": "^0.26.0"
46+
"xo": "^0.29.1"
4547
},
4648
"scripts": {
47-
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
49+
"format": "remark . -qfo && prettier --write . && xo --fix --ignore types",
4850
"build-bundle": "browserify . -s mdastUtilDefinitions > mdast-util-definitions.js",
4951
"build-mangle": "browserify . -s mdastUtilDefinitions -p tinyify > mdast-util-definitions.min.js",
5052
"build": "npm run build-bundle && npm run build-mangle",
5153
"test-api": "node test",
5254
"test-coverage": "nyc --reporter lcov tape test.js",
53-
"test": "npm run format && npm run build && npm run test-coverage"
55+
"test-types": "dtslint types",
56+
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
5457
},
5558
"nyc": {
5659
"check-coverage": true,

test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ var test = require('tape')
44
var remark = require('remark')
55
var definitions = require('.')
66

7-
test('mdast-util-definitions', function(t) {
7+
test('mdast-util-definitions', function (t) {
88
var getDefinition
99
var tree
1010

1111
t.throws(
12-
function() {
12+
function () {
1313
definitions()
1414
},
1515
/mdast-util-definitions expected node/,

types/index.d.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Minimum TypeScript Version: 3.2
2+
import {Node} from 'unist'
3+
import {Definition} from 'mdast'
4+
5+
declare namespace definitions {
6+
interface Options {
7+
/**
8+
* Turn on (`true`) to use CommonMark precedence: ignore definitions found later for duplicate definitions. The default behavior is to prefer the last found definition.
9+
*
10+
* @default false
11+
*/
12+
commonmark: boolean
13+
}
14+
15+
/**
16+
* @param identifier [Identifier](https://github.com/syntax-tree/mdast#association) of [definition](https://github.com/syntax-tree/mdast#definition).
17+
*/
18+
type DefinitionCache = (identifier: string) => Definition | null
19+
}
20+
21+
/**
22+
* Create a cache of all [definition](https://github.com/syntax-tree/mdast#definition)s in [`node`](https://github.com/syntax-tree/unist#node).
23+
*/
24+
declare function definitions(
25+
node: Node,
26+
options?: definitions.Options
27+
): definitions.DefinitionCache
28+
29+
export = definitions

types/mdast-util-definitions-tests.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import remark = require('remark')
2+
import definitions = require('mdast-util-definitions')
3+
4+
const ast = remark().parse('[example]: https://example.com "Example"')
5+
6+
const definition = definitions(ast)
7+
8+
definition('example')
9+
10+
definition('foo')

types/tsconfig.json

+10
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+
"mdast-util-definitions": ["index.d.ts"]
8+
}
9+
}
10+
}

types/tslint.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"no-redundant-jsdoc": false,
5+
"semicolon": false,
6+
"whitespace": false
7+
}
8+
}

0 commit comments

Comments
 (0)