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

unist-util-select

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-select - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

5

index.js

@@ -6,6 +6,11 @@ 'use strict';

var debug = require('debug')('unist-util-select');
module.exports = function (ast, selector) {
debug('Selector: %j', selector);
selector = parseSelector(selector);
debug('AST: %s',
JSON.stringify(selector, null, 2).replace(/(^|\n)/g, '\n '));
return selector ? select[selector.type](selector, ast) : [];
};

22

lib/select.js

@@ -81,9 +81,10 @@ 'use strict';

function matches (rule, node) {
var match = true;
// Match type.
if (rule.tagName && rule.tagName != '*' && node.type != rule.tagName) {
return false;
}
match = match && (!rule.tagName || rule.tagName == '*' ||
rule.tagName == node.type);
// Match attributes.
return (rule.attrs || []).every(function (attr) {
match = match && (rule.attrs || []).every(function (attr) {
switch (attr.operator) {

@@ -126,2 +127,15 @@ case undefined:

});
// Match pseudo classes.
match = match && (rule.pseudos || []).every(function (pseudo) {
switch (pseudo.name) {
case 'not':
return !matches(pseudo.value.rule, node);
default:
throw Error('Undefined pseudo-class: ' + pseudo.name);
}
});
return match;
}

@@ -128,0 +142,0 @@

@@ -10,3 +10,4 @@ 'use strict';

parser.registerAttrEqualityMods('^', '*', '$');
parser.registerSelectorPseudos('not');
return parser.parse.bind(parser);
};

5

package.json
{
"name": "unist-util-select",
"version": "1.0.0",
"version": "1.1.0",
"description": "Select unist nodes using css-like selectors",

@@ -43,3 +43,4 @@ "author": "Eugene Sharygin <eush77@gmail.com>",

"dependencies": {
"css-selector-parser": "^1.1.0"
"css-selector-parser": "^1.1.0",
"debug": "^2.2.0"
},

@@ -46,0 +47,0 @@ "devDependencies": {

@@ -62,2 +62,3 @@ [![npm](https://nodei.co/npm/unist-util-select.png)](https://npmjs.com/package/unist-util-select)

- [x] Ends with: `[value$="suffix"]`
- [x] Negation pseudo-class: `*:not(paragraph)`

@@ -64,0 +65,0 @@ ## API

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