Unable to check the type of node
See original GitHub issueI have a Yaml document with key, which can be either Yaml mapping with some configuration fields or a string as alias to some predefined configuration:
storage:
type: fs
location: /tmp/storage
# etc
or
storage: default # alias to default storage
Since Yaml language is dynamic, I’m expecting to read different node types for some key, but EoYaml doesn’t support node type checks. So I need to use workarounds like:
if (yaml.string("storage") == null) {
storage = fromConfig(yaml.mapping("storage"));
} else {
storage = storages.get(yaml.string("storage"));
}
It would be great if I could check the type of node and convert it to string or mapping if needed. E.g. like in javax.json
:
var node = yaml.node("storage");
if (node.type() == Node.STRING) {
storage = storages.get(node.asString());
} else if (node.type() == Node.MAPPING) {
storage = fromConfig(node.asMapping());
} else {
// throw something
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How do I check the type of error in Node JS? - Stack Overflow
1 Answer 1 ... The thing is that I can't do a method on the string like err.code.contains(); or toLowerCase. ... code is...
Read more >How to resolve 'node' is not recognized as an internal or ...
Open the Environment Variables option in your Control Panel. · Select the variable named Path. · Restart the command prompt again and now...
Read more >It's impossible to check 'self' object type because of the Parse ...
Create new script; Fill it with this code: extends Node func _ready(): if (self is Spatial): pass if (self is Node2D): pass.
Read more >Handling errors - Node-RED
These are a particular type of node.js error that can occur when a Node fails to properly handle an internal error. They cause...
Read more >Typescript compiler can t find node with yarn - Edureka
I have @types/node installed. I'm using Yarn 2 (PnP). Seems like Typescript can't find the @types/node package? Running yarn build with the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@g4s8 OK, let’s do it. I’ll take care of these issues in the weekend I think. Then we’ll release 5.0.0
@amihaiemil yes, I used old version with package private
Scalar
, now I can check it withinstanceof
, but it looks not really reliable: e.g. I may decorateNode
interface somehow, theninstanceof
won’t work. I think it would be better to have a method liketype()
to check the type of node, WDYT?