UNPKG

epubavocado

Version:

I am an EPUB object model aspiring to be standards compliant.

47 lines (46 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Entity = void 0; var xpath_js_1 = require("../../xpath.js"); var Entity = /** @class */ (function () { function Entity(node, context) { this._node = node; this._context = context || this; } Entity.prototype._select = function (expression) { return xpath_js_1.select(expression, this._node); }; Entity.prototype._selectAll = function (expression) { return xpath_js_1.selectAll(expression, this._node); }; Entity.prototype._resolve = function (expression, constructor) { var node = this._select(expression); if (!node) { return null; } if (constructor) { return new constructor(node, this._context); } var attrType = node; var nodeType = node; if (attrType.value) { return attrType.value; } if (nodeType.nodeValue) { return nodeType.nodeValue; } }; Entity.prototype._resolveAll = function (expression, constructor) { var _this = this; var nodes = this._selectAll(expression); if (!nodes) { return []; } if (constructor) { return nodes.map(function (node) { return new constructor(node, _this._context); }); } return nodes.map(function (node) { return node.nodeValue; }); }; return Entity; }()); exports.Entity = Entity;