Skip to content

Add types #7

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

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
"author": "Eugene Sharygin <eush77@gmail.com>",
"contributors": [
"Eugene Sharygin <eush77@gmail.com>",
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Christian Murphy <christian.murphy.42@gmail.com>"
],
"files": [
"index.js",
"lib/"
"lib/",
"types/index.d.ts"
],
"types": "types/index.d.ts",
"dependencies": {
"css-selector-parser": "^1.1.0",
"not": "^0.1.0",
Expand All @@ -45,6 +48,7 @@
"zwitch": "^1.0.3"
},
"devDependencies": {
"dtslint": "^0.9.9",
"nyc": "^14.0.0",
"prettier": "^1.0.0",
"remark-cli": "^6.0.0",
Expand All @@ -57,7 +61,8 @@
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test": "npm run format && npm run test-coverage"
"test-types": "dtslint types",
"test": "npm run format && npm run test-coverage && npm run test-types"
},
"nyc": {
"check-coverage": true,
Expand Down
29 changes: 29 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// TypeScript Version: 3.5

import {Node} from 'unist'

/**
* Is there a match for the given selector in the Unist tree
*
* @param selector CSS-like selector
* @param tree Unist node or tree of nodes to search
*/
declare function matches(selector: string, tree: Node): boolean

/**
* Find first Node that matches selector
*
* @param selector CSS-like selector
* @param tree Unist node or tree of nodes to search
*/
declare function select(selector: string, tree: Node): Node | null

/**
* Find all Nodes that match selector
*
* @param selector CSS-like selector
* @param tree Unist node or tree of nodes to search
*/
declare function selectAll(selector: string, tree: Node): Node[]

export {matches, select, selectAll}
10 changes: 10 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"lib": ["es2015"],
"strict": true,
"baseUrl": ".",
"paths": {
"unist-util-select": ["index.d.ts"]
}
}
}
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": {
"whitespace": false,
"semicolon": false
}
}
13 changes: 13 additions & 0 deletions types/unist-util-select-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {matches, select, selectAll} from 'unist-util-select'

matches() // $ExpectError
matches('*') // $ExpectError
matches('*', {type: 'root'}) // $ExpectType boolean

select() // $ExpectError
select('*') // $ExpectError
select('*', {type: 'root'}) // $ExpectType Node | null

selectAll() // $ExpectError
selectAll('*') // $ExpectError
selectAll('*', {type: 'root'}) // $ExpectType Node[]