docxml
Version:
TypeScript (component) library for building and parsing a DOCX file
113 lines (112 loc) • 3.88 kB
JavaScript
/**
* @file
* Proxies most of the fontoxpath methods and fixes some of the typing around it. Also, XPath errors
* will no longer have a stack trace pointing to the (minified) fontoxpath internals, but instead
* tell you where the query was run from.
*/
// Import the file that registers custom XPath functions to the fontoxpath global;
import fontoxpath from 'fontoxpath';
import { DOCXML_NS_URI } from './xquery-functions.js';
export const XQUERY_3_1_LANGUAGE = fontoxpath.evaluateXPath.XQUERY_3_1_LANGUAGE;
const OPTIONS = {
language: XQUERY_3_1_LANGUAGE,
moduleImports: {
docxml: DOCXML_NS_URI,
},
};
export function evaluateXPath(...[query, node, domFacade, variables, returnType, options]) {
try {
return fontoxpath.evaluateXPath(query, node, domFacade, variables, returnType, {
...(options || {}),
...OPTIONS,
});
}
catch (error) {
// Rethrow because we're not interested in the fontoxpath stack itself.
throw new Error(error.message);
}
}
export function evaluateXPathToArray(...[query, node, domFacade, variables, options]) {
try {
return fontoxpath.evaluateXPathToArray(query, node, domFacade, variables, {
...(options || {}),
...OPTIONS,
});
}
catch (error) {
// Rethrow because we're not interested in the fontoxpath stack itself.
throw new Error(error.message);
}
}
export function evaluateXPathToMap(...[query, node, domFacade, variables, options]) {
try {
return fontoxpath.evaluateXPathToMap(query, node, domFacade, variables, {
...(options || {}),
...OPTIONS,
});
}
catch (error) {
// Rethrow because we're not interested in the fontoxpath stack itself.
throw new Error(error.message);
}
}
export function evaluateXPathToFirstNode(...[query, node, domFacade, variables, options]) {
try {
return fontoxpath.evaluateXPathToFirstNode(query, node, domFacade, variables, {
...(options || {}),
...OPTIONS,
});
}
catch (error) {
// Rethrow because we're not interested in the fontoxpath stack itself.
throw new Error(error.stack);
}
}
export function evaluateXPathToNodes(...[query, node, domFacade, variables, options]) {
try {
return fontoxpath.evaluateXPathToNodes(query, node, domFacade, variables, {
...(options || {}),
...OPTIONS,
});
}
catch (error) {
// Rethrow because we're not interested in the fontoxpath stack itself.
throw new Error(error.message);
}
}
export function evaluateXPathToBoolean(...[query, node, domFacade, variables, options]) {
try {
return fontoxpath.evaluateXPathToBoolean(query, node, domFacade, variables, {
...(options || {}),
...OPTIONS,
});
}
catch (error) {
// Rethrow because we're not interested in the fontoxpath stack itself.
throw new Error(error.message);
}
}
export function evaluateXPathToNumber(...[query, node, domFacade, variables, options]) {
try {
return fontoxpath.evaluateXPathToNumber(query, node, domFacade, variables, {
...(options || {}),
...OPTIONS,
});
}
catch (error) {
// Rethrow because we're not interested in the fontoxpath stack itself.
throw new Error(error.message);
}
}
export function evaluateXPathToString(...[query, node, domFacade, variables, options]) {
try {
return fontoxpath.evaluateXPathToString(query, node, domFacade, variables, {
...(options || {}),
...OPTIONS,
});
}
catch (error) {
// Rethrow because we're not interested in the fontoxpath stack itself.
throw new Error(error.message);
}
}