Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cheerio-select

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cheerio-select - npm Package Compare versions

Comparing version 1.6.0 to 2.0.0

lib/esm/helpers.d.ts

4

lib/helpers.d.ts

@@ -1,5 +0,5 @@

import type { Node } from "domhandler";
import type { AnyNode } from "domhandler";
import type { Selector } from "css-what";
export declare function getDocumentRoot(node: Node): Node;
export declare function getDocumentRoot(node: AnyNode): AnyNode;
export declare function groupSelectors(selectors: Selector[][]): [plain: Selector[][], filtered: Selector[][]];
//# sourceMappingURL=helpers.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.groupSelectors = exports.getDocumentRoot = void 0;
var positionals_1 = require("./positionals");
var positionals_js_1 = require("./positionals.js");
function getDocumentRoot(node) {

@@ -16,3 +16,3 @@ while (node.parent)

var selector = selectors_1[_i];
if (selector.some(positionals_1.isFilter)) {
if (selector.some(positionals_js_1.isFilter)) {
filteredSelectors.push(selector);

@@ -27,1 +27,2 @@ }

exports.groupSelectors = groupSelectors;
//# sourceMappingURL=helpers.js.map

@@ -1,5 +0,5 @@

import { Options as CSSSelectOptions } from "css-select";
import type { Element, Node, Document } from "domhandler";
import { type Options as CSSSelectOptions } from "css-select";
import type { Element, AnyNode, Document } from "domhandler";
export { filters, pseudos, aliases } from "css-select";
export interface Options extends CSSSelectOptions<Node, Element> {
export interface Options extends CSSSelectOptions<AnyNode, Element> {
/** Optional reference to the root of the document. If not set, this will be computed when needed. */

@@ -10,4 +10,4 @@ root?: Document;

export declare function some(elements: Element[], selector: string | ((el: Element) => boolean), options?: Options): boolean;
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[];
export declare function filter(selector: string, elements: AnyNode[], options?: Options): Element[];
export declare function select(selector: string | ((el: Element) => boolean), root: AnyNode | AnyNode[], options?: Options): Element[];
//# sourceMappingURL=index.d.ts.map

@@ -50,4 +50,5 @@ "use strict";

var DomUtils = __importStar(require("domutils"));
var helpers_1 = require("./helpers");
var positionals_1 = require("./positionals");
var boolbase = __importStar(require("boolbase"));
var helpers_js_1 = require("./helpers.js");
var positionals_js_1 = require("./positionals.js");
// Re-export pseudo extension points

@@ -58,3 +59,6 @@ var css_select_2 = require("css-select");

Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return css_select_2.aliases; } });
/** Used to indicate a scope should be filtered. Might be ignored when filtering. */
var UNIVERSAL_SELECTOR = {
type: css_what_1.SelectorType.Universal,
namespace: null,
};
var SCOPE_PSEUDO = {

@@ -65,8 +69,2 @@ type: css_what_1.SelectorType.Pseudo,

};
/** Used for actually filtering for scope. */
var CUSTOM_SCOPE_PSEUDO = __assign({}, SCOPE_PSEUDO);
var UNIVERSAL_SELECTOR = {
type: css_what_1.SelectorType.Universal,
namespace: null,
};
function is(element, selector, options) {

@@ -81,3 +79,3 @@ if (options === void 0) { options = {}; }

return elements.some(selector);
var _a = (0, helpers_1.groupSelectors)((0, css_what_1.parse)(selector)), plain = _a[0], filtered = _a[1];
var _a = (0, helpers_js_1.groupSelectors)((0, css_what_1.parse)(selector)), plain = _a[0], filtered = _a[1];
return ((plain.length > 0 && elements.some((0, css_select_1._compileToken)(plain, options))) ||

@@ -130,3 +128,3 @@ filtered.some(function (sel) { return filterBySelector(sel, elements, options).length > 0; }));

return [];
var _a = (0, helpers_1.groupSelectors)(selector), plainSelectors = _a[0], filteredSelectors = _a[1];
var _a = (0, helpers_js_1.groupSelectors)(selector), plainSelectors = _a[0], filteredSelectors = _a[1];
var found;

@@ -184,5 +182,6 @@ if (plainSelectors.length) {

*/
var root = (_a = options.root) !== null && _a !== void 0 ? _a : (0, helpers_1.getDocumentRoot)(elements[0]);
var sel = __spreadArray(__spreadArray([], selector, true), [CUSTOM_SCOPE_PSEUDO], false);
return findFilterElements(root, sel, options, true, elements);
var root = (_a = options.root) !== null && _a !== void 0 ? _a : (0, helpers_js_1.getDocumentRoot)(elements[0]);
var opts = __assign(__assign({}, options), { context: elements, relativeSelector: false });
selector.push(SCOPE_PSEUDO);
return findFilterElements(root, selector, opts, true);
}

@@ -197,3 +196,3 @@ // Performance optimization: If we don't have to traverse, just filter set.

}
var _a = (0, helpers_1.groupSelectors)((0, css_what_1.parse)(selector)), plain = _a[0], filtered = _a[1];
var _a = (0, helpers_js_1.groupSelectors)((0, css_what_1.parse)(selector)), plain = _a[0], filtered = _a[1];
var results = filtered.map(function (sel) {

@@ -218,17 +217,6 @@ return findFilterElements(root, sel, options, true);

// Traversals that are treated differently in css-select.
var specialTraversal = new Set([
css_what_1.SelectorType.Descendant,
var siblingTraversal = new Set([
css_what_1.SelectorType.Sibling,
css_what_1.SelectorType.Adjacent,
]);
function includesScopePseudo(t) {
return (t !== SCOPE_PSEUDO &&
t.type === "pseudo" &&
(t.name === "scope" ||
(Array.isArray(t.data) &&
t.data.some(function (data) { return data.some(includesScopePseudo); }))));
}
function addContextIfScope(selector, options, scopeContext) {
return scopeContext && selector.some(includesScopePseudo)
? __assign(__assign({}, options), { context: scopeContext }) : options;
}
/**

@@ -240,6 +228,5 @@ *

* @param queryForSelector Query multiple levels deep for the initial selector, even if it doesn't contain a traversal.
* @param scopeContext Optional context for a :scope.
*/
function findFilterElements(root, selector, options, queryForSelector, scopeContext) {
var filterIndex = selector.findIndex(positionals_1.isFilter);
function findFilterElements(root, selector, options, queryForSelector) {
var filterIndex = selector.findIndex(positionals_js_1.isFilter);
var sub = selector.slice(0, filterIndex);

@@ -251,6 +238,5 @@ var filter = selector[filterIndex];

*/
var limit = (0, positionals_1.getLimit)(filter.name, filter.data);
var limit = (0, positionals_js_1.getLimit)(filter.name, filter.data);
if (limit === 0)
return [];
var subOpts = addContextIfScope(sub, options, scopeContext);
/*

@@ -262,7 +248,7 @@ * Skip `findElements` call if our selector starts with a positional

? DomUtils.getChildren(root).filter(DomUtils.isTag)
: sub.length === 0 || (sub.length === 1 && sub[0] === SCOPE_PSEUDO)
: sub.length === 0
? (Array.isArray(root) ? root : [root]).filter(DomUtils.isTag)
: queryForSelector || sub.some(css_what_1.isTraversal)
? findElements(root, [sub], subOpts, limit)
: filterElements(root, [sub], subOpts);
? findElements(root, [sub], options, limit)
: filterElements(root, [sub], options);
var elems = elemsNoLimit.slice(0, limit);

@@ -275,19 +261,23 @@ var result = filterByPosition(filter.name, elems, filter.data, options);

var remainingHasTraversal = remainingSelector.some(css_what_1.isTraversal);
var remainingOpts = addContextIfScope(remainingSelector, options, scopeContext);
if (remainingHasTraversal) {
/*
* Some types of traversals have special logic when they start a selector
* in css-select. If this is the case, add a universal selector in front of
* the selector to avoid this behavior.
*/
if (specialTraversal.has(remainingSelector[0].type)) {
if ((0, css_what_1.isTraversal)(remainingSelector[0])) {
if (siblingTraversal.has(remainingSelector[0].type)) {
// If we have a sibling traversal, we need to also look at the siblings.
result = (0, css_select_1.prepareContext)(result, DomUtils, true);
}
// Avoid a traversal-first selector error.
remainingSelector.unshift(UNIVERSAL_SELECTOR);
}
/*
* Add a scope token in front of the remaining selector,
* to make sure traversals don't match elements that aren't a
* part of the considered tree.
*/
remainingSelector.unshift(SCOPE_PSEUDO);
options = __assign(__assign({}, options), {
// Avoid absolutizing the selector
relativeSelector: false,
/*
* Add a custom root func, to make sure traversals don't match elements
* that aren't a part of the considered tree.
*/
rootFunc: function (el) { return result.includes(el); } });
}
else if (options.rootFunc && options.rootFunc !== boolbase.trueFunc) {
options = __assign(__assign({}, options), { rootFunc: boolbase.trueFunc });
}
/*

@@ -300,13 +290,11 @@ * If we have another filter, recursively call `findFilterElements`,

*/
return remainingSelector.some(positionals_1.isFilter)
? findFilterElements(result, remainingSelector, options, false, scopeContext)
return remainingSelector.some(positionals_js_1.isFilter)
? findFilterElements(result, remainingSelector, options, false)
: remainingHasTraversal
? // Query existing elements to resolve traversal.
findElements(result, [remainingSelector], remainingOpts, Infinity)
findElements(result, [remainingSelector], options, Infinity)
: // If we don't have any more traversals, simply filter elements.
filterElements(result, [remainingSelector], remainingOpts);
filterElements(result, [remainingSelector], options);
}
function findElements(root, sel, options, limit) {
if (limit === 0)
return [];
var query = (0, css_select_1._compileToken)(sel, options, root);

@@ -325,3 +313,4 @@ return find(root, query, limit);

var query = (0, css_select_1._compileToken)(sel, options);
return els.filter(query);
return query === boolbase.trueFunc ? els : els.filter(query);
}
//# sourceMappingURL=index.js.map

@@ -43,1 +43,2 @@ "use strict";

exports.getLimit = getLimit;
//# sourceMappingURL=positionals.js.map
{
"name": "cheerio-select",
"description": "CSS selector engine supporting jQuery selectors",
"version": "1.6.0",
"version": "2.0.0",
"author": "Felix Boehm <me@feedic.com>",

@@ -20,2 +20,7 @@ "funding": {

"types": "lib/index.d.ts",
"module": "lib/esm/index.js",
"exports": {
"require": "./lib/index.js",
"import": "./lib/esm/index.js"
},
"files": [

@@ -34,23 +39,27 @@ "lib/**/*"

"format:prettier:raw": "prettier '**/*.{ts,md,json,yml}'",
"build": "tsc",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc --sourceRoot https://raw.githubusercontent.com/cheeriojs/cheerio-select/$(git rev-parse HEAD)/src/",
"build:esm": "npm run build:cjs -- --module esnext --target es2019 --outDir lib/esm && echo '{\"type\":\"module\"}' > lib/esm/package.json",
"prepare": "npm run build"
},
"dependencies": {
"css-select": "^4.3.0",
"css-what": "^6.0.1",
"domelementtype": "^2.2.0",
"domhandler": "^4.3.1",
"domutils": "^2.8.0"
"boolbase": "^1.0.0",
"css-select": "^5.1.0",
"css-what": "^6.1.0",
"domelementtype": "^2.3.0",
"domhandler": "^5.0.2",
"domutils": "^3.0.1"
},
"devDependencies": {
"@types/boolbase": "^1.0.1",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"eslint": "^8.12.0",
"@types/node": "^17.0.29",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"htmlparser2": "^7.2.0",
"htmlparser2": "^8.0.0",
"jest": "^27.5.1",
"prettier": "^2.6.1",
"ts-jest": "^27.1.3",
"prettier": "^2.6.2",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"

@@ -60,3 +69,7 @@ },

"preset": "ts-jest",
"testEnvironment": "node"
"testEnvironment": "node",
"coverageProvider": "v8",
"moduleNameMapper": {
"^(.*)\\.js$": "$1"
}
},

@@ -63,0 +76,0 @@ "prettier": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc