-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add types #3
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
Add types #3
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
eba500f
adds type definitions
guillaumegarcia13 200fc95
Update package.json
guillaumegarcia13 598c89e
Update types/index.d.ts
guillaumegarcia13 43834f1
Update types/index.d.ts
guillaumegarcia13 8134e93
amends based on reviews
guillaumegarcia13 10891a0
Merge branch 'main' of https://github.com/guillaumegarcia13/unist-uti…
guillaumegarcia13 43afc88
adds tslint.json
guillaumegarcia13 c230075
fixes formatting
guillaumegarcia13 6baa5db
adds type test
guillaumegarcia13 027e875
Update types/test.ts
guillaumegarcia13 7d68fe3
Update types/index.d.ts
guillaumegarcia13 931878b
Update types/index.d.ts
guillaumegarcia13 3f226b3
Update package.json
guillaumegarcia13 8ab150d
adds fixes
guillaumegarcia13 ab3d07f
fixes multiple export with same name
guillaumegarcia13 f965220
changes syntax to matcht unist-builder's one
guillaumegarcia13 6a4f5a5
fixes superfluous declare
guillaumegarcia13 93006d4
Update types/index.d.ts
guillaumegarcia13 b37a296
adds options within namespace
guillaumegarcia13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// TypeScript Version: 3.5 | ||
|
||
import {Node} from 'unist' | ||
import {Test} from 'unist-util-is' | ||
|
||
export interface RemoveOptions { | ||
/** | ||
* Whether to drop parent nodes if they had children, but all their children were filtered out test | ||
*/ | ||
cascade?: boolean | ||
} | ||
|
||
/** | ||
* | ||
* Mutate the given tree by removing all nodes that pass test. The tree is walked in preorder (NLR), visiting the node itself, then its head, etc. | ||
* | ||
* @param tree Tree to filter | ||
* @param test is-compatible test (such as a type) | ||
*/ | ||
export function remove<T extends Node>(tree: T, test?: Test<Node>): T | null | ||
/** | ||
* | ||
* Mutate the given tree by removing all nodes that pass test. The tree is walked in preorder (NLR), visiting the node itself, then its head, etc. | ||
* | ||
* @param tree Tree to filter | ||
* @param options Whether to drop parent nodes if they had children, but all their children were filtered out. Default is {cascade: true} | ||
* @param test is-compatible test (such as a type) | ||
*/ | ||
export function remove<T extends Node>( | ||
tree: T, | ||
options?: RemoveOptions, | ||
guillaumegarcia13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
test?: Test<Node> | ||
): T | null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {remove} from 'uninst-util-remove'; | ||
import * as u from 'unist-builder'; | ||
|
||
const tree = u('root', [ | ||
u('leaf', '1'), | ||
u('node', [ | ||
u('leaf', '2'), | ||
u('node', [u('leaf', '3'), u('other', '4')]), | ||
u('node', [u('leaf', '5')]) | ||
]), | ||
u('leaf', '6') | ||
]); | ||
|
||
remove() // $ExpectError | ||
remove('leaf') // $ExpectError | ||
|
||
remove(tree) | ||
remove(tree, 'leaf'); | ||
remove(tree, {cascade: false}, 'leaf'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "es2015", | ||
"lib": ["es2015"], | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"noEmit": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"uninst-util-remove": ["."] | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"no-redundant-jsdoc": false, | ||
"no-redundant-jsdoc-2": true, | ||
"semicolon": false, | ||
"whitespace": false | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is exported using
module.exports = remove
.To reflect this correctly in the types, this should be exported using: