yaml-language-server-parser
Advanced tools
Comparing version 0.1.2-1636770.0 to 0.1.2-a9241ce.0
"use strict"; | ||
'use strict'; | ||
const type_1 = require("../type"); | ||
function resolveYamlBoolean(data) { | ||
if (null === data) { | ||
const ast = require("../yamlAST"); | ||
function resolveYamlBoolean(nodeOrString) { | ||
const booleanValue = ast.isYAMLNode(nodeOrString) ? nodeOrString.value : nodeOrString; | ||
if (null === booleanValue) { | ||
return false; | ||
} | ||
var max = data.length; | ||
return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) || | ||
(max === 5 && (data === 'false' || data === 'False' || data === 'FALSE')); | ||
var max = booleanValue.length; | ||
return (max === 4 && (booleanValue === 'true' || booleanValue === 'True' || booleanValue === 'TRUE')) || | ||
(max === 5 && (booleanValue === 'false' || booleanValue === 'False' || booleanValue === 'FALSE')); | ||
} | ||
function constructYamlBoolean(data) { | ||
return data === 'true' || | ||
data === 'True' || | ||
data === 'TRUE'; | ||
function constructYamlBoolean(nodeOrString) { | ||
if (ast.isYAMLNode(nodeOrString)) { | ||
return nodeOrString; | ||
} | ||
return nodeOrString === 'true' || | ||
nodeOrString === 'True' || | ||
nodeOrString === 'TRUE'; | ||
} | ||
@@ -17,0 +22,0 @@ function isBoolean(object) { |
'use strict'; | ||
const common = require("../common"); | ||
const type_1 = require("../type"); | ||
var YAML_FLOAT_PATTERN = new RegExp('^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?' + | ||
'|\\.[0-9_]+(?:[eE][-+][0-9]+)?' + | ||
'|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' + | ||
'|[-+]?\\.(?:inf|Inf|INF)' + | ||
'|\\.(?:nan|NaN|NAN))$'); | ||
function resolveYamlFloat(data) { | ||
if (null === data) { | ||
const ast = require("../yamlAST"); | ||
var YAML_FLOAT_PATTERN = new RegExp('-?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][-+]?[0-9]+)?' + | ||
'|^0$' + | ||
'|^[-+]?\.(inf|Inf|INF)$' + | ||
'|^\.(nan|NaN|NAN)$'); | ||
function resolveYamlFloat(nodeOrString) { | ||
const floatValue = ast.isYAMLNode(nodeOrString) ? nodeOrString.value : nodeOrString; | ||
if (null === floatValue) { | ||
return false; | ||
} | ||
var value, sign, base, digits; | ||
if (!YAML_FLOAT_PATTERN.test(data)) { | ||
if (!YAML_FLOAT_PATTERN.test(floatValue)) { | ||
return false; | ||
@@ -19,5 +19,8 @@ } | ||
} | ||
function constructYamlFloat(data) { | ||
function constructYamlFloat(nodeOrString) { | ||
if (ast.isYAMLNode(nodeOrString)) { | ||
return nodeOrString; | ||
} | ||
var value, sign, base, digits; | ||
value = data.replace(/_/g, '').toLowerCase(); | ||
value = nodeOrString.replace(/_/g, '').toLowerCase(); | ||
sign = '-' === value[0] ? -1 : 1; | ||
@@ -24,0 +27,0 @@ digits = []; |
'use strict'; | ||
const common = require("../common"); | ||
const type_1 = require("../type"); | ||
const ast = require("../yamlAST"); | ||
function isHexCode(c) { | ||
@@ -15,13 +16,14 @@ return ((0x30 <= c) && (c <= 0x39)) || | ||
} | ||
function resolveYamlInteger(data) { | ||
if (null === data) { | ||
function resolveYamlInteger(nodeOrString) { | ||
const integerValue = ast.isYAMLNode(nodeOrString) ? nodeOrString.value : nodeOrString; | ||
if (null === integerValue) { | ||
return false; | ||
} | ||
var max = data.length, index = 0, hasDigits = false, ch; | ||
var max = integerValue.length, index = 0, hasDigits = false, ch; | ||
if (!max) { | ||
return false; | ||
} | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
if (ch === '-' || ch === '+') { | ||
ch = data[++index]; | ||
ch = integerValue[++index]; | ||
} | ||
@@ -32,7 +34,7 @@ if (ch === '0') { | ||
} | ||
ch = data[++index]; | ||
ch = integerValue[++index]; | ||
if (ch === 'b') { | ||
index++; | ||
for (; index < max; index++) { | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
if (ch === '_') { | ||
@@ -51,7 +53,7 @@ continue; | ||
for (; index < max; index++) { | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
if (ch === '_') { | ||
continue; | ||
} | ||
if (!isHexCode(data.charCodeAt(index))) { | ||
if (!isHexCode(integerValue.charCodeAt(index))) { | ||
return false; | ||
@@ -64,7 +66,7 @@ } | ||
for (; index < max; index++) { | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
if (ch === '_') { | ||
continue; | ||
} | ||
if (!isOctCode(data.charCodeAt(index))) { | ||
if (!isOctCode(integerValue.charCodeAt(index))) { | ||
return false; | ||
@@ -77,3 +79,3 @@ } | ||
for (; index < max; index++) { | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
if (ch === '_') { | ||
@@ -85,3 +87,3 @@ continue; | ||
} | ||
if (!isDecCode(data.charCodeAt(index))) { | ||
if (!isDecCode(integerValue.charCodeAt(index))) { | ||
return false; | ||
@@ -97,6 +99,9 @@ } | ||
} | ||
return /^(:[0-5]?[0-9])+$/.test(data.slice(index)); | ||
return /^(:[0-5]?[0-9])+$/.test(integerValue.slice(index)); | ||
} | ||
function constructYamlInteger(data) { | ||
var value = data, sign = 1, ch, base, digits = []; | ||
function constructYamlInteger(nodeOrString) { | ||
if (ast.isYAMLNode(nodeOrString)) { | ||
return nodeOrString; | ||
} | ||
var value = nodeOrString, sign = 1, ch, base, digits = []; | ||
if (value.indexOf('_') !== -1) { | ||
@@ -103,0 +108,0 @@ value = value.replace(/_/g, ''); |
'use strict'; | ||
const type_1 = require("../type"); | ||
function resolveYamlNull(data) { | ||
if (null === data) { | ||
const ast = require("../yamlAST"); | ||
function resolveYamlNull(nodeOrString) { | ||
const nullValue = ast.isYAMLNode(nodeOrString) ? nodeOrString.value : nodeOrString; | ||
if (null === nullValue) { | ||
return true; | ||
} | ||
var max = data.length; | ||
return (max === 1 && data === '~') || | ||
(max === 4 && (data === 'null' || data === 'Null' || data === 'NULL')); | ||
var max = nullValue.length; | ||
return (max === 1 && nullValue === '~') || | ||
(max === 4 && (nullValue === 'null' || nullValue === 'Null' || nullValue === 'NULL')); | ||
} | ||
function constructYamlNull() { | ||
function constructYamlNull(nodeOrString) { | ||
if (ast.isYAMLNode(nodeOrString)) { | ||
return nodeOrString; | ||
} | ||
return null; | ||
@@ -13,0 +18,0 @@ } |
@@ -55,1 +55,2 @@ import YAMLException = require('./exception'); | ||
export declare function isNodesEqual(a: YAMLNode, b: YAMLNode): boolean; | ||
export declare function isYAMLNode(obj: any): obj is YAMLNode; |
@@ -136,2 +136,6 @@ "use strict"; | ||
exports.isNodesEqual = isNodesEqual; | ||
function isYAMLNode(obj) { | ||
return obj.startPosition !== undefined && obj.endPosition !== undefined && obj.kind !== undefined; | ||
} | ||
exports.isYAMLNode = isYAMLNode; | ||
//# sourceMappingURL=yamlAST.js.map |
{ | ||
"name": "yaml-language-server-parser", | ||
"version": "0.1.2-1636770.0", | ||
"version": "0.1.2-a9241ce.0", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
declare function require(n:string):any | ||
declare function require(n: string): any | ||
'use strict'; | ||
import {Type} from '../type'; | ||
import { Type } from '../type'; | ||
import ast = require('../yamlAST'); | ||
function resolveYamlBoolean(data) { | ||
if (null === data) { | ||
function resolveYamlBoolean(nodeOrString: ast.YAMLNode | string) { | ||
const booleanValue = ast.isYAMLNode(nodeOrString) ? nodeOrString.value : nodeOrString; | ||
if (null === booleanValue) { | ||
return false; | ||
} | ||
var max = data.length; | ||
var max = booleanValue.length; | ||
return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) || | ||
(max === 5 && (data === 'false' || data === 'False' || data === 'FALSE')); | ||
return (max === 4 && (booleanValue === 'true' || booleanValue === 'True' || booleanValue === 'TRUE')) || | ||
(max === 5 && (booleanValue === 'false' || booleanValue === 'False' || booleanValue === 'FALSE')); | ||
} | ||
function constructYamlBoolean(data) { | ||
return data === 'true' || | ||
data === 'True' || | ||
data === 'TRUE'; | ||
function constructYamlBoolean(nodeOrString: ast.YAMLNode | string) { | ||
if (ast.isYAMLNode(nodeOrString)) { | ||
// YAML Boolean is already constructed | ||
return nodeOrString; | ||
} | ||
return nodeOrString === 'true' || | ||
nodeOrString === 'True' || | ||
nodeOrString === 'TRUE'; | ||
} | ||
@@ -25,0 +31,0 @@ |
@@ -6,19 +6,18 @@ | ||
import common = require('../common'); | ||
import {Type} from '../type'; | ||
import { Type } from '../type'; | ||
import ast = require('../yamlAST'); | ||
var YAML_FLOAT_PATTERN = new RegExp( | ||
'^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?' + | ||
'|\\.[0-9_]+(?:[eE][-+][0-9]+)?' + | ||
'|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' + | ||
'|[-+]?\\.(?:inf|Inf|INF)' + | ||
'|\\.(?:nan|NaN|NAN))$'); | ||
'-?(0|[1-9][0-9]*)(\.[0-9]*)?([eE][-+]?[0-9]+)?' + | ||
'|^0$' + | ||
'|^[-+]?\.(inf|Inf|INF)$' + | ||
'|^\.(nan|NaN|NAN)$'); | ||
function resolveYamlFloat(data) { | ||
if (null === data) { | ||
function resolveYamlFloat(nodeOrString: ast.YAMLNode | string) { | ||
const floatValue = ast.isYAMLNode(nodeOrString) ? (nodeOrString as ast.YAMLNode).value : nodeOrString; | ||
if (null === floatValue) { | ||
return false; | ||
} | ||
var value, sign, base, digits; | ||
if (!YAML_FLOAT_PATTERN.test(data)) { | ||
if (!YAML_FLOAT_PATTERN.test(floatValue)) { | ||
return false; | ||
@@ -29,7 +28,10 @@ } | ||
function constructYamlFloat(data) { | ||
function constructYamlFloat(nodeOrString: ast.YAMLNode | string) { | ||
if (ast.isYAMLNode(nodeOrString)) { | ||
return nodeOrString; | ||
} | ||
var value, sign, base, digits; | ||
value = data.replace(/_/g, '').toLowerCase(); | ||
sign = '-' === value[0] ? -1 : 1; | ||
value = nodeOrString.replace(/_/g, '').toLowerCase(); | ||
sign = '-' === value[0] ? -1 : 1; | ||
digits = []; | ||
@@ -69,26 +71,26 @@ | ||
switch (style) { | ||
case 'lowercase': | ||
return '.nan'; | ||
case 'uppercase': | ||
return '.NAN'; | ||
case 'camelcase': | ||
return '.NaN'; | ||
case 'lowercase': | ||
return '.nan'; | ||
case 'uppercase': | ||
return '.NAN'; | ||
case 'camelcase': | ||
return '.NaN'; | ||
} | ||
} else if (Number.POSITIVE_INFINITY === object) { | ||
switch (style) { | ||
case 'lowercase': | ||
return '.inf'; | ||
case 'uppercase': | ||
return '.INF'; | ||
case 'camelcase': | ||
return '.Inf'; | ||
case 'lowercase': | ||
return '.inf'; | ||
case 'uppercase': | ||
return '.INF'; | ||
case 'camelcase': | ||
return '.Inf'; | ||
} | ||
} else if (Number.NEGATIVE_INFINITY === object) { | ||
switch (style) { | ||
case 'lowercase': | ||
return '-.inf'; | ||
case 'uppercase': | ||
return '-.INF'; | ||
case 'camelcase': | ||
return '-.Inf'; | ||
case 'lowercase': | ||
return '-.inf'; | ||
case 'uppercase': | ||
return '-.INF'; | ||
case 'camelcase': | ||
return '-.Inf'; | ||
} | ||
@@ -103,6 +105,6 @@ } else if (common.isNegativeZero(object)) { | ||
return ('[object Number]' === Object.prototype.toString.call(object)) && | ||
(0 !== object % 1 || common.isNegativeZero(object)); | ||
(0 !== object % 1 || common.isNegativeZero(object)); | ||
} | ||
export= new Type('tag:yaml.org,2002:float', { | ||
export = new Type('tag:yaml.org,2002:float', { | ||
kind: 'scalar', | ||
@@ -109,0 +111,0 @@ resolve: resolveYamlFloat, |
@@ -6,8 +6,9 @@ | ||
import common = require('../common'); | ||
import {Type} from '../type'; | ||
import { Type } from '../type'; | ||
import ast = require('../yamlAST'); | ||
function isHexCode(c) { | ||
return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) || | ||
((0x41/* A */ <= c) && (c <= 0x46/* F */)) || | ||
((0x61/* a */ <= c) && (c <= 0x66/* f */)); | ||
((0x41/* A */ <= c) && (c <= 0x46/* F */)) || | ||
((0x61/* a */ <= c) && (c <= 0x66/* f */)); | ||
} | ||
@@ -23,19 +24,20 @@ | ||
function resolveYamlInteger(data) { | ||
if (null === data) { | ||
function resolveYamlInteger(nodeOrString: ast.YAMLNode | string) { | ||
const integerValue = ast.isYAMLNode(nodeOrString) ? (nodeOrString as ast.YAMLNode).value : nodeOrString; | ||
if (null === integerValue) { | ||
return false; | ||
} | ||
var max = data.length, | ||
index = 0, | ||
hasDigits = false, | ||
ch; | ||
var max = integerValue.length, | ||
index = 0, | ||
hasDigits = false, | ||
ch; | ||
if (!max) { return false; } | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
// sign | ||
if (ch === '-' || ch === '+') { | ||
ch = data[++index]; | ||
ch = integerValue[++index]; | ||
} | ||
@@ -46,3 +48,3 @@ | ||
if (index + 1 === max) { return true; } | ||
ch = data[++index]; | ||
ch = integerValue[++index]; | ||
@@ -56,3 +58,3 @@ // base 2, base 8, base 16 | ||
for (; index < max; index++) { | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
if (ch === '_') { continue; } | ||
@@ -73,5 +75,5 @@ if (ch !== '0' && ch !== '1') { | ||
for (; index < max; index++) { | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
if (ch === '_') { continue; } | ||
if (!isHexCode(data.charCodeAt(index))) { | ||
if (!isHexCode(integerValue.charCodeAt(index))) { | ||
return false; | ||
@@ -86,5 +88,5 @@ } | ||
for (; index < max; index++) { | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
if (ch === '_') { continue; } | ||
if (!isOctCode(data.charCodeAt(index))) { | ||
if (!isOctCode(integerValue.charCodeAt(index))) { | ||
return false; | ||
@@ -100,6 +102,6 @@ } | ||
for (; index < max; index++) { | ||
ch = data[index]; | ||
ch = integerValue[index]; | ||
if (ch === '_') { continue; } | ||
if (ch === ':') { break; } | ||
if (!isDecCode(data.charCodeAt(index))) { | ||
if (!isDecCode(integerValue.charCodeAt(index))) { | ||
return false; | ||
@@ -116,7 +118,10 @@ } | ||
// base60 almost not used, no needs to optimize | ||
return /^(:[0-5]?[0-9])+$/.test(data.slice(index)); | ||
return /^(:[0-5]?[0-9])+$/.test(integerValue.slice(index)); | ||
} | ||
function constructYamlInteger(data) { | ||
var value = data, sign = 1, ch, base, digits = []; | ||
function constructYamlInteger(nodeOrString: ast.YAMLNode | string) { | ||
if (ast.isYAMLNode(nodeOrString)) { | ||
return nodeOrString; | ||
} | ||
var value = nodeOrString as any, sign = 1, ch, base, digits = []; | ||
@@ -172,3 +177,3 @@ if (value.indexOf('_') !== -1) { | ||
return ('[object Number]' === Object.prototype.toString.call(object)) && | ||
(0 === object % 1 && !common.isNegativeZero(object)); | ||
(0 === object % 1 && !common.isNegativeZero(object)); | ||
} | ||
@@ -182,5 +187,5 @@ | ||
represent: { | ||
binary: function (object) { return '0b' + object.toString(2); }, | ||
octal: function (object) { return '0' + object.toString(8); }, | ||
decimal: function (object) { return object.toString(10); }, | ||
binary: function (object) { return '0b' + object.toString(2); }, | ||
octal: function (object) { return '0' + object.toString(8); }, | ||
decimal: function (object) { return object.toString(10); }, | ||
hexadecimal: function (object) { return '0x' + object.toString(16).toUpperCase(); } | ||
@@ -190,7 +195,7 @@ }, | ||
styleAliases: { | ||
binary: [ 2, 'bin' ], | ||
octal: [ 8, 'oct' ], | ||
decimal: [ 10, 'dec' ], | ||
hexadecimal: [ 16, 'hex' ] | ||
binary: [2, 'bin'], | ||
octal: [8, 'oct'], | ||
decimal: [10, 'dec'], | ||
hexadecimal: [16, 'hex'] | ||
} | ||
}); |
@@ -5,16 +5,21 @@ | ||
import {Type} from '../type'; | ||
import { Type } from '../type'; | ||
import ast = require('../yamlAST'); | ||
function resolveYamlNull(data) { | ||
if (null === data) { | ||
function resolveYamlNull(nodeOrString: ast.YAMLNode | string) { | ||
const nullValue = ast.isYAMLNode(nodeOrString) ? (nodeOrString as ast.YAMLNode).value : nodeOrString; | ||
if (null === nullValue) { | ||
return true; | ||
} | ||
var max = data.length; | ||
var max = nullValue.length; | ||
return (max === 1 && data === '~') || | ||
(max === 4 && (data === 'null' || data === 'Null' || data === 'NULL')); | ||
return (max === 1 && nullValue === '~') || | ||
(max === 4 && (nullValue === 'null' || nullValue === 'Null' || nullValue === 'NULL')); | ||
} | ||
function constructYamlNull() { | ||
function constructYamlNull(nodeOrString?: ast.YAMLNode | string) { | ||
if (ast.isYAMLNode(nodeOrString)) { | ||
return nodeOrString; | ||
} | ||
return null; | ||
@@ -33,3 +38,3 @@ } | ||
represent: { | ||
canonical: function () { return '~'; }, | ||
canonical: function () { return '~'; }, | ||
lowercase: function () { return 'null'; }, | ||
@@ -36,0 +41,0 @@ uppercase: function () { return 'NULL'; }, |
@@ -5,4 +5,4 @@ | ||
*/ | ||
import YAMLException = require('./exception'); | ||
export enum Kind{ | ||
import YAMLException = require('./exception'); | ||
export enum Kind { | ||
SCALAR, | ||
@@ -17,18 +17,18 @@ MAPPING, | ||
export interface YAMLDocument { | ||
startPosition:number | ||
endPosition:number | ||
errors:YAMLException[] | ||
startPosition: number | ||
endPosition: number | ||
errors: YAMLException[] | ||
} | ||
export interface YAMLNode extends YAMLDocument{ | ||
startPosition:number | ||
endPosition:number | ||
kind:Kind | ||
anchorId?:string | ||
valueObject?:any | ||
parent:YAMLNode | ||
errors:YAMLException[] | ||
export interface YAMLNode extends YAMLDocument { | ||
startPosition: number | ||
endPosition: number | ||
kind: Kind | ||
anchorId?: string | ||
valueObject?: any | ||
parent: YAMLNode | ||
errors: YAMLException[] | ||
/** | ||
* @deprecated Inspect kind and cast to the appropriate subtype instead. | ||
*/ | ||
value?:any | ||
value?: any | ||
@@ -38,3 +38,3 @@ /** | ||
*/ | ||
key?:any | ||
key?: any | ||
@@ -44,64 +44,64 @@ /** | ||
*/ | ||
mappings?:any | ||
mappings?: any | ||
} | ||
export interface YAMLAnchorReference extends YAMLNode{ | ||
referencesAnchor:string | ||
value:YAMLNode | ||
export interface YAMLAnchorReference extends YAMLNode { | ||
referencesAnchor: string | ||
value: YAMLNode | ||
} | ||
export interface YAMLScalar extends YAMLNode{ | ||
value:string | ||
doubleQuoted?:boolean | ||
singleQuoted?:boolean | ||
plainScalar?:boolean | ||
rawValue:string | ||
export interface YAMLScalar extends YAMLNode { | ||
value: string | ||
doubleQuoted?: boolean | ||
singleQuoted?: boolean | ||
plainScalar?: boolean | ||
rawValue: string | ||
} | ||
export interface YAMLMapping extends YAMLNode{ | ||
key:YAMLNode | ||
value:YAMLNode | ||
export interface YAMLMapping extends YAMLNode { | ||
key: YAMLNode | ||
value: YAMLNode | ||
} | ||
export interface YAMLSequence extends YAMLNode{ | ||
items:YAMLNode[] | ||
export interface YAMLSequence extends YAMLNode { | ||
items: YAMLNode[] | ||
} | ||
export interface YamlMap extends YAMLNode{ | ||
mappings:YAMLMapping[] | ||
export interface YamlMap extends YAMLNode { | ||
mappings: YAMLMapping[] | ||
} | ||
export function newMapping(key:YAMLNode,value:YAMLNode):YAMLMapping{ | ||
export function newMapping(key: YAMLNode, value: YAMLNode): YAMLMapping { | ||
var end = (value ? value.endPosition : key.endPosition + 1); //FIXME.workaround, end should be defied by position of ':' | ||
//console.log('key: ' + key.value + ' ' + key.startPosition + '..' + key.endPosition + ' ' + value + ' end: ' + end); | ||
var node = { | ||
key: key, | ||
value: value, | ||
startPosition: key.startPosition, | ||
endPosition: end, | ||
kind: Kind.MAPPING, | ||
parent: null, | ||
errors: [] | ||
}; | ||
return node | ||
key: key, | ||
value: value, | ||
startPosition: key.startPosition, | ||
endPosition: end, | ||
kind: Kind.MAPPING, | ||
parent: null, | ||
errors: [] | ||
}; | ||
return node | ||
} | ||
export function newAnchorRef(key:string,start:number,end:number,value:YAMLNode):YAMLAnchorReference{ | ||
export function newAnchorRef(key: string, start: number, end: number, value: YAMLNode): YAMLAnchorReference { | ||
return { | ||
errors:[], | ||
referencesAnchor:key, | ||
value:value, | ||
startPosition:start, | ||
endPosition:end, | ||
kind:Kind.ANCHOR_REF, | ||
parent:null | ||
errors: [], | ||
referencesAnchor: key, | ||
value: value, | ||
startPosition: start, | ||
endPosition: end, | ||
kind: Kind.ANCHOR_REF, | ||
parent: null | ||
} | ||
} | ||
export function newScalar(v:string|boolean|number=""):YAMLScalar{ | ||
const result:YAMLScalar = { | ||
errors:[], | ||
startPosition:-1, | ||
endPosition:-1, | ||
value:""+v, | ||
kind:Kind.SCALAR, | ||
parent:null, | ||
doubleQuoted:false, | ||
rawValue:""+v, | ||
export function newScalar(v: string | boolean | number = ""): YAMLScalar { | ||
const result: YAMLScalar = { | ||
errors: [], | ||
startPosition: -1, | ||
endPosition: -1, | ||
value: "" + v, | ||
kind: Kind.SCALAR, | ||
parent: null, | ||
doubleQuoted: false, | ||
rawValue: "" + v, | ||
}; | ||
if(typeof v !== "string"){ | ||
if (typeof v !== "string") { | ||
result.valueObject = v; | ||
@@ -111,23 +111,23 @@ } | ||
} | ||
export function newItems():YAMLSequence{ | ||
export function newItems(): YAMLSequence { | ||
return { | ||
errors:[], | ||
startPosition:-1, | ||
endPosition:-1, | ||
items:[], | ||
kind:Kind.SEQ, | ||
parent:null | ||
errors: [], | ||
startPosition: -1, | ||
endPosition: -1, | ||
items: [], | ||
kind: Kind.SEQ, | ||
parent: null | ||
} | ||
} | ||
export function newSeq():YAMLSequence{ | ||
export function newSeq(): YAMLSequence { | ||
return newItems(); | ||
} | ||
export function newMap(mappings?: YAMLMapping[]):YamlMap{ | ||
export function newMap(mappings?: YAMLMapping[]): YamlMap { | ||
return { | ||
errors:[], | ||
startPosition:-1, | ||
endPosition:-1, | ||
errors: [], | ||
startPosition: -1, | ||
endPosition: -1, | ||
mappings: mappings ? mappings : [], | ||
kind:Kind.MAP, | ||
parent:null | ||
kind: Kind.MAP, | ||
parent: null | ||
} | ||
@@ -146,18 +146,18 @@ } | ||
if(!a || !b){ | ||
if (!a || !b) { | ||
return false; | ||
} | ||
if(a.kind !== b.kind){ | ||
if (a.kind !== b.kind) { | ||
return false; | ||
} | ||
if(a.kind === Kind.SCALAR) { | ||
if (a.kind === Kind.SCALAR) { | ||
return (<YAMLScalar>a).value === (<YAMLScalar>b).value; | ||
} | ||
if(a.kind === Kind.SEQ) { | ||
const aSeq = <YAMLSequence> a; | ||
const bSeq = <YAMLSequence> b; | ||
if(aSeq.items.length !== bSeq.items.length){ | ||
if (a.kind === Kind.SEQ) { | ||
const aSeq = <YAMLSequence>a; | ||
const bSeq = <YAMLSequence>b; | ||
if (aSeq.items.length !== bSeq.items.length) { | ||
return false; | ||
@@ -169,5 +169,5 @@ } | ||
const elementB = bSeq.items[i]; | ||
if(!isNodesEqual(elementA, elementB)){ | ||
if (!isNodesEqual(elementA, elementB)) { | ||
return false; | ||
} | ||
} | ||
} | ||
@@ -177,16 +177,16 @@ return true; | ||
if(a.kind === Kind.MAP) { | ||
if (a.kind === Kind.MAP) { | ||
const aMap = <YamlMap>a; | ||
const bMap = <YamlMap>b; | ||
if(aMap.mappings.length !== bMap.mappings.length){ | ||
if (aMap.mappings.length !== bMap.mappings.length) { | ||
return false; | ||
} | ||
for(const mapA of aMap.mappings) { | ||
for (const mapA of aMap.mappings) { | ||
const keyA = mapA.key; | ||
const valA = mapA.value; | ||
const mapB = bMap.mappings.find(mapB => isNodesEqual(keyA, mapB.key)); | ||
if(mapB) { | ||
if(!isNodesEqual(valA, mapB.value)){ | ||
if (mapB) { | ||
if (!isNodesEqual(valA, mapB.value)) { | ||
return false; | ||
@@ -212,1 +212,5 @@ } | ||
} | ||
export function isYAMLNode(obj: any): obj is YAMLNode { | ||
return obj.startPosition !== undefined && obj.endPosition !== undefined && obj.kind !== undefined; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
435146
161
8126
1