Re:Jtc – CLI tool to extract, manipulate and transform sourc...
by zeroimpl on Wednesday October 09, 2019 @07:58PM
(#21209500)
Something like this would do the same, if somebody implemented a tool called jsed:
jsed '
Object.fromEntries(
$("Directory").map(
x => [
x.name + " has children",
x.children && x.children.length != 0
]
)
)'
Interestingly enough there is already a tool called jsed which seems to kind of do this... https://www.npmjs.com/package/jsedEdit: Note the jQuery part of it is for advanced cases like searching for specific nodes in the tree, then navigating back up to the parent. Basically the cases like "<Work>[-1][children]" from the jtc guide, I would write as: '$("Work").parent().find("children")'
Here's an explanation of the syntax in the command I posted:
> IMO the ideal solution is something using pure JavaScript syntaxThe greatest advantage of the current syntax is the great balance it has between legibility and terseness. I don't think making it pure JavaScript would be better.
> possibly with a library resembling jQuery for tree traversal
Using jQuery in JavaScript to traverse JavaScript objects? I don't know what to say...