UNPKG

docxml

Version:

TypeScript (component) library for building and parsing a DOCX file

127 lines (126 loc) 4.9 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.evaluateXPathToString = exports.evaluateXPathToNumber = exports.evaluateXPathToBoolean = exports.evaluateXPathToNodes = exports.evaluateXPathToFirstNode = exports.evaluateXPathToMap = exports.evaluateXPathToArray = exports.evaluateXPath = exports.XQUERY_3_1_LANGUAGE = void 0; /** * @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; const fontoxpath_1 = __importDefault(require("fontoxpath")); const xquery_functions_js_1 = require("./xquery-functions.js"); exports.XQUERY_3_1_LANGUAGE = fontoxpath_1.default.evaluateXPath.XQUERY_3_1_LANGUAGE; const OPTIONS = { language: exports.XQUERY_3_1_LANGUAGE, moduleImports: { docxml: xquery_functions_js_1.DOCXML_NS_URI, }, }; function evaluateXPath(...[query, node, domFacade, variables, returnType, options]) { try { return fontoxpath_1.default.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); } } exports.evaluateXPath = evaluateXPath; function evaluateXPathToArray(...[query, node, domFacade, variables, options]) { try { return fontoxpath_1.default.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); } } exports.evaluateXPathToArray = evaluateXPathToArray; function evaluateXPathToMap(...[query, node, domFacade, variables, options]) { try { return fontoxpath_1.default.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); } } exports.evaluateXPathToMap = evaluateXPathToMap; function evaluateXPathToFirstNode(...[query, node, domFacade, variables, options]) { try { return fontoxpath_1.default.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); } } exports.evaluateXPathToFirstNode = evaluateXPathToFirstNode; function evaluateXPathToNodes(...[query, node, domFacade, variables, options]) { try { return fontoxpath_1.default.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); } } exports.evaluateXPathToNodes = evaluateXPathToNodes; function evaluateXPathToBoolean(...[query, node, domFacade, variables, options]) { try { return fontoxpath_1.default.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); } } exports.evaluateXPathToBoolean = evaluateXPathToBoolean; function evaluateXPathToNumber(...[query, node, domFacade, variables, options]) { try { return fontoxpath_1.default.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); } } exports.evaluateXPathToNumber = evaluateXPathToNumber; function evaluateXPathToString(...[query, node, domFacade, variables, options]) { try { return fontoxpath_1.default.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); } } exports.evaluateXPathToString = evaluateXPathToString;