Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// $ExpectType TreeNode
createNode("div", { prop1: "prop1", prop2: ["expression", "x=2"] }, []);
// $ExpectType Node[]
getChildren(ast[0]);
// $ExpectType void
walkNodes(ast, (n: Node) => {
(n as TreeNode)[0] = "funky-name";
});
// $ExpectType Node[]
findNodes(ast, n => n instanceof Array);
// $ExpectType Node
modifyChildren(ast[0], (n: Node) => {
if (typeof n === "object") {
n[0] = "somename";
}
});
// $ExpectType Node[]
getNodesByName(ast, "h1");
// $ExpectType Node
filterChildren(ast[1], n => n === "world");
// $ExpectType Node[] || AST
filterNodes(ast, n => (n instanceof Object ? n[0] === "h1" : false));
// $ExpectType Node[] || AST
modifyNodesByName(ast, "h2", n => {
typeof n === "object" ? (n[1] = []) : undefined;
return node;
}
var id = IdyllAST.getProperty(node, 'id');
if(id === undefined) {
return node;
}
var compare = id[1] === key
// console.log('id[1]',id[1],'key',key,compare)
if( compare ) {
console.log('mod block')
found = true;
return newNode;
}
node = IdyllAST.modifyChildren(node, handleNode);
return node;
}
return modifyNodesByName(ast, 'TextContainer', (node) => {
return modifyChildren(node, (child) => {
if (typeof child === 'string') {
return ['p', [], [child]];
}
return child;
})
})
};
function autoLinkifyHelper(node) {
if(typeof node === 'string') {
return hyperLinkifiedVersion(node);
} else if (['a', 'code', 'pre', 'equation'].indexOf(getNodeName(node).toLowerCase()) > -1){
return node;
} else {
return modifyChildren(node, autoLinkifyHelper);
}
}