lassy-xpath
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "lassy-xpath", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "XPath format and editor for searching LASSY XML files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,2 +6,9 @@ import { XPathModels } from 'ts-xpath'; | ||
parse(xpath: string): ParsedXPath; | ||
/** | ||
* Formats an xpath (add indentation and newlines). | ||
* @param xpath The xpath to format. | ||
* @param indentSize The indentation size of each step. | ||
* @param indentCount The zero-based count of the current level of indentation. | ||
*/ | ||
format(xpath: string, indentSize?: number, indentCount?: number): any; | ||
private createWarning(message, location, offset?); | ||
@@ -8,0 +15,0 @@ private getWarnings(expressions); |
@@ -42,2 +42,40 @@ "use strict"; | ||
}; | ||
/** | ||
* Formats an xpath (add indentation and newlines). | ||
* @param xpath The xpath to format. | ||
* @param indentSize The indentation size of each step. | ||
* @param indentCount The zero-based count of the current level of indentation. | ||
*/ | ||
/** | ||
* Formats an xpath (add indentation and newlines). | ||
* @param xpath The xpath to format. | ||
* @param indentSize The indentation size of each step. | ||
* @param indentCount The zero-based count of the current level of indentation. | ||
*/ | ||
Parser.prototype.format = /** | ||
* Formats an xpath (add indentation and newlines). | ||
* @param xpath The xpath to format. | ||
* @param indentSize The indentation size of each step. | ||
* @param indentCount The zero-based count of the current level of indentation. | ||
*/ | ||
function (xpath, indentSize, indentCount) { | ||
if (indentSize === void 0) { indentSize = 4; } | ||
if (indentCount === void 0) { indentCount = 0; } | ||
var index = xpath.search(/(?<![\/:])node/); | ||
if (index == -1) { | ||
return xpath; | ||
} | ||
var preceding = xpath.substring(0, index); | ||
for (var _i = 0, preceding_1 = preceding; _i < preceding_1.length; _i++) { | ||
var c = preceding_1[_i]; | ||
if (c == '[') { | ||
indentCount++; | ||
} | ||
else if (c == ']') { | ||
indentCount--; | ||
} | ||
} | ||
var tail = xpath.substring(index + 4); | ||
return preceding.replace(/ +$/, '') + "\n" + ' '.repeat(indentCount * indentSize) + "node" + this.format(tail, indentSize, indentCount); | ||
}; | ||
Parser.prototype.createWarning = function (message, location, offset) { | ||
@@ -44,0 +82,0 @@ if (offset === void 0) { offset = -1; } |
@@ -1,1 +0,1 @@ | ||
[{"__symbolic":"module","version":4,"metadata":{"Parser":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor"}],"parse":[{"__symbolic":"method"}],"createWarning":[{"__symbolic":"method"}],"getWarnings":[{"__symbolic":"method"}],"getOperationWarnings":[{"__symbolic":"method"}],"getPathWarnings":[{"__symbolic":"method"}]}},"ParsedXPath":{"__symbolic":"interface"},"ParseMessage":{"__symbolic":"interface"}}}] | ||
[{"__symbolic":"module","version":4,"metadata":{"Parser":{"__symbolic":"class","members":{"__ctor__":[{"__symbolic":"constructor"}],"parse":[{"__symbolic":"method"}],"format":[{"__symbolic":"method"}],"createWarning":[{"__symbolic":"method"}],"getWarnings":[{"__symbolic":"method"}],"getOperationWarnings":[{"__symbolic":"method"}],"getPathWarnings":[{"__symbolic":"method"}]}},"ParsedXPath":{"__symbolic":"interface"},"ParseMessage":{"__symbolic":"interface"}}}] |
@@ -44,2 +44,5 @@ "use strict"; | ||
}); | ||
it('Formats', function () { | ||
expect(parserService.format('//node[@foo and node[@bar or @id="42"]]')).toEqual("//node[@foo and\n node[@bar or @id=\"42\"]]"); | ||
}); | ||
function expectWarnings(xpath, expectedWarnings) { | ||
@@ -46,0 +49,0 @@ var parsed = parserService.parse(xpath); |
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
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
264644
3072