UNPKG

yaml-language-server-parser

Version:

This is a maintained fork of YAML-AST-PARSER specifically for the YAML Language server.

37 lines 1.38 kB
"use strict"; 'use strict'; const type_1 = require("../type"); const ast = require("../yamlAST"); function resolveYamlBoolean(nodeOrString) { const booleanValue = ast.isYAMLNode(nodeOrString) ? nodeOrString.value : nodeOrString; if (null === booleanValue) { return false; } var max = booleanValue.length; return (max === 4 && (booleanValue === 'true' || booleanValue === 'True' || booleanValue === 'TRUE')) || (max === 5 && (booleanValue === 'false' || booleanValue === 'False' || booleanValue === 'FALSE')); } function constructYamlBoolean(nodeOrString) { if (ast.isYAMLNode(nodeOrString)) { return nodeOrString; } return nodeOrString === 'true' || nodeOrString === 'True' || nodeOrString === 'TRUE'; } function isBoolean(object) { return '[object Boolean]' === Object.prototype.toString.call(object); } module.exports = new type_1.Type('tag:yaml.org,2002:bool', { kind: 'scalar', resolve: resolveYamlBoolean, construct: constructYamlBoolean, predicate: isBoolean, represent: { lowercase: function (object) { return object ? 'true' : 'false'; }, uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; }, camelcase: function (object) { return object ? 'True' : 'False'; } }, defaultStyle: 'lowercase' }); //# sourceMappingURL=bool.js.map