cheerio-select
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -1,5 +0,5 @@ | ||
import type { NodeWithChildren } from "domhandler"; | ||
import type { Node } from "domhandler"; | ||
import type { Selector } from "css-what"; | ||
export declare function getDocumentRoot(node: NodeWithChildren): NodeWithChildren; | ||
export declare function getDocumentRoot(node: Node): Node; | ||
export declare function groupSelectors(selectors: Selector[][]): [plain: Selector[][], filtered: Selector[][]]; | ||
//# sourceMappingURL=helpers.d.ts.map |
import { Options as CSSSelectOptions } from "css-select"; | ||
import type { Element, Node } from "domhandler"; | ||
import type { Element, Node, Document } from "domhandler"; | ||
export { filters, pseudos, aliases } from "css-select"; | ||
export declare type Options = CSSSelectOptions<Node, Element>; | ||
export interface Options extends CSSSelectOptions<Node, Element> { | ||
/** Optional reference to the root of the document. If not set, this will be computed when needed. */ | ||
root?: Document; | ||
} | ||
export declare function is(element: Element, selector: string | ((el: Element) => boolean), options?: Options): boolean; | ||
export declare function some(elements: Element[], selector: string | ((el: Element) => boolean), options?: Options): boolean; | ||
export declare function filter(selector: string, elements: Element[], options?: Options): Element[]; | ||
export declare function filter(selector: string, elements: Node[], options?: Options): Element[]; | ||
export declare function select(selector: string | ((el: Element) => boolean), root: Node | Node[], options?: Options): Element[]; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -60,7 +60,3 @@ "use strict"; | ||
if (options === void 0) { options = {}; } | ||
if (typeof selector === "function") | ||
return selector(element); | ||
var _a = helpers_1.groupSelectors(css_what_1.parse(selector, options)), plain = _a[0], filtered = _a[1]; | ||
return ((plain.length > 0 && css_select_1.is(element, plain, options)) || | ||
filtered.some(function (sel) { return filterBySelector(sel, [element], options).length > 0; })); | ||
return some([element], selector, options); | ||
} | ||
@@ -136,3 +132,3 @@ exports.is = is; | ||
var missing = found | ||
? elements.filter(function (e) { return !found.has(e); }) | ||
? elements.filter(function (e) { return DomUtils.isTag(e) && !found.has(e); }) | ||
: elements; | ||
@@ -159,14 +155,18 @@ if (missing.length === 0) | ||
return typeof found !== "undefined" | ||
? found.size === elements.length | ||
? (found.size === elements.length | ||
? elements | ||
: elements.filter(function (el) { return found.has(el); }) | ||
: // Filter elements to preserve order | ||
elements.filter(function (el) { | ||
return found.has(el); | ||
})) | ||
: []; | ||
} | ||
function filterBySelector(selector, elements, options) { | ||
var _a; | ||
if (selector.some(css_what_1.isTraversal)) { | ||
/* | ||
* Get one root node, run selector with the scope | ||
* Get root node, run selector with the scope | ||
* set to all of our nodes. | ||
*/ | ||
var root = helpers_1.getDocumentRoot(elements[0]); | ||
var root = (_a = options.root) !== null && _a !== void 0 ? _a : helpers_1.getDocumentRoot(elements[0]); | ||
var sel = __spreadArray(__spreadArray([], selector), [CUSTOM_SCOPE_PSEUDO]); | ||
@@ -173,0 +173,0 @@ return findFilterElements(root, sel, options, true, elements); |
{ | ||
"name": "cheerio-select", | ||
"description": "CSS selector engine supporting jQuery selectors", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"author": "Felix Boehm <me@feedic.com>", | ||
@@ -37,20 +37,20 @@ "funding": { | ||
"dependencies": { | ||
"css-select": "^4.1.2", | ||
"css-what": "^5.0.0", | ||
"css-select": "^4.1.3", | ||
"css-what": "^5.0.1", | ||
"domelementtype": "^2.2.0", | ||
"domhandler": "^4.2.0", | ||
"domutils": "^2.6.0" | ||
"domutils": "^2.7.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.22", | ||
"@typescript-eslint/eslint-plugin": "^4.22.0", | ||
"@typescript-eslint/parser": "^4.22.0", | ||
"@types/jest": "^26.0.23", | ||
"@typescript-eslint/eslint-plugin": "^4.26.0", | ||
"@typescript-eslint/parser": "^4.26.0", | ||
"coveralls": "^3.1.0", | ||
"eslint": "^7.24.0", | ||
"eslint-config-prettier": "^8.2.0", | ||
"eslint": "^7.28.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"htmlparser2": "^6.1.0", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.5.5", | ||
"typescript": "^4.2.4" | ||
"jest": "^27.0.4", | ||
"prettier": "^2.3.1", | ||
"ts-jest": "^27.0.3", | ||
"typescript": "^4.3.2" | ||
}, | ||
@@ -57,0 +57,0 @@ "jest": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
22316
387
Updatedcss-select@^4.1.3
Updatedcss-what@^5.0.1
Updateddomutils@^2.7.0