-
-
Notifications
You must be signed in to change notification settings - Fork 1
Exposing node types as constants #2
Comments
I’m not sure about your argument for readability. How is your example more readable than the following? const { parse } = require('remark')
parse(markdown).children.forEach(node => {
if (node.type === 'heading') {
// do something for headings
} else if (node.type === 'paragraph') {
// do something for paragraphs
}
}) I have been thinking about using the |
The word readability was a little misleading. Sorry for that. But it is sometimes considered as an antipattern to put string literals directly in source code, especially when the string literal works like a symbol or enum. For example, see this. So what I do in my source code for now is like the below. const { parse } = require('remark')
const { HEADING, PARAGRAPH } = require('./my-constant-module')
parse(markdown).children.forEach(node => {
if (node.type === HEADING) {
// do something for headings
} else if (node.type === PARAGRAPH) {
// do something for paragraphs
}
}) If remark provides the type strings officially, I don't need define types by myself and the code would look more legitimate.
That would be great! |
@kt3k Would you like to work on an |
@wooorm Yes! I'm glad to contribute what I've suggested. |
Alright! I added you to the |
Thanks! I joined @syntax-tree org. I started working on Please review it when I finished scaffolding the test settings. |
Super! Looks like a good start! |
I added bundling (microbundle), testing (tape & babel), lint (xo), coverage(nyc & codecov) and ci (travis). I put the type constants in index.js and confirmed they exist in test cases. I think I've done what I can do for now! 😄 I used microbundle because it seemed easier to configure than other tools, but I found that it only supports node >= 6.x. If that's a problem for mdastscript, then I'll switch bundling tool to another one. I guessed the description of mdastscript as |
Thanks for starting the discussion @kt3k ! |
How about exposing node types (strings) as constants of remark module?
It would increase the readability of dependent modules.
The text was updated successfully, but these errors were encountered: