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

csstoxpath

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csstoxpath - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

27

index.js

@@ -100,2 +100,5 @@ const parser = require('css-what');

}
else if (token.isPseudoAny) {
filters.push(cssToXPath.subExpression(data));
}
else if (token.isPseudoComment) {

@@ -134,7 +137,9 @@ if (! previous.isAxis) {

let elements = [];
let {name, value, action, data} = token;
if (token.isTag) {
elements.push(`name() = '${token.name}'`);
let {az, AZ} = translateCaseMap(name);
elements.push(`translate(name(), '${az}', '${AZ}') = '${name.toUpperCase()}'`);
}
else if (token.isAttribute) {
let {name, value, action} = token;
switch (action) {

@@ -175,3 +180,2 @@ case 'exists':

else if (token.isPseudo) {
let {name, data} = token;
switch (name) {

@@ -190,2 +194,5 @@ case 'empty':

break;
case 'not':
elements.push(`not(${subExpression(data, {operator: 'or'})})`);
break;
case 'nth-child': {

@@ -241,4 +248,4 @@ let aliases = {

if (! /case/.test(name)) {
let abc = 'abcdefghijklmnopqrstuvwxyz';
text = `translate(normalize-space(), '${abc.toUpperCase()}', '${abc}')`;
let {az, AZ} = translateCaseMap(searchText);
text = az ? `translate(normalize-space(), '${AZ}', '${az}')` : `normalize-space()`;
searchText = searchText.toLowerCase();

@@ -303,4 +310,14 @@ }

function translateCaseMap(str) {
const letters = str
.toLowerCase()
// ISO/IEC 8859-15 (+ greek) lowercase letters.
.replace(/[^a-z\u0161\u017E\u0153\u00E0-\u00FF\u03AC-\u03CE]/g, '')
.split('');
const az = arrayUnique(letters).join('');
return {az, AZ: az.toUpperCase()};
}
function arrayUnique(arr) {
return arr.filter((v, i, a) => a.indexOf(v) === i);
}

5

package.json
{
"name": "csstoxpath",
"version": "1.1.1",
"version": "1.2.0",
"description": "CSS to XPath",
"main": "index.js",
"scripts": {
"test": "mocha test"
"test": "mocha test",
"lint": "eslint --fix ."
},

@@ -9,0 +10,0 @@ "repository": {

@@ -28,2 +28,8 @@ [![Build Status](https://travis-ci.org/peteboere/csstoxpath.svg?branch=master)](https://travis-ci.org/peteboere/csstoxpath)

#### `:any`
Selectors containing multiple options, any one of which will be matched:
E.g: `div :any(ol, ul, dl) > *` equates to `div ol > *, div ul > *, div dl > *`
#### `:comment`

@@ -38,3 +44,3 @@

* `:childless` As `:empty` but ignoring whitespace
As `:empty` but ignoring whitespace.

@@ -41,0 +47,0 @@

@@ -30,3 +30,3 @@ /* global describe it */

['.a + b',
`//*[@class and contains(concat(' ', normalize-space(@class), ' '), ' a ')]/following-sibling::*[(name() = 'b') and (position() = 1)]`
`//*[@class and contains(concat(' ', normalize-space(@class), ' '), ' a ')]/following-sibling::*[(translate(name(), 'b', 'B') = 'B') and (position() = 1)]`
],

@@ -37,3 +37,3 @@ ['.a + .b',

['.a + b.b',
`//*[@class and contains(concat(' ', normalize-space(@class), ' '), ' a ')]/following-sibling::*[(name() = 'b') and (position() = 1) and @class and contains(concat(' ', normalize-space(@class), ' '), ' b ')]`
`//*[@class and contains(concat(' ', normalize-space(@class), ' '), ' a ')]/following-sibling::*[(translate(name(), 'b', 'B') = 'B') and (position() = 1) and @class and contains(concat(' ', normalize-space(@class), ' '), ' b ')]`
],

@@ -109,3 +109,3 @@

[':not(a.b[c]:first-child)',
`//*[not((name() = 'a') and @class and contains(concat(' ', normalize-space(@class), ' '), ' b ') and @c and (position() = 1))]`],
`//*[not((translate(name(), 'a', 'A') = 'A') and @class and contains(concat(' ', normalize-space(@class), ' '), ' b ') and @c and (position() = 1))]`],
[':not(:last-child)', `//*[not(position() = last())]`],

@@ -117,4 +117,7 @@ [':not(:nth-child(1n+2))', `//*[not(position() - 2 >= 0)]`],

':text',
[':text(" Foo Bar ")',
`//*[translate(normalize-space(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = "foo bar"]`],
[':text("CafÉ fØöBÄR")',
`//*[translate(normalize-space(), 'CAFÉØÖBÄR', 'caféøöbär') = "café føöbär"]`],
[':text("Μεγάλο λιπαρό ελληνικό γάμο")',
`//*[translate(normalize-space(), 'ΜΕΓΆΛΟΙΠΑΡΌΗΝΚ', 'μεγάλοιπαρόηνκ') = "μεγάλο λιπαρό ελληνικό γάμο"]`],
[':text("עבריתת")', `//*[normalize-space() = "עבריתת"]`],

@@ -126,3 +129,3 @@ ':text-case (case sensitive)',

[':text-contains("foo bar ")',
`//*[contains(translate(normalize-space(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), "foo bar")]`],
`//*[contains(translate(normalize-space(), 'FOBAR', 'fobar'), "foo bar")]`],

@@ -134,3 +137,3 @@ ':text-contains-case (case sensitive)',

[':text-start("foo bar")',
`//*[starts-with(translate(normalize-space(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), "foo bar")]`],
`//*[starts-with(translate(normalize-space(), 'FOBAR', 'fobar'), "foo bar")]`],

@@ -143,3 +146,3 @@ ':text-start-case (case sensitive)',

[':text-end("foo bar")',
`//*[substring(translate(normalize-space(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), string-length(translate(normalize-space(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))-6) = "foo bar"]`],
`//*[substring(translate(normalize-space(), 'FOBAR', 'fobar'), string-length(translate(normalize-space(), 'FOBAR', 'fobar'))-6) = "foo bar"]`],

@@ -150,2 +153,9 @@ ':text-end-case (case sensitive)',

':any',
[':any(a, b)', `//*[(translate(name(), 'a', 'A') = 'A') or (translate(name(), 'b', 'B') = 'B')]`],
['a :any(first-child[id], c) d',
`//a//*[((translate(name(), 'firstchld', 'FIRSTCHLD') = 'FIRST-CHILD') and @id) or (translate(name(), 'c', 'C') = 'C')]//d`],
['a > :any(b.b:not([c]), d.d) > e',
`//a/*[((translate(name(), 'b', 'B') = 'B') and @class and contains(concat(' ', normalize-space(@class), ' '), ' b ') and not(@c)) or ((translate(name(), 'd', 'D') = 'D') and @class and contains(concat(' ', normalize-space(@class), ' '), ' d '))]/e`],
'Unions',

@@ -163,6 +173,6 @@ ['a, b', `(//a|//b)`],

['a:comment(1):text("Foo")',
`//a/comment()[1][translate(normalize-space(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = "foo"]`],
`//a/comment()[1][translate(normalize-space(), 'FO', 'fo') = "foo"]`],
['a:comment(1):text-case("Foo")', `//a/comment()[1][normalize-space() = "Foo"]`],
['a:comment:text-contains("Foo")',
`//a/comment()[contains(translate(normalize-space(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), "foo")]`],
`//a/comment()[contains(translate(normalize-space(), 'FO', 'fo'), "foo")]`],
['a:comment:text-contains-case("Foo")', `//a/comment()[contains(normalize-space(), "Foo")]`]

@@ -201,7 +211,7 @@ ];

const samples = [
['a', `name() = 'a'`],
['a', `translate(name(), 'a', 'A') = 'A'`],
['.b', `@class and contains(concat(' ', normalize-space(@class), ' '), ' b ')`],
['a.b', `(name() = 'a') and @class and contains(concat(' ', normalize-space(@class), ' '), ' b ')`],
['a, b', `(name() = 'a') or (name() = 'b')`],
[':text("foo")', `translate(normalize-space(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = "foo"`]
['a.b', `(translate(name(), 'a', 'A') = 'A') and @class and contains(concat(' ', normalize-space(@class), ' '), ' b ')`],
['a, b', `(translate(name(), 'a', 'A') = 'A') or (translate(name(), 'b', 'B') = 'B')`],
[':text("foo")', `translate(normalize-space(), 'FO', 'fo') = "foo"`]
];

@@ -208,0 +218,0 @@ for (let [css, xpath] of samples) {

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