How to use the yaml-ast-parser.Kind.MAP function in yaml-ast-parser

To help you get started, we’ve selected a few yaml-ast-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AEB-labs / cruddl / src / schema / schema-builder.ts View on Github external
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:
github replicatedhq / replicated-lint / src / ast.ts View on Github external
function isMap(node: YAMLNode) {
  return node.kind === Kind.MAP;
}
github redhat-developer / yaml-language-server / src / languageService / services / validationService.ts View on Github external
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;
  }