unist-util-select
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -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) : []; | ||
}; |
@@ -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); | ||
}; |
{ | ||
"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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8159
138
79
2
+ Addeddebug@^2.2.0
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)