fontoxpath
Advanced tools
Comparing version 3.9.2 to 3.10.0
@@ -121,43 +121,96 @@ | ||
/** | ||
* Evaluates an XPath on the given contextItem. | ||
* | ||
* If the return type is ANY_TYPE, the returned value depends on the result of the XPath: | ||
* * If the XPath evaluates to the empty sequence, an empty array is returned. | ||
* * If the XPath evaluates to a singleton node, that node is returned. | ||
* * If the XPath evaluates to a singleton value, that value is atomized and returned. | ||
* * If the XPath evaluates to a sequence of nodes, those nodes are returned. | ||
* * Else, the sequence is atomized and returned. | ||
* | ||
* @public | ||
* | ||
* @param selector - The selector to execute. Supports XPath 3.1. | ||
* @param contextItem - The node from which to run the XPath. | ||
* @param domFacade - The domFacade (or DomFacade like interface) for retrieving relations. | ||
* @param variables - Extra variables (name to value). Values can be number, string, boolean, nodes or object literals and arrays. | ||
* @param returnType - One of the return types, indicates the expected type of the XPath query. | ||
* @param options - Extra options for evaluating this XPath | ||
* | ||
* @returns The result of executing this XPath | ||
*/ | ||
export declare function evaluateXPath<TNode extends Node, TReturnType extends keyof IReturnTypes<TNode>>(selector: string, contextItem?: any | null, domFacade?: IDomFacade | null, variables?: { | ||
[s: string]: any; | ||
} | null, returnType?: TReturnType, options?: Options | null): IReturnTypes<TNode>[TReturnType]; | ||
export declare type EvaluateXPath = { | ||
/** | ||
* Evaluates an XPath on the given contextItem. | ||
* | ||
* If the return type is ANY_TYPE, the returned value depends on the result of the XPath: | ||
* * If the XPath evaluates to the empty sequence, an empty array is returned. | ||
* * If the XPath evaluates to a singleton node, that node is returned. | ||
* * If the XPath evaluates to a singleton value, that value is atomized and returned. | ||
* * If the XPath evaluates to a sequence of nodes, those nodes are returned. | ||
* * Else, the sequence is atomized and returned. | ||
* | ||
* @public | ||
* | ||
* @param selector - The selector to execute. Supports XPath 3.1. | ||
* @param contextItem - The node from which to run the XPath. | ||
* @param domFacade - The domFacade (or DomFacade like interface) for retrieving relations. | ||
* @param variables - Extra variables (name to value). Values can be number, string, boolean, nodes or object literals and arrays. | ||
* @param returnType - One of the return types, indicates the expected type of the XPath query. | ||
* @param options - Extra options for evaluating this XPath | ||
* | ||
* @returns The result of executing this XPath | ||
*/ | ||
<TNode extends Node, TReturnType extends keyof IReturnTypes<TNode>>(selector: string, contextItem?: any | null, domFacade?: IDomFacade | null, variables?: { | ||
[s: string]: any; | ||
} | null, returnType?: TReturnType, options?: Options | null): IReturnTypes<TNode>[TReturnType]; | ||
/** | ||
* Can be used to signal an XPath program should executed | ||
*/ | ||
XPATH_3_1_LANGUAGE: Language.XPATH_3_1_LANGUAGE; | ||
/** | ||
* Can be used to signal an XQuery program should be executed instead | ||
* of an XPath | ||
*/ | ||
XQUERY_3_1_LANGUAGE: Language.XQUERY_3_1_LANGUAGE; | ||
/** | ||
* Can be used to signal Update facility can be used. | ||
* | ||
* To catch pending updates, use {@link evaluateUpdatingExpression} | ||
*/ | ||
XQUERY_UPDATE_3_1_LANGUAGE: Language.XQUERY_UPDATE_3_1_LANGUAGE; | ||
/** | ||
* Returns the result of the query, can be anything depending on the | ||
* query. Note that the return type is determined dynamically, not | ||
* statically: XPaths returning empty sequences will return empty | ||
* arrays and not null, like one might expect. | ||
*/ | ||
ANY_TYPE: ReturnType.ANY; | ||
/** | ||
* Resolve to a number, like count((1,2,3)) resolves to 3. | ||
*/ | ||
NUMBER_TYPE: ReturnType.NUMBER; | ||
/** | ||
* Resolve to a string, like //someElement[1] resolves to the text | ||
* content of the first someElement | ||
*/ | ||
STRING_TYPE: ReturnType.STRING; | ||
/** | ||
* Resolves to true or false, uses the effective boolean value to | ||
* determine the result. count(1) resolves to true, count(()) | ||
* resolves to false | ||
*/ | ||
BOOLEAN_TYPE: ReturnType.BOOLEAN; | ||
/** | ||
* Resolve to all nodes the XPath resolves to. Returns nodes in the | ||
* order the XPath would. Meaning (//a, //b) resolves to all A nodes, | ||
* followed by all B nodes. //*[self::a or self::b] resolves to A and | ||
* B nodes in document order. | ||
*/ | ||
NODES_TYPE: ReturnType.NODES; | ||
/** | ||
* Resolves to the first node.NODES_TYPE would have resolved to. | ||
*/ | ||
FIRST_NODE_TYPE: ReturnType.FIRST_NODE; | ||
/** | ||
* Resolve to an array of strings | ||
*/ | ||
STRINGS_TYPE: ReturnType.STRINGS; | ||
/** | ||
* Resolve to an object, as a map | ||
*/ | ||
MAP_TYPE: ReturnType.MAP; | ||
ARRAY_TYPE: ReturnType.ARRAY; | ||
ASYNC_ITERATOR_TYPE: ReturnType.ASYNC_ITERATOR; | ||
/** | ||
export declare namespace evaluateXPath { | ||
var ANY_TYPE: ReturnType.ANY; | ||
var NUMBER_TYPE: ReturnType.NUMBER; | ||
var STRING_TYPE: ReturnType.STRING; | ||
var BOOLEAN_TYPE: ReturnType.BOOLEAN; | ||
var NODES_TYPE: ReturnType.NODES; | ||
var FIRST_NODE_TYPE: ReturnType.FIRST_NODE; | ||
var STRINGS_TYPE: ReturnType.STRINGS; | ||
var MAP_TYPE: ReturnType.MAP; | ||
var ARRAY_TYPE: ReturnType.ARRAY; | ||
var ASYNC_ITERATOR_TYPE: ReturnType.ASYNC_ITERATOR; | ||
var NUMBERS_TYPE: ReturnType.NUMBERS; | ||
var XQUERY_UPDATE_3_1_LANGUAGE: Language; | ||
var XQUERY_3_1_LANGUAGE: Language; | ||
var XPATH_3_1_LANGUAGE: Language; | ||
} | ||
* Resolve to an array of numbers | ||
*/ | ||
NUMBERS_TYPE: ReturnType.NUMBERS; | ||
}; | ||
export declare const evaluateXPath: EvaluateXPath; | ||
/** | ||
@@ -479,3 +532,3 @@ * Evaluates an XPath on the given contextNode. Returns the result as an array, if the result is an XPath array. | ||
[ReturnType.BOOLEAN]: boolean; | ||
[ReturnType.NODES]: T[] | undefined[]; | ||
[ReturnType.NODES]: T[]; | ||
[ReturnType.FIRST_NODE]: T | null; | ||
@@ -482,0 +535,0 @@ [ReturnType.STRINGS]: string[]; |
@@ -0,0 +0,0 @@ MIT License |
{ | ||
"name": "fontoxpath", | ||
"version": "3.9.2", | ||
"version": "3.10.0", | ||
"description": "A minimalistic XPath 3.1 engine in JavaScript", | ||
@@ -60,34 +60,33 @@ "main": "dist/fontoxpath.js", | ||
"devDependencies": { | ||
"@microsoft/api-extractor": "^7.3.8", | ||
"@types/chai": "^4.2.0", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.7.2", | ||
"@microsoft/api-extractor": "^7.7.7", | ||
"@tscc/tscc": "^0.4.8", | ||
"@types/chai": "^4.2.7", | ||
"@types/mocha": "^7.0.0", | ||
"@types/node": "^13.5.0", | ||
"@types/node-static": "^0.7.3", | ||
"@types/sinon": "^7.0.13", | ||
"@types/sinon": "^7.5.1", | ||
"chai": "^4.2.0", | ||
"concurrently": "^5.0.0", | ||
"coveralls": "^3.0.6", | ||
"cross-env": "^6.0.3", | ||
"concurrently": "^5.1.0", | ||
"coveralls": "^3.0.9", | ||
"cross-env": "^7.0.0", | ||
"fs-extra": "^8.1.0", | ||
"google-closure-compiler": "^20190929.0.0", | ||
"mocha": "^6.2.0", | ||
"mocha": "^7.0.1", | ||
"node-static": "^0.7.11", | ||
"nyc": "^14.1.1", | ||
"nyc": "^15.0.0", | ||
"pegjs": "^0.10.0", | ||
"prettier": "^1.18.2", | ||
"sinon": "^7.4.1", | ||
"sinon-chai": "^3.3.0", | ||
"slimdom": "^2.3.1", | ||
"slimdom-sax-parser": "^1.2.1", | ||
"source-map-support": "^0.5.13", | ||
"prettier": "^1.19.1", | ||
"sinon": "^8.1.1", | ||
"sinon-chai": "^3.4.0", | ||
"slimdom": "^2.3.2", | ||
"slimdom-sax-parser": "^1.3.0", | ||
"source-map-support": "^0.5.16", | ||
"ts-mocha": "^6.0.0", | ||
"ts-node": "^8.3.0", | ||
"tsconfig-paths": "^3.8.0", | ||
"tsickle": "^0.37.0", | ||
"tslint": "^5.18.0", | ||
"ts-node": "^8.6.2", | ||
"tscc": "0.0.2", | ||
"tsconfig-paths": "^3.9.0", | ||
"tslint": "^6.0.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.5.3", | ||
"uglify-js": "^3.6.0" | ||
}, | ||
"dependencies": {} | ||
"typescript": "^3.7.5", | ||
"uglify-js": "^3.7.6" | ||
} | ||
} |
@@ -53,3 +53,3 @@ # fontoxpath [](https://travis-ci.org/FontoXML/fontoxpath) [](https://david-dm.org/FontoXML/fontoxpath#info=devDependencies) [](http://badge.fury.io/js/fontoxpath) [](https://greenkeeper.io/) [](https://packagephobia.now.sh/result?p=fontoxpath) [](https://coveralls.io/github/FontoXML/fontoxpath?branch=master) | ||
* `moduleImports` `<Object<string, string>` | ||
* `debug` `<boolean>` If a debug trace should be tracked, see (debugging)[#] for more information. | ||
* `debug` `<boolean>` If a debug trace should be tracked, see [debugging](#debugging) for more information. | ||
@@ -90,3 +90,3 @@ ### Example | ||
(1, 2, 3) | ||
`, null, null, null, {debugMode: true}); | ||
`, null, null, null, {debug: true}); | ||
@@ -145,12 +145,2 @@ // Throws: | ||
### Pre compilation | ||
Precompile an XPath expression for future use. This uses a webworker to populate an IndexedDB database so that the XPath is available for future use. This is a no-op on systems without indexedDB. | ||
```js | ||
precompileXPath(xpathExpression); | ||
``` | ||
* `xpathExpression` `<String>` The XPath expression. | ||
### Global functions | ||
@@ -164,3 +154,3 @@ | ||
* `name` `<String>` The function name. | ||
* `name` `<string>` The function name. | ||
* `signature` `string[]` The arguments of the function. | ||
@@ -207,3 +197,3 @@ * `returnType` `string` The return type of the function. | ||
For all available features, see the unit tests. | ||
For all available features, see the unit tests, or just try it out on the [Demo page](https://xpath.playground.fontoxml.com). | ||
@@ -219,2 +209,4 @@ ## Compatibility | ||
Please refer to the [Contribution Guide](./CONTRIBUTING.md). | ||
If you have any questions on how to use FontoXPath, or if you are running into problems, just file a | ||
github issue! If you are looking to contribute, we have a [Contribution Guide](./CONTRIBUTING.md) | ||
that should help you in getting your development environment set up. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
972182
2207
207