Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function recursiveObjectExtraction(node: YAMLNode | undefined, object: PlainObject, validationContext: ValidationContext, source: ProjectSource): any {
// ATTENTION: Typings of the yaml ast parser are wrong
if (!node) {
return object;
}
switch (node.kind) {
case Kind.MAP:
const mapNode = node as YamlMap;
mapNode.mappings.forEach(val => {
object[val.key.value] = recursiveObjectExtraction(val.value, {}, validationContext, source);
});
return object;
case Kind.MAPPING:
throw new Error('Should never be reached since a mapping can not exist without a map.');
case Kind.SCALAR:
const scalarNode = node as YAMLScalar;
// check whether string or number scalar
if (scalarNode.doubleQuoted || scalarNode.singleQuoted || isNaN(Number(scalarNode.value))) {
return scalarNode.value;
} else {
return Number(scalarNode.value);
}
case Kind.SEQ:
function isMap(node: YAMLNode) {
return node.kind === Kind.MAP;
}
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;
}