Skip to content

Commit 3100da1

Browse files
ChristianMurphywooorm
authored andcommitted
Add types
Closes GH-7. Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent ba5fbb2 commit 3100da1

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@
3131
"author": "Eugene Sharygin <eush77@gmail.com>",
3232
"contributors": [
3333
"Eugene Sharygin <eush77@gmail.com>",
34-
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
34+
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
35+
"Christian Murphy <christian.murphy.42@gmail.com>"
3536
],
3637
"files": [
3738
"index.js",
38-
"lib/"
39+
"lib/",
40+
"types/index.d.ts"
3941
],
42+
"types": "types/index.d.ts",
4043
"dependencies": {
4144
"css-selector-parser": "^1.1.0",
4245
"not": "^0.1.0",
@@ -45,6 +48,7 @@
4548
"zwitch": "^1.0.3"
4649
},
4750
"devDependencies": {
51+
"dtslint": "^0.9.9",
4852
"nyc": "^14.0.0",
4953
"prettier": "^1.0.0",
5054
"remark-cli": "^6.0.0",
@@ -57,7 +61,8 @@
5761
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
5862
"test-api": "node test",
5963
"test-coverage": "nyc --reporter lcov tape test/index.js",
60-
"test": "npm run format && npm run test-coverage"
64+
"test-types": "dtslint types",
65+
"test": "npm run format && npm run test-coverage && npm run test-types"
6166
},
6267
"nyc": {
6368
"check-coverage": true,

types/index.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// TypeScript Version: 3.5
2+
3+
import {Node} from 'unist'
4+
5+
/**
6+
* Is there a match for the given selector in the Unist tree
7+
*
8+
* @param selector CSS-like selector
9+
* @param tree Unist node or tree of nodes to search
10+
*/
11+
declare function matches(selector: string, tree: Node): boolean
12+
13+
/**
14+
* Find first Node that matches selector
15+
*
16+
* @param selector CSS-like selector
17+
* @param tree Unist node or tree of nodes to search
18+
*/
19+
declare function select(selector: string, tree: Node): Node | null
20+
21+
/**
22+
* Find all Nodes that match selector
23+
*
24+
* @param selector CSS-like selector
25+
* @param tree Unist node or tree of nodes to search
26+
*/
27+
declare function selectAll(selector: string, tree: Node): Node[]
28+
29+
export {matches, select, selectAll}

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+
"unist-util-select": ["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+
"whitespace": false,
5+
"semicolon": false
6+
}
7+
}

types/unist-util-select-tests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {matches, select, selectAll} from 'unist-util-select'
2+
3+
matches() // $ExpectError
4+
matches('*') // $ExpectError
5+
matches('*', {type: 'root'}) // $ExpectType boolean
6+
7+
select() // $ExpectError
8+
select('*') // $ExpectError
9+
select('*', {type: 'root'}) // $ExpectType Node | null
10+
11+
selectAll() // $ExpectError
12+
selectAll('*') // $ExpectError
13+
selectAll('*', {type: 'root'}) // $ExpectType Node[]

0 commit comments

Comments
 (0)