Giter VIP home page Giter VIP logo

Comments (7)

ChristianMurphy avatar ChristianMurphy commented on May 27, 2024 1

https://github.com/syntax-tree/unist-util-visit/pull/16/files#diff-fbc098e48a28691a544d0b13581a96af should give a better picture of how this can work cross-project.
There are tests for a remark heading node and a rehype element node.

from unist-util-visit.

wooorm avatar wooorm commented on May 27, 2024 1

Released as well!

from unist-util-visit.

ChristianMurphy avatar ChristianMurphy commented on May 27, 2024

Ideally when a function is passed as a test, it should be able to define a type predicate, and verify that the type passed to the visitor matches
https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates

from unist-util-visit.

ChristianMurphy avatar ChristianMurphy commented on May 27, 2024

Also ideally if a string is passed for a test, TypeScript should verify that the string value matches the type of the node.
For example

interface HeadingNode extends ParentNode {
  type: 'heading'
  depth: number
}

// valid
unistUntiVisit(tree, 'heading', (node: HeadingNode) => {...})

// not valid
unistUntiVisit(tree, 'not-a-heading', (node: HeadingNode) => {...})

from unist-util-visit.

wooorm avatar wooorm commented on May 27, 2024

How would type work with the different syntax es, and with custom nodes?

from unist-util-visit.

ChristianMurphy avatar ChristianMurphy commented on May 27, 2024

My goal is to keep it generic.
The only requirement that I am aware of is that what gets passed as tree and what gets passed as node, must extend unist Node. In that they must have a typeattribute.
Everything else should be flexible enough to support unist, mdast, mdxast, hast and redot.

from unist-util-visit.

wooorm avatar wooorm commented on May 27, 2024

Perfect!

from unist-util-visit.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.