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

css-selector-tokenizer

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-selector-tokenizer - npm Package Compare versions

Comparing version 0.5.4 to 0.6.0

0

lib/index.js

@@ -0,0 +0,0 @@ exports.parse = require("./parse");

32

lib/parse.js
"use strict";
var Parser = require("fastparse");
var regexpu = require("regexpu-core");

@@ -167,7 +168,15 @@ function unescape(str) {

var parser = new Parser({
selector: {
"/\\*([\\s\\S]*?)\\*/": commentMatch,
"\\.((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": typeMatch("class"),
"#((?:\\\\.|[A-Za-z_\\-])(?:\\\\.|[A-Za-z_\\-0-9])*)": typeMatch("id"),
function getSelectors() {
// The assignment here is split to preserve the property enumeration order.
var selectors = {
"/\\*([\\s\\S]*?)\\*/": commentMatch
};
// https://www.w3.org/TR/CSS21/syndata.html#characters
// 4.1.3: identifiers (...) can contain only the characters [a-zA-Z0-9] and
// ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_)
//
// 10ffff is the maximum allowed in current Unicode
selectors[regexpu("\\.((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)", "u")] = typeMatch("class");
selectors[regexpu("#((?:\\\\.|[A-Za-z_\\-\\u{00a0}-\\u{10ffff}])(?:\\\\.|[A-Za-z_\\-0-9\\u{00a0}-\\u{10ffff}])*)", "u")] = typeMatch("id");
var selectorsSecondHalf = {
":(not|matches|has|local|global)\\((\\s*)": nestedPseudoClassStartMatch,

@@ -189,3 +198,14 @@ ":((?:\\\\.|[A-Za-z_\\-0-9])+)\\(": pseudoClassStartMatch,

".": invalidMatch
},
};
var selector;
for (selector in selectorsSecondHalf) {
if (Object.prototype.hasOwnProperty.call(selectorsSecondHalf, selector)) {
selectors[selector] = selectorsSecondHalf[selector];
}
}
return selectors;
}
var parser = new Parser({
selector: getSelectors(),
inBrackets: {

@@ -192,0 +212,0 @@ "/\\*[\\s\\S]*?\\*/": addToCurrent,

20

lib/parseValues.js

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

function unescapeString(content) {
return content.replace(/\\([a-fA-F0-9]{2,5}|.)/g, function(escaped) {
if(escaped.length > 2) {
var C = parseInt(escaped.substr(1), 16);
if(C < 0x10000) {
return String.fromCharCode(C);
} else {
return String.fromCharCode(Math.floor((C - 0x10000) / 0x400) + 0xD800) +
String.fromCharCode((C - 0x10000) % 0x400 + 0xDC00);
}
return content.replace(/\\(?:([a-fA-F0-9]{1,6})|(.))/g, function(all, unicode, otherCharacter) {
if (otherCharacter) {
return otherCharacter;
}
var C = parseInt(unicode, 16);
if(C < 0x10000) {
return String.fromCharCode(C);
} else {
return escaped.substr(1);
return String.fromCharCode(Math.floor((C - 0x10000) / 0x400) + 0xD800) +
String.fromCharCode((C - 0x10000) % 0x400 + 0xDC00);
}

@@ -39,0 +39,0 @@ });

@@ -5,7 +5,17 @@ "use strict";

function escape(str) {
var regexpu = require("regexpu-core");
var identifierEscapeRegexp = new RegExp(
regexpu("(^[^A-Za-z_\\-\\u{00a0}-\\u{10ffff}]|^\\-\\-|[^A-Za-z_0-9\\-\\u{00a0}-\\u{10ffff}])", "ug"),
"g"
);
function escape(str, identifier) {
if(str === "*") {
return "*";
}
return str.replace(/(^[^A-Za-z_\\-]|^\-\-|[^A-Za-z_0-9\\-])/g, "\\$1");
if (identifier) {
return str.replace(identifierEscapeRegexp, "\\$1");
} else {
return str.replace(/(^[^A-Za-z_\\-]|^\-\-|[^A-Za-z_0-9\\-])/g, "\\$1");
}
}

@@ -22,5 +32,5 @@

case "class":
return "." + escape(tree.name);
return "." + escape(tree.name, true);
case "id":
return "#" + escape(tree.name);
return "#" + escape(tree.name, true);
case "attribute":

@@ -27,0 +37,0 @@ return "[" + tree.content + "]";

@@ -0,0 +0,0 @@ "use strict";

{
"name": "css-selector-tokenizer",
"version": "0.5.4",
"version": "0.6.0",
"description": "Parses and stringifies CSS selectors",

@@ -35,3 +35,4 @@ "main": "lib/index.js",

"cssesc": "^0.1.0",
"fastparse": "^1.1.1"
"fastparse": "^1.1.1",
"regexpu-core": "^1.0.0"
},

@@ -38,0 +39,0 @@ "devDependencies": {

@@ -0,0 +0,0 @@ # CSS Modules: CSS selector Tokenizer

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