Socket
Socket
Sign inDemoInstall

css-select

Package Overview
Dependencies
8
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.2.1 to 4.3.0

105

lib/attributes.js

@@ -16,10 +16,71 @@ "use strict";

/**
* Attributes that are case-insensitive in HTML.
*
* @private
* @see https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors
*/
var caseInsensitiveAttributes = new Set([
"accept",
"accept-charset",
"align",
"alink",
"axis",
"bgcolor",
"charset",
"checked",
"clear",
"codetype",
"color",
"compact",
"declare",
"defer",
"dir",
"direction",
"disabled",
"enctype",
"face",
"frame",
"hreflang",
"http-equiv",
"lang",
"language",
"link",
"media",
"method",
"multiple",
"nohref",
"noresize",
"noshade",
"nowrap",
"readonly",
"rel",
"rev",
"rules",
"scope",
"scrolling",
"selected",
"shape",
"target",
"text",
"type",
"valign",
"valuetype",
"vlink",
]);
function shouldIgnoreCase(selector, options) {
return typeof selector.ignoreCase === "boolean"
? selector.ignoreCase
: selector.ignoreCase === "quirks"
? !!options.quirksMode
: !options.xmlMode && caseInsensitiveAttributes.has(selector.name);
}
/**
* Attribute selectors
*/
exports.attributeRules = {
equals: function (next, data, _a) {
var adapter = _a.adapter;
equals: function (next, data, options) {
var adapter = options.adapter;
var name = data.name;
var value = data.value;
if (data.ignoreCase) {
if (shouldIgnoreCase(data, options)) {
value = value.toLowerCase();

@@ -38,8 +99,8 @@ return function (elem) {

},
hyphen: function (next, data, _a) {
var adapter = _a.adapter;
hyphen: function (next, data, options) {
var adapter = options.adapter;
var name = data.name;
var value = data.value;
var len = value.length;
if (data.ignoreCase) {
if (shouldIgnoreCase(data, options)) {
value = value.toLowerCase();

@@ -62,9 +123,9 @@ return function hyphenIC(elem) {

},
element: function (next, _a, _b) {
var name = _a.name, value = _a.value, ignoreCase = _a.ignoreCase;
var adapter = _b.adapter;
element: function (next, data, options) {
var adapter = options.adapter;
var name = data.name, value = data.value;
if (/\s/.test(value)) {
return boolbase_1.falseFunc;
}
var regex = new RegExp("(?:^|\\s)".concat(escapeRegex(value), "(?:$|\\s)"), ignoreCase ? "i" : "");
var regex = new RegExp("(?:^|\\s)".concat(escapeRegex(value), "(?:$|\\s)"), shouldIgnoreCase(data, options) ? "i" : "");
return function element(elem) {

@@ -83,4 +144,4 @@ var attr = adapter.getAttributeValue(elem, name);

},
start: function (next, data, _a) {
var adapter = _a.adapter;
start: function (next, data, options) {
var adapter = options.adapter;
var name = data.name;

@@ -92,3 +153,3 @@ var value = data.value;

}
if (data.ignoreCase) {
if (shouldIgnoreCase(data, options)) {
value = value.toLowerCase();

@@ -109,4 +170,4 @@ return function (elem) {

},
end: function (next, data, _a) {
var adapter = _a.adapter;
end: function (next, data, options) {
var adapter = options.adapter;
var name = data.name;

@@ -118,3 +179,3 @@ var value = data.value;

}
if (data.ignoreCase) {
if (shouldIgnoreCase(data, options)) {
value = value.toLowerCase();

@@ -133,4 +194,4 @@ return function (elem) {

},
any: function (next, data, _a) {
var adapter = _a.adapter;
any: function (next, data, options) {
var adapter = options.adapter;
var name = data.name, value = data.value;

@@ -140,3 +201,3 @@ if (value === "") {

}
if (data.ignoreCase) {
if (shouldIgnoreCase(data, options)) {
var regex_1 = new RegExp(escapeRegex(value), "i");

@@ -157,4 +218,4 @@ return function anyIC(elem) {

},
not: function (next, data, _a) {
var adapter = _a.adapter;
not: function (next, data, options) {
var adapter = options.adapter;
var name = data.name;

@@ -167,3 +228,3 @@ var value = data.value;

}
else if (data.ignoreCase) {
else if (shouldIgnoreCase(data, options)) {
value = value.toLowerCase();

@@ -170,0 +231,0 @@ return function (elem) {

@@ -26,3 +26,3 @@ "use strict";

function compileUnsafe(selector, options, context) {
var token = typeof selector === "string" ? (0, css_what_1.parse)(selector, options) : selector;
var token = typeof selector === "string" ? (0, css_what_1.parse)(selector) : selector;
return compileToken(token, options, context);

@@ -37,7 +37,11 @@ }

}
var DESCENDANT_TOKEN = { type: "descendant" };
var DESCENDANT_TOKEN = { type: css_what_1.SelectorType.Descendant };
var FLEXIBLE_DESCENDANT_TOKEN = {
type: "_flexibleDescendant",
};
var SCOPE_TOKEN = { type: "pseudo", name: "scope", data: null };
var SCOPE_TOKEN = {
type: css_what_1.SelectorType.Pseudo,
name: "scope",
data: null,
};
/*

@@ -44,0 +48,0 @@ * CSS 4 Spec (Draft): 3.3.1. Absolutizing a Scope-relative Selector

@@ -6,2 +6,3 @@ "use strict";

var pseudo_selectors_1 = require("./pseudo-selectors");
var css_what_1 = require("css-what");
/*

@@ -13,15 +14,35 @@ * All available rules

switch (selector.type) {
case "pseudo-element":
case css_what_1.SelectorType.PseudoElement: {
throw new Error("Pseudo-elements are not supported by css-select");
case "attribute":
}
case css_what_1.SelectorType.ColumnCombinator: {
throw new Error("Column combinators are not yet supported by css-select");
}
case css_what_1.SelectorType.Attribute: {
if (selector.namespace != null) {
throw new Error("Namespaced attributes are not yet supported by css-select");
}
if (!options.xmlMode || options.lowerCaseAttributeNames) {
selector.name = selector.name.toLowerCase();
}
return attributes_1.attributeRules[selector.action](next, selector, options);
case "pseudo":
}
case css_what_1.SelectorType.Pseudo: {
return (0, pseudo_selectors_1.compilePseudoSelector)(next, selector, options, context, compileToken);
}
// Tags
case "tag":
case css_what_1.SelectorType.Tag: {
if (selector.namespace != null) {
throw new Error("Namespaced tag names are not yet supported by css-select");
}
var name_1 = selector.name;
if (!options.xmlMode || options.lowerCaseTags) {
name_1 = name_1.toLowerCase();
}
return function tag(elem) {
return adapter.getName(elem) === selector.name && next(elem);
return adapter.getName(elem) === name_1 && next(elem);
};
}
// Traversal
case "descendant":
case css_what_1.SelectorType.Descendant: {
if (options.cacheResults === false ||

@@ -40,3 +61,2 @@ typeof WeakSet === "undefined") {

// @ts-expect-error `ElementNode` is not extending object
// eslint-disable-next-line no-case-declarations
var isFalseCache_1 = new WeakSet();

@@ -55,3 +75,4 @@ return function cachedDescendant(elem) {

};
case "_flexibleDescendant":
}
case "_flexibleDescendant": {
// Include element itself, only used while querying an array

@@ -66,3 +87,4 @@ return function flexibleDescendant(elem) {

};
case "parent":
}
case css_what_1.SelectorType.Parent: {
return function parent(elem) {

@@ -73,3 +95,4 @@ return adapter

};
case "child":
}
case css_what_1.SelectorType.Child: {
return function child(elem) {

@@ -79,3 +102,4 @@ var parent = adapter.getParent(elem);

};
case "sibling":
}
case css_what_1.SelectorType.Sibling: {
return function sibling(elem) {

@@ -93,3 +117,10 @@ var siblings = adapter.getSiblings(elem);

};
case "adjacent":
}
case css_what_1.SelectorType.Adjacent: {
if (adapter.prevElementSibling) {
return function adjacent(elem) {
var previous = adapter.prevElementSibling(elem);
return previous != null && next(previous);
};
}
return function adjacent(elem) {

@@ -108,6 +139,11 @@ var siblings = adapter.getSiblings(elem);

};
case "universal":
}
case css_what_1.SelectorType.Universal: {
if (selector.namespace != null && selector.namespace !== "*") {
throw new Error("Namespaced universal selectors are not yet supported by css-select");
}
return next;
}
}
}
exports.compileGeneralSelector = compileGeneralSelector;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

@@ -10,2 +10,3 @@ "use strict";

"pseudo-element": 0,
"column-combinator": -1,
descendant: -1,

@@ -12,0 +13,0 @@ child: -1,

@@ -37,3 +37,3 @@ "use strict";

// The alias has to be parsed here, to make sure options are respected.
var alias = (0, css_what_1.parse)(aliases_1.aliases[name], options);
var alias = (0, css_what_1.parse)(aliases_1.aliases[name]);
return subselects_1.subselects.is(next, alias, options, context, compileToken);

@@ -40,0 +40,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var css_what_1 = require("css-what");
var procedure_1 = require("./procedure");

@@ -39,3 +40,3 @@ var attributes = {

var proc = procedure_1.procedure[token.type];
if (token.type === "attribute") {
if (token.type === css_what_1.SelectorType.Attribute) {
proc = attributes[token.action];

@@ -54,3 +55,3 @@ if (proc === attributes.equals && token.name === "id") {

}
else if (token.type === "pseudo") {
else if (token.type === css_what_1.SelectorType.Pseudo) {
if (!token.data) {

@@ -57,0 +58,0 @@ proc = 3;

@@ -37,2 +37,6 @@ import type { Selector } from "css-what";

/**
* Returns the previous element sibling of a node.
*/
prevElementSibling?: (node: Node) => ElementNode | null;
/**
* Get the text content of the node, and its children if it has any.

@@ -88,2 +92,22 @@ */

/**
* Lower-case attribute names.
*
* @default !xmlMode
*/
lowerCaseAttributeNames?: boolean;
/**
* Lower-case tag names.
*
* @default !xmlMode
*/
lowerCaseTags?: boolean;
/**
* Is the document in quirks mode?
*
* This will lead to .className and #id being case-insensitive.
*
* @default false
*/
quirksMode?: boolean;
/**
* The last function in the stack, will be called with the last element

@@ -90,0 +114,0 @@ * that's looked at.

{
"name": "css-select",
"version": "4.2.1",
"version": "4.3.0",
"description": "a CSS selector compiler/engine",

@@ -25,4 +25,4 @@ "author": "Felix Boehm <me@feedic.com>",

"boolbase": "^1.0.0",
"css-what": "^5.1.0",
"domhandler": "^4.3.0",
"css-what": "^6.0.1",
"domhandler": "^4.3.1",
"domutils": "^2.8.0",

@@ -33,14 +33,14 @@ "nth-check": "^2.0.1"

"@types/boolbase": "^1.0.1",
"@types/jest": "^27.0.3",
"@types/node": "^17.0.4",
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"cheerio-soupselect": "^0.1.1",
"eslint": "^8.5.0",
"eslint-config-prettier": "^8.1.0",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"htmlparser2": "^7.2.0",
"jest": "^27.4.5",
"prettier": "^2.5.1",
"ts-jest": "^27.1.2",
"typescript": "^4.5.4"
"jest": "^27.5.1",
"prettier": "^2.6.1",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
},

@@ -47,0 +47,0 @@ "scripts": {

@@ -25,4 +25,4 @@ # css-select [![NPM version](http://img.shields.io/npm/v/css-select.svg)](https://npmjs.org/package/css-select) [![Build Status](https://travis-ci.com/fb55/css-select.svg?branch=master)](http://travis-ci.com/fb55/css-select) [![Downloads](https://img.shields.io/npm/dm/css-select.svg)](https://npmjs.org/package/css-select) [![Coverage](https://coveralls.io/repos/fb55/css-select/badge.svg?branch=master)](https://coveralls.io/r/fb55/css-select)

remaining selectors)
- ๐Ÿง‘โ€๐Ÿ”ฌ High test coverage, including the full test suites from Sizzle, Qwery
and NWMatcher.
- ๐Ÿง‘โ€๐Ÿ”ฌ High test coverage, including the full test suites from Sizzle, Qwery and
NWMatcher.
- ๐Ÿฅผ Reliably great performance

@@ -29,0 +29,0 @@

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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc