forked from enviPath/enviPy
Current Dev State
This commit is contained in:
68
static/js/ketcher2/node_modules/xpath/docs/XPathEvaluator.md
generated
vendored
Normal file
68
static/js/ketcher2/node_modules/xpath/docs/XPathEvaluator.md
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
# `XPathEvaluator`
|
||||
|
||||
The `xpath.parse()` method returns an `XPathEvaluator`, which contains the following methods.
|
||||
|
||||
Each of these methods takes an optional `options` object, which can contain any of the following properties:
|
||||
|
||||
`namespaces` - a namespace resolver. See the [documentation page](namespace resolvers.md) for details.
|
||||
|
||||
`variables` - a variable resolver. See the [documentation page](variable resolvers.md) for details.
|
||||
|
||||
`functions` - a function resolver. See the [documentation page](function resolvers.md) for details.
|
||||
|
||||
`node` - the context node for evaluating the expression
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
var evaluator = xpath.parse('/characters/character[@greeting = $greeting]');
|
||||
var character = evaluator.select1({
|
||||
node: myCharacterDoc,
|
||||
variables: {
|
||||
greeting: 'Hello, I'm Harry, Harry Potter.`
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## `XPathEvaluator` methods
|
||||
|
||||
`evaluate([options])`
|
||||
|
||||
Evaluates the XPath expression and returns the result. The resulting type is determined based on the type of the expression, using the same criteria as [`xpath.select`](xpath methods.md).
|
||||
|
||||
`evaluateNumber([options])`
|
||||
|
||||
Evaluates the XPath expression and returns the result as a number.
|
||||
|
||||
`evaluateString([options])`
|
||||
|
||||
Evaluates the XPath expression and returns the result as a string.
|
||||
|
||||
`evaluateBoolean([options])`
|
||||
|
||||
Evaluates the XPath expression and returns the result as a boolean value.
|
||||
|
||||
`evaluateNodeSet([options])`
|
||||
|
||||
Evaluates the XPath expression and returns the result as an XNodeSet. See the [documentation page](#) for details on this interface.
|
||||
|
||||
This is only valid for expressions that evaluate to a node set.
|
||||
|
||||
`select([options])`
|
||||
|
||||
Evaluates the XPath expression and returns an array of the resulting nodes, in document order.
|
||||
|
||||
This is only valid for expressions that evaluate to a node set.
|
||||
|
||||
`select([options])`
|
||||
|
||||
Evaluates the XPath expression and returns an array of the resulting nodes, in document order.
|
||||
|
||||
This is only valid for expressions that evaluate to a node set.
|
||||
|
||||
`select1([options])`
|
||||
|
||||
Evaluates the XPath expression and the first node in the resulting node set, in document order. Returns `undefined`
|
||||
|
||||
This is only valid for expressions that evaluate to a node set.
|
||||
|
||||
47
static/js/ketcher2/node_modules/xpath/docs/XPathResult.md
generated
vendored
Normal file
47
static/js/ketcher2/node_modules/xpath/docs/XPathResult.md
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
# XPathResult interface
|
||||
|
||||
Represents the result of an XPath expression. This interface is used for the parameters passed into custom functions
|
||||
used in [function resolvers](function resolvers.md) and can represent a number, a string, a boolean value, or a node set.
|
||||
|
||||
## Methods
|
||||
|
||||
```js
|
||||
booleanValue() -> boolean
|
||||
```
|
||||
|
||||
Returns the boolean value of the result in accordance with the XPath 1.0 spec.
|
||||
|
||||
```js
|
||||
numberValue() -> number
|
||||
```
|
||||
|
||||
Returns the numeric value of the result in accordance with the XPath 1.0 spec.
|
||||
|
||||
```js
|
||||
stringValue() -> string
|
||||
```
|
||||
|
||||
Returns the string value of the result in accordance with the XPath 1.0 spec.
|
||||
|
||||
## Methods and properties that are only present on `XPathResult`s representing node sets
|
||||
|
||||
```js
|
||||
toArray() -> Array of nodes
|
||||
```
|
||||
|
||||
Returns an array of the nodes in the node set, in document order.
|
||||
|
||||
```js
|
||||
first() -> Node
|
||||
```
|
||||
|
||||
Returns the first node in the node set, in document order.
|
||||
|
||||
```js
|
||||
size -> number
|
||||
```
|
||||
|
||||
Returns the number of nodes in this node set
|
||||
|
||||
|
||||
|
||||
88
static/js/ketcher2/node_modules/xpath/docs/function resolvers.md
generated
vendored
Normal file
88
static/js/ketcher2/node_modules/xpath/docs/function resolvers.md
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
# Function Resolvers
|
||||
|
||||
The methods on the [XPathEvaluator](XPathEvaluator.md) type can optionally take a function resolver to resolve
|
||||
function references in the XPath expression being evaluated.
|
||||
|
||||
There are three ways to specify a function resolver and you can use any one of them depending on which is
|
||||
most suited to your particular situation.
|
||||
|
||||
Note that if your functions are in a namespace (e.g. `fn:myFunction()`), you must use the second or third
|
||||
type as the plain object implementation does not support namespaces.
|
||||
|
||||
## Function implementations
|
||||
|
||||
Custom XPath functions are implemented as JavaScript functions taking one or more arguments.
|
||||
|
||||
The first argument passed in is a context object containing a number of properties relating to the execution context,
|
||||
the most important being `contextNode`, the context in which the function is being evaluated.
|
||||
|
||||
The remaining arguments are the arguments passed into the XPath function, as instances of the `XPathResult` interface.
|
||||
Please see [the documentation on that interface](XPathResult.md) for details.
|
||||
|
||||
As the return value, you can return a string, number, boolean, single node, or array of nodes.
|
||||
|
||||
## Function Resolver Type 1: Plain object
|
||||
|
||||
A plain object with function names as the keys and function implementations as the values.
|
||||
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
var evaluator = xpath.parse('squareRoot(10)');
|
||||
var aboutPi = evaluator.evaluateNumber({
|
||||
functions: {
|
||||
'squareRoot': function (c, value) {
|
||||
return Math.sqrt(value.numberValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Function Resolver Type 2: Function
|
||||
|
||||
A function that takes a function name as its first parameter and an optional namespace URI as its second parameter
|
||||
and returns a function based on the name and namespace.
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
var evaluator = xpath.parse('math:squareRoot(10)');
|
||||
var aboutPi = evaluator.evaluateNumber({
|
||||
functions: function (name, namespace) {
|
||||
if (name === 'squareRoot' && namespace === 'http://sample.org/math/') {
|
||||
return function (c, value) {
|
||||
return Math.sqrt(value.numberValue());
|
||||
};
|
||||
}
|
||||
},
|
||||
namespaces: {
|
||||
math: 'http://sample.org/math/'
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Function Resolver Type 3: Object with `getFunction` method
|
||||
|
||||
An object with a method named `getFunction` that works in the same way as the function-based function resolver
|
||||
described above.
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
var evaluator = xpath.parse('math:squareRoot(10)');
|
||||
var aboutPi = evaluator.evaluateNumber({
|
||||
functions: {
|
||||
getFunction: function (name, namespace) {
|
||||
if (name === 'squareRoot' && namespace === 'http://sample.org/math/') {
|
||||
return function (c, value) {
|
||||
return Math.sqrt(value.numberValue());
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
namespaces: {
|
||||
math: 'http://sample.org/math/'
|
||||
}
|
||||
});
|
||||
```
|
||||
69
static/js/ketcher2/node_modules/xpath/docs/namespace resolvers.md
generated
vendored
Normal file
69
static/js/ketcher2/node_modules/xpath/docs/namespace resolvers.md
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
# Namespace Resolvers
|
||||
|
||||
The methods on the [XPathEvaluator](XPathEvaluator.md) type can optionally take a namespace resolver to resolve
|
||||
namespace references in the XPath expression being evaluated.
|
||||
|
||||
There are three ways to specify a namespace resolver and you can use any one of them depending on which is
|
||||
most suited to your particular situation.
|
||||
|
||||
## Namespace Resolver Type 1: Plain object
|
||||
|
||||
A plain object with namespace prefixes as the keys and namespace URIs as the values:
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
var evaluator = xpath.parse('/bk:book/hp:characters');
|
||||
var characters = evaluator.select({
|
||||
node: myBookNode,
|
||||
namespaces: {
|
||||
'bk': 'http://sample.org/books/',
|
||||
'hp': 'http://sample.org/harrypotter/'
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Namespace Resolver Type 2: Function
|
||||
|
||||
A function that takes a namespace prefix as a parameter and returns the corresponding namespace URI.
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
var evaluator = xpath.parse('/bk:book/hp:characters');
|
||||
var characters = evaluator.select({
|
||||
node: myBookNode,
|
||||
namespaces: function (prefix) {
|
||||
if (prefix === 'bk') {
|
||||
return 'http://sample.org/books/';
|
||||
}
|
||||
if (prefix === 'hp') {
|
||||
return 'http://sample.org/books/';
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Namespace Resolver Type 3: Object with `getNamespace` method
|
||||
|
||||
An object with a method named `getNamespace` that works in the same way as the function-based namespace resolver
|
||||
described above.
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
var evaluator = xpath.parse('/bk:book/hp:characters');
|
||||
var characters = evaluator.select({
|
||||
node: myBookNode,
|
||||
namespaces: {
|
||||
getNamespace: function (prefix) {
|
||||
if (prefix === 'bk') {
|
||||
return 'http://sample.org/books/';
|
||||
}
|
||||
if (prefix === 'hp') {
|
||||
return 'http://sample.org/books/';
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
21
static/js/ketcher2/node_modules/xpath/docs/parsed expressions.md
generated
vendored
Normal file
21
static/js/ketcher2/node_modules/xpath/docs/parsed expressions.md
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Using Parsed Expressions
|
||||
|
||||
The `xpath.parse()` method allows pre-parsing an XPath expression and creating an XPath executor to evaluate the XPath as many times as needed.
|
||||
|
||||
This can provide a performance benefit if you plan to evaluate the same XPath multiple times because the expression only needs to be parsed once.
|
||||
|
||||
This also provides access to additional features such as the use of variables and custom XPath functinos, which are not available using the evaluation methods on the `xpath` object.
|
||||
|
||||
#### xpath.parse(expression)
|
||||
|
||||
Parses the specified XPath expression and returns an `XPathEvaluator`. See the [documentation page](XPathEvaluator.md) for API details.
|
||||
|
||||
`expression` should be a string.
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
var evaluator = xpath.parse('/book/characters');
|
||||
```
|
||||
|
||||
|
||||
89
static/js/ketcher2/node_modules/xpath/docs/variable resolvers.md
generated
vendored
Normal file
89
static/js/ketcher2/node_modules/xpath/docs/variable resolvers.md
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
# Variable Resolvers
|
||||
|
||||
The methods on the [XPathEvaluator](#) type can optionally take a variable resolver to resolve
|
||||
variable references in the XPath expression being evaluated.
|
||||
|
||||
There are three ways to specify a variable resolver and you can use any one of them depending on which is
|
||||
most suited to your particular situation.
|
||||
|
||||
Note that if your variables are in a namespace (e.g. `$myVars:var`), you must use the second or third
|
||||
type as the plain object implementation does not support namespaces.
|
||||
|
||||
## Variable values
|
||||
|
||||
You can use any of five types of values to specify the values of variables:
|
||||
|
||||
- string
|
||||
- number
|
||||
- boolean
|
||||
- single node (will be treated as a node set)
|
||||
- array of nodes or array-like collection of nodes (will be treated as a node set)
|
||||
|
||||
## Variable Resolver Type 1: Plain object
|
||||
|
||||
A plain object with variable names as the keys and variable values as the values.
|
||||
|
||||
Example usage:
|
||||
|
||||
````
|
||||
var evaluator = xpath.parse('concat($character1, ", ", $character2, ", and ", $character3)');
|
||||
var mainCharacters = evaluator.evaluateString({
|
||||
variables: {
|
||||
character1: 'Harry',
|
||||
character2: 'Ron',
|
||||
character3: 'Hermione'
|
||||
}
|
||||
});
|
||||
````
|
||||
|
||||
## Variable Resolver Type 2: Function
|
||||
|
||||
A function that takes a variable name as its first parameter and an optional namespace URI as its second parameter
|
||||
and returns a value based on the name and namespace.
|
||||
|
||||
Example usage:
|
||||
|
||||
````
|
||||
var evaluator = xpath.parse('concat($hp:character1, ", ", $hp:character2, ", and ", $hp:character3)');
|
||||
var mainCharacters = evaluator.evaluateString({
|
||||
variables: function (name, namespace) {
|
||||
if (namespace === 'http://sample.org/harrypotter/') {
|
||||
switch (name) {
|
||||
case 'character1': return 'Harry';
|
||||
case 'character2': return 'Ron';
|
||||
case 'character3': return 'Hermione';
|
||||
}
|
||||
}
|
||||
},
|
||||
namespaces: {
|
||||
hp: 'http://sample.org/harrypotter/'
|
||||
}
|
||||
});
|
||||
````
|
||||
|
||||
## Function Resolver Type 3: Object with `getFunction` method
|
||||
|
||||
An object with a method named `getVariable` that works in the same way as the function-based variable resolver
|
||||
described above.
|
||||
|
||||
Example usage:
|
||||
|
||||
````
|
||||
var evaluator = xpath.parse('concat($hp:character1, ", ", $hp:character2, ", and ", $hp:character3)');
|
||||
var mainCharacters = evaluator.evaluateString({
|
||||
variables: {
|
||||
getVariable: function (name, namespace) {
|
||||
if (namespace === 'http://sample.org/harrypotter/') {
|
||||
switch (name) {
|
||||
case 'character1': return 'Harry';
|
||||
case 'character2': return 'Ron';
|
||||
case 'character3': return 'Hermione';
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
namespaces: {
|
||||
hp: 'http://sample.org/harrypotter/'
|
||||
}
|
||||
});
|
||||
````
|
||||
39
static/js/ketcher2/node_modules/xpath/docs/xpath methods.md
generated
vendored
Normal file
39
static/js/ketcher2/node_modules/xpath/docs/xpath methods.md
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
#xpath methods
|
||||
|
||||
This page details the methods exposed on the `xpath` object.
|
||||
|
||||
### `xpath.select(expression[, node[, single]])`
|
||||
|
||||
Evaluates an XPath expression and returns the result. The return value is determined based on the result type of the expression (which can always be predicted ahead of time):
|
||||
|
||||
- A boolean value if the expression evaluates to a boolean value.
|
||||
- A number if the expression evaluates to a numeric value.
|
||||
- A string if the expression evaluates to a string.
|
||||
- If the expression evaluates to a nodeset:
|
||||
- An array of nodes if `single` is unspecified or falsy
|
||||
- A single node (the first node in document order) or `undefined` if `single` is truthy
|
||||
|
||||
`node` is optional and if specified, is used as the context node for evaluating the expression. (It is necessary if the expression includes any node tests.)
|
||||
|
||||
`single` is optional and is ignored if the expression evaluates to anything other than a nodeset.
|
||||
|
||||
### `xpath.useNamespaces(mappings)`
|
||||
|
||||
Produces a function with the signature `func(expression, node)` that evaluates the provided xpath expression with the XML namespace definitions provided in `mapppings`.
|
||||
|
||||
`mappings` should be an object with namespace prefixes as its property names and namespace URIs as its property values.
|
||||
|
||||
Example usage:
|
||||
|
||||
```js
|
||||
var expr = xpath.useNamespaces({ hp: 'http://www.example.com/harryPotter', bk: 'http://www.example.com/books' });
|
||||
var result = expr('/bk:books/bk:book[@name = "Harry Potter and the Half-Blood Prince"]/hp:characters', myBooks);
|
||||
```
|
||||
|
||||
### `xpath.select1(expression[, node])`
|
||||
|
||||
Alias for [`xpath.select(expression, node, true)`](#xpathselectexpression-node-single). Selects a single node or value.
|
||||
|
||||
### `xpath.parse(expression)`
|
||||
|
||||
Creates a parsed expression. See the [documentation page](parsed expressions.md) for details.
|
||||
Reference in New Issue
Block a user