Skip to content
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

Node class could have new methods for finding nodes among its direct children content and its descendants #1477

Closed
KevinVerre opened this issue Jul 8, 2024 · 1 comment

Comments

@KevinVerre
Copy link

I would love it if the Node class had more methods. That way, we wouldn't have to write our own helper functions. We write these helper functions using node.descendants(). An example of a helper function that is useful is to take the current Node and return all of the children nodes or descendant nodes with a particular type.

function getDescendantsWithType(node: Node, targetType: NodeType): Node[]
function getDirectChildrenWithType(node: Node, targetType: NodeType): Node[]

@marijnh
Copy link
Member

marijnh commented Jul 9, 2024

Since these are simple enough to implement on top of descendants, and the precise form they take will be different per use case (sometimes you need just the node, sometimes the node and its position, sometimes its parent, etc), I feel it's fine to have people implement these as custom functions in their own codebase.

@marijnh marijnh closed this as completed Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants