Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const mapNode = node as YamlMap;
const mergedMap = ([] as { path: ReadonlyArray<(string | number)>, node: YAMLNode }[]).concat(...(mapNode.mappings.map(
(childNode) => extractAllPaths(childNode, [...curPath]))));
return [...mergedMap];
case Kind.MAPPING:
const mappingNode = node as YAMLMapping;
if (mappingNode.value) {
return [
{ path: [...curPath, mappingNode.key.value], node: mappingNode },
...extractAllPaths(mappingNode.value, [...curPath, mappingNode.key.value])
];
}
break;
case Kind.SCALAR:
const scalarNode = node as YAMLScalar;
if (scalarNode.parent && scalarNode.parent.kind == Kind.SEQ) {
return [{ path: curPath, node: scalarNode }];
} else {
return [{ path: curPath, node: scalarNode.parent }];
}
case Kind.SEQ:
const seqNode = node as YAMLSequence;
const mergedSequence = ([] as { path: ReadonlyArray<(string | number)>, node: YAMLNode }[]).concat(...(seqNode.items.map(
(childNode, index) => extractAllPaths(childNode, [...curPath, index]))));
return [...mergedSequence];
case Kind.INCLUDE_REF:
case Kind.ANCHOR_REF:
const refNode = node as YAMLAnchorReference;
return extractAllPaths(refNode.value, [...curPath]);
}
return [{ path: curPath, node: node }];
}
function isSeq(node: YAMLNode) {
return node.kind === Kind.SEQ;
}
private testForParentType(parentNodeType, itemsList, currentNode, parentNode){
if(itemsList.indexOf(currentNode) !== -1){
if(parentNodeType === 'array'){
return parentNode.kind !== Kind.SEQ;
}else if(parentNodeType === undefined ){
return parentNode.kind !== Kind.MAP;
}else if(parentNodeType === "object"){
return parentNode.kind !== Kind.MAP;
}
}
return false;
}