UNPKG

docxml

Version:

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

31 lines (30 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getChangeInformation = void 0; const namespaces_js_1 = require("./namespaces.js"); const xquery_js_1 = require("./xquery.js"); /** * Parses common change tracking information from a given node. * * For convenience the node is "optional", in the sense that TS will not complain when passing in * the result of a query (which may or may not be strictly a node). If no node is passed, the * function will throw. Only use this function if you're already certain you have a change tracking * node. */ function getChangeInformation(node) { if (!node) { throw new Error(`Unexpectedly missing node with change information.`); } const props = (0, xquery_js_1.evaluateXPathToMap)(` map { "id": ./@${namespaces_js_1.QNS.w}id/number(), "author": ./@${namespaces_js_1.QNS.w}author/string(), "date": ./@${namespaces_js_1.QNS.w}date/string() } `, node); return { ...props, date: new Date(props.date), }; } exports.getChangeInformation = getChangeInformation;