This commit is contained in:
Siwat Sirichai 2024-05-03 16:11:08 +07:00
parent 029fe23657
commit 1876580d86
911 changed files with 160008 additions and 2 deletions

22
node_modules/xpath/LICENSE generated vendored Normal file
View file

@ -0,0 +1,22 @@
MIT License
Copyright (c) 2018 Cameron McCormack
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

133
node_modules/xpath/README.md generated vendored Normal file
View file

@ -0,0 +1,133 @@
## xpath
DOM 3 XPath 1.0 implemention and helper for JavaScript, with node.js support.
Originally written by Cameron McCormack ([blog](http://mcc.id.au/xpathjs)).
Additional contributions from
Yaron Naveh ([blog](http://webservices20.blogspot.com/))
goto100
Thomas Weinert
Jimmy Rishe
and [others](https://github.com/goto100/xpath/graphs/contributors)
## Install
Install with [npm](http://github.com/isaacs/npm):
npm install xpath
xpath is xml engine agnostic but I recommend to use [xmldom](https://github.com/jindw/xmldom):
npm install xmldom
## API Documentation
Can be found [here](https://github.com/goto100/xpath/blob/master/docs/xpath%20methods.md). See below for example usage.
## Your first xpath:
`````javascript
var xpath = require('xpath')
, dom = require('xmldom').DOMParser
var xml = "<book><title>Harry Potter</title></book>"
var doc = new dom().parseFromString(xml)
var nodes = xpath.select("//title", doc)
console.log(nodes[0].localName + ": " + nodes[0].firstChild.data)
console.log("Node: " + nodes[0].toString())
`````
title: Harry Potter
Node: <title>Harry Potter</title>
### Alternatively
Using the same interface you have on modern browsers ([MDN])
`````javascript
var node = null;
var xml = "<book author='J. K. Rowling'><title>Harry Potter</title></book>"
var doc = new dom().parseFromString(xml)
var result = xpath.evaluate(
"/book/title", // xpathExpression
doc, // contextNode
null, // namespaceResolver
xpath.XPathResult.ANY_TYPE, // resultType
null // result
)
node = result.iterateNext();
while (node) {
console.log(node.localName + ": " + node.firstChild.data);
console.log("Node: " + node.toString());
node = result.iterateNext();
}
`````
title: Harry Potter
Node: <title>Harry Potter</title>
## Evaluate string values directly:
`````javascript
var xml = "<book><title>Harry Potter</title></book>";
var doc = new dom().parseFromString(xml);
var title = xpath.select("string(//title)", doc);
console.log(title);
`````
Harry Potter
## Namespaces
`````javascript
var xml = "<book><title xmlns='myns'>Harry Potter</title></book>"
var doc = new dom().parseFromString(xml)
var node = xpath.select("//*[local-name(.)='title' and namespace-uri(.)='myns']", doc)[0]
console.log(node.namespaceURI)
`````
myns
## Namespaces with easy mappings
`````javascript
var xml = "<book xmlns:bookml='http://example.com/book'><bookml:title>Harry Potter</bookml:title></book>"
var select = xpath.useNamespaces({"bookml": "http://example.com/book"});
console.log(select('//bookml:title/text()', doc)[0].nodeValue);
`````
Harry Potter
## Default namespace with mapping
`````javascript
var xml = "<book xmlns='http://example.com/book'><title>Harry Potter</title></book>"
var select = xpath.useNamespaces({"bookml": "http://example.com/book"});
console.log(select('//bookml:title/text()', doc)[0].nodeValue);
`````
Harry Potter
## Attributes
`````javascript
var xml = "<book author='J. K. Rowling'><title>Harry Potter</title></book>"
var doc = new dom().parseFromString(xml)
var author = xpath.select1("/book/@author", doc).value
console.log(author)
`````
J. K. Rowling
[MDN]: https://developer.mozilla.org/en/docs/Web/API/Document/evaluate
## License
MIT

62
node_modules/xpath/docs/XPathEvaluator.md generated vendored Normal file
View file

@ -0,0 +1,62 @@
# `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. See the links for each item for further details:
- `namespaces` - a [namespace resolver](namespace%20resolvers.md)
- `variables` - a [variable resolver](variable%20resolvers.md)
- `functions` - a [function resolver](function%20resolvers.md)
- `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%20methods.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.
`select1([options])`
Evaluates the XPath expression and the first node in the resulting node set, in document order. Returns `undefined` if the resulting node set is empty.
This is only valid for expressions that evaluate to a node set.

47
node_modules/xpath/docs/XPathResult.md generated vendored Normal file
View 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
node_modules/xpath/docs/function resolvers.md generated vendored Normal file
View 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
node_modules/xpath/docs/namespace resolvers.md generated vendored Normal file
View 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
node_modules/xpath/docs/parsed expressions.md generated vendored Normal file
View 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 functions, 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
node_modules/xpath/docs/variable resolvers.md generated vendored Normal file
View 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
node_modules/xpath/docs/xpath methods.md generated vendored Normal file
View file

@ -0,0 +1,39 @@
# xpath methods
This page details the methods exposed on the `xpath` object.
### `xpath.parse(expression)`
Creates a parsed expression. See the [documentation page](parsed%20expressions.md) for details.
### `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 based on the expression's syntax):
- 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 0 or more 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 makes use of the current contex.)
`single` is optional and is ignored if the expression evaluates to anything other than a nodeset.
### `xpath.select1(expression[, node])`
Alias for [`xpath.select(expression, node, true)`](#xpathselectexpression-node-single). Selects a single node or value.
### `xpath.useNamespaces(mappings)`
Produces a function with the same signature as [`xpath.select()`](#xpathselectexpression-node-single) that evaluates the provided xpath expression using 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);
```

37
node_modules/xpath/package.json generated vendored Normal file
View file

@ -0,0 +1,37 @@
{
"name": "xpath",
"version": "0.0.32",
"description": "DOM 3 XPath implemention and helper for node.js.",
"engines": {
"node": ">=0.6.0"
},
"author": {
"name": "Cameron McCormack"
},
"contributors": [
{
"name": "goto100"
},
{
"name": "James Rishe"
}
],
"dependencies": {},
"devDependencies": {
"xmldom": "^0.1.19"
},
"typings": "./xpath.d.ts",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "https://github.com/goto100/xpath.git"
},
"main": "./xpath.js",
"keywords": [
"xpath",
"xml"
],
"license": "MIT"
}

1050
node_modules/xpath/test.js generated vendored Normal file

File diff suppressed because it is too large Load diff

11
node_modules/xpath/xpath.d.ts generated vendored Normal file
View file

@ -0,0 +1,11 @@
/// <reference lib="dom" />
type SelectedValue = Node | Attr | string | number | boolean;
interface XPathSelect {
(expression: string, node?: Node): Array<SelectedValue>;
(expression: string, node: Node, single: true): SelectedValue | undefined;
}
export var select: XPathSelect;
export function select1(expression: string, node?: Node): SelectedValue | undefined;
export function evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | null, type: number, result: XPathResult | null): XPathResult;
export function useNamespaces(namespaceMap: { [name: string]: string }): XPathSelect;

4847
node_modules/xpath/xpath.js generated vendored Normal file

File diff suppressed because it is too large Load diff