diff --git a/src/count.js b/src/count.js deleted file mode 100644 index 2a40b63..0000000 --- a/src/count.js +++ /dev/null @@ -1,20 +0,0 @@ -const utils = require('./utils.js'); - -/** - * Counts the amount of results of the provided XPath. - * @param {Document} xmlDoc The instance of `Document` representating the XML document. - * @param {string} xpath The XPath to count in `xmlDoc`. - * @returns {number} The amount of results. - */ -function count(xmlDoc, xpath) { - if (!xmlDoc) throw new Error('A Document must be provided.'); - if (typeof xpath !== 'string') throw new Error('path must be a string.'); - - if (!xmlDoc.namespace) return xmlDoc.get(`count(${xpath})`); - - const fullXPath = `count(${utils.addNamespacePrefixInPath(xmlDoc.namespace.alias, xpath)})`; - - return xmlDoc.get(fullXPath, { [xmlDoc.namespace.alias]: xmlDoc.namespace.url }); -} - -module.exports = count; diff --git a/src/find.js b/src/find.js deleted file mode 100644 index 02bb228..0000000 --- a/src/find.js +++ /dev/null @@ -1,20 +0,0 @@ -const utils = require('./utils.js'); - -/** - * Finds the result of the provided XPath. - * @param {Document} xmlDoc The instance of `Document` representating the XML document. - * @param {string} xpath The XPath to get in `xmlDoc`. - * @returns {(Element|Element[])} The found `Element` or `Element`s. - */ -function find(xmlDoc, xpath) { - if (!xmlDoc) throw new Error('A Document must be provided.'); - if (typeof xpath !== 'string') throw new Error('path must be a string.'); - - if (!xmlDoc.namespace) return xmlDoc.find(xpath); - - const fullXPath = utils.addNamespacePrefixInPath(xmlDoc.namespace.alias, xpath); - - return xmlDoc.find(fullXPath, { [xmlDoc.namespace.alias]: xmlDoc.namespace.url }); -} - -module.exports = find; diff --git a/src/namespace.js b/src/namespace.js deleted file mode 100644 index 3be715b..0000000 --- a/src/namespace.js +++ /dev/null @@ -1,21 +0,0 @@ -const utils = require('./utils.js'); - -/** - * Sets the namespace to use for the specified `Document`. - * @param {Document} xmlDoc The `Document` instance to set the namespace of. - * @param {string} alias The namespace alias. - * @param {string} url The namespace URL. - */ -function setNamespace(xmlDoc, alias, url) { - if (!xmlDoc) throw new Error('A Document must be provided.'); - if (typeof alias !== 'string') throw new Error('alias must be a string.'); - if (typeof url !== 'string') throw new Error('url must be a string.'); - if (!utils.isValidURL(url)) throw new Error('url is not a valid URL.'); - - xmlDoc.namespace = { - alias, - url, - }; -} - -module.exports = setNamespace;