Skip to content

Commit 84e0376

Browse files
Add types (#5)
Co-authored-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com> Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
1 parent 99ba85d commit 84e0376

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@
2222
},
2323
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
2424
"contributors": [
25-
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
25+
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
26+
"Merlijn Vos <merlijn@soverin.net>"
2627
],
2728
"files": [
28-
"index.js"
29+
"index.js",
30+
"types/index.d.ts"
2931
],
32+
"types": "types/index.d.ts",
3033
"dependencies": {
3134
"unist-util-visit": "^2.0.0"
3235
},
3336
"devDependencies": {
3437
"browserify": "^16.0.0",
38+
"dtslint": "^3.0.0",
3539
"nyc": "^15.0.0",
3640
"prettier": "^2.0.0",
3741
"remark": "^12.0.0",
@@ -47,9 +51,10 @@
4751
"build-bundle": "browserify . -s unistUtilRemovePosition > unist-util-remove-position.js",
4852
"build-mangle": "browserify . -s unistUtilRemovePosition -p tinyify > unist-util-remove-position.min.js",
4953
"build": "npm run build-bundle && npm run build-mangle",
54+
"test-types": "dtslint types",
5055
"test-api": "node test",
5156
"test-coverage": "nyc --reporter lcov tape test.js",
52-
"test": "npm run format && npm run build && npm run test-coverage"
57+
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
5358
},
5459
"prettier": {
5560
"tabWidth": 2,
@@ -63,7 +68,7 @@
6368
"prettier": true,
6469
"esnext": false,
6570
"ignores": [
66-
"unist-util-remove-position.js"
71+
"types/"
6772
]
6873
},
6974
"nyc": {

types/index.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// TypeScript Version: 3.5
2+
3+
import {Node} from 'unist'
4+
5+
declare namespace unistUtilRemovePosition {
6+
interface NodeWithUndefinedPosition extends Node {
7+
position: undefined
8+
}
9+
10+
interface NodeWithoutPosition extends Omit<Node, 'position'> {}
11+
}
12+
13+
/**
14+
* Utility to remove positions from a tree
15+
*
16+
* @param node the unist tree
17+
* @param force if `force` is given, uses `delete`, otherwise, sets positions to `undefined`.
18+
*/
19+
declare function unistUtilRemovePosition(
20+
tree: Node,
21+
force?: false
22+
): unistUtilRemovePosition.NodeWithUndefinedPosition
23+
declare function unistUtilRemovePosition(
24+
tree: Node,
25+
force: true
26+
): unistUtilRemovePosition.NodeWithoutPosition
27+
28+
export = unistUtilRemovePosition

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

types/tslint.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "dtslint/dtslint.json",
3+
"rules": {
4+
"whitespace": false,
5+
"semicolon": false,
6+
"no-unnecessary-callback-wrapper": false
7+
}
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Node} from 'unist'
2+
3+
import remark = require('remark')
4+
5+
import removePosition = require('unist-util-remove-position')
6+
7+
const tree: Node = remark().parse(
8+
'Some _emphasis_, **importance**, and `code`.'
9+
)
10+
11+
// $ExpectType NodeWithUndefinedPosition
12+
removePosition(tree)
13+
14+
// $ExpectType NodeWithUndefinedPosition
15+
removePosition(tree, false)
16+
17+
// $ExpectType NodeWithoutPosition
18+
removePosition(tree, true)
19+
20+
// Used as a plugin
21+
void remark()
22+
.use(() => (tree) => removePosition(tree))
23+
.process('Some _emphasis_, **importance**, and `code`.')

0 commit comments

Comments
 (0)