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.5.0 to 1.6.0

33

helpers.js

@@ -81,8 +81,20 @@ 'use strict';

.replace(patt, (_, name, data) => {
const handler = pseudos[name];
const handlerIsFn = typeof handler === 'function';
data = typeof data === 'string'
? restore(data.trim())
? data.trim()
: undefined;
return typeof handler === 'function'
? handler(data)
let args = [];
if (data) {
args = (handlerIsFn && handler.length > 1
? data.split(/\s*,\s*/)
: [data])
.map(restore);
}
return handlerIsFn
? handler(...args)
: handler;

@@ -140,2 +152,17 @@ });

self.quotedString = str => {
const single = "'";
const double = '"';
const strip = /^["']|["']$/g;
if (
(str.startsWith(single) && str.endsWith(single))
|| (str.startsWith(double) && str.endsWith(double))
) {
str = str.replace(strip, '');
}
return `"${str.replace(/"/g, '"')}"`;
};
const literalCapture = string => {

@@ -142,0 +169,0 @@ const literals = [];

7

index.js
'use strict';
const {tokenStreams, decorateToken, translateCaseMap,
arrayFilterUnique, applyCustomPsuedos} = require('./helpers');
arrayFilterUnique, applyCustomPsuedos, quotedString} = require('./helpers');

@@ -56,3 +56,6 @@ const self = module.exports = function cssToXPath(css, {pseudos}={}) {

self.applyCustomPsuedos = applyCustomPsuedos;
Object.assign(self, {
applyCustomPsuedos,
quotedString,
});

@@ -59,0 +62,0 @@ function xpathExpression(tokens) {

{
"name": "csstoxpath",
"version": "1.5.0",
"version": "1.6.0",
"description": "CSS to XPath",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -274,2 +274,4 @@ 'use strict';

const {quotedString} = cssToXpath;
const pseudos = {

@@ -296,2 +298,6 @@

// Parse as multiple arguments if handler specifies them.
link: (text, href) => `a${href ? `[href="${href}"]` : ''}:text(${quotedString(text)})`,
link2: text => `a:text(${quotedString(text)})`,
// Regexes.

@@ -357,2 +363,14 @@ [/custom-(?<position>\d+)(-(?<type>heading|link))?/](data, matches) {

]],
[':link(Some text, https://link.com)', [
`a[href="https://link.com"]:text("Some text")`,
`//a[(@href = 'https://link.com') and (translate(normalize-space(), 'SOMETX', 'sometx') = "some text")]`,
]],
[':link("Some, text, with, commas", https://link.com)', [
`a[href="https://link.com"]:text("Some, text, with, commas")`,
`//a[(@href = 'https://link.com') and (translate(normalize-space(), 'SOMETXWIHCA', 'sometxwihca') = "some, text, with, commas")]`,
]],
[':link2(Some text, but no link)', [
`a:text("Some text, but no link")`,
`//a[translate(normalize-space(), 'SOMETXBUNLIK', 'sometxbunlik') = "some text, but no link"]`,
]],
[':custom-1-heading', [

@@ -359,0 +377,0 @@ 'element:nth-of-type(1) > h1',

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