diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-06 22:18:28 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-06 22:18:28 +0200 |
commit | 83354b2b88218090988dd6e526b0a2505b57e0f1 (patch) | |
tree | e3c73c38a122a78bb7e66fbb99056407edd9d4b9 /includes/external/addressbook/node_modules/domutils/lib/esm/legacy.js | |
parent | 47b8f2299a483024c4a6a8876af825a010954caa (diff) | |
download | pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.gz pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.bz2 pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.zip |
Updated 5 files and added 1110 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/domutils/lib/esm/legacy.js')
-rw-r--r-- | includes/external/addressbook/node_modules/domutils/lib/esm/legacy.js | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/domutils/lib/esm/legacy.js b/includes/external/addressbook/node_modules/domutils/lib/esm/legacy.js new file mode 100644 index 0000000..113f470 --- /dev/null +++ b/includes/external/addressbook/node_modules/domutils/lib/esm/legacy.js @@ -0,0 +1,117 @@ +import { isTag, isText } from "domhandler"; +import { filter, findOne } from "./querying.js"; +const Checks = { + tag_name(name) { + if (typeof name === "function") { + return (elem) => isTag(elem) && name(elem.name); + } + else if (name === "*") { + return isTag; + } + return (elem) => isTag(elem) && elem.name === name; + }, + tag_type(type) { + if (typeof type === "function") { + return (elem) => type(elem.type); + } + return (elem) => elem.type === type; + }, + tag_contains(data) { + if (typeof data === "function") { + return (elem) => isText(elem) && data(elem.data); + } + return (elem) => isText(elem) && elem.data === data; + }, +}; +/** + * @param attrib Attribute to check. + * @param value Attribute value to look for. + * @returns A function to check whether the a node has an attribute with a + * particular value. + */ +function getAttribCheck(attrib, value) { + if (typeof value === "function") { + return (elem) => isTag(elem) && value(elem.attribs[attrib]); + } + return (elem) => isTag(elem) && elem.attribs[attrib] === value; +} +/** + * @param a First function to combine. + * @param b Second function to combine. + * @returns A function taking a node and returning `true` if either of the input + * functions returns `true` for the node. + */ +function combineFuncs(a, b) { + return (elem) => a(elem) || b(elem); +} +/** + * @param options An object describing nodes to look for. + * @returns A function executing all checks in `options` and returning `true` if + * any of them match a node. + */ +function compileTest(options) { + const funcs = Object.keys(options).map((key) => { + const value = options[key]; + return Object.prototype.hasOwnProperty.call(Checks, key) + ? Checks[key](value) + : getAttribCheck(key, value); + }); + return funcs.length === 0 ? null : funcs.reduce(combineFuncs); +} +/** + * @category Legacy Query Functions + * @param options An object describing nodes to look for. + * @param node The element to test. + * @returns Whether the element matches the description in `options`. + */ +export function testElement(options, node) { + const test = compileTest(options); + return test ? test(node) : true; +} +/** + * @category Legacy Query Functions + * @param options An object describing nodes to look for. + * @param nodes Nodes to search through. + * @param recurse Also consider child nodes. + * @param limit Maximum number of nodes to return. + * @returns All nodes that match `options`. + */ +export function getElements(options, nodes, recurse, limit = Infinity) { + const test = compileTest(options); + return test ? filter(test, nodes, recurse, limit) : []; +} +/** + * @category Legacy Query Functions + * @param id The unique ID attribute value to look for. + * @param nodes Nodes to search through. + * @param recurse Also consider child nodes. + * @returns The node with the supplied ID. + */ +export function getElementById(id, nodes, recurse = true) { + if (!Array.isArray(nodes)) + nodes = [nodes]; + return findOne(getAttribCheck("id", id), nodes, recurse); +} +/** + * @category Legacy Query Functions + * @param tagName Tag name to search for. + * @param nodes Nodes to search through. + * @param recurse Also consider child nodes. + * @param limit Maximum number of nodes to return. + * @returns All nodes with the supplied `tagName`. + */ +export function getElementsByTagName(tagName, nodes, recurse = true, limit = Infinity) { + return filter(Checks["tag_name"](tagName), nodes, recurse, limit); +} +/** + * @category Legacy Query Functions + * @param type Element type to look for. + * @param nodes Nodes to search through. + * @param recurse Also consider child nodes. + * @param limit Maximum number of nodes to return. + * @returns All nodes with the supplied `type`. + */ +export function getElementsByTagType(type, nodes, recurse = true, limit = Infinity) { + return filter(Checks["tag_type"](type), nodes, recurse, limit); +} +//# sourceMappingURL=legacy.js.map
\ No newline at end of file |