Socket
Socket
Sign inDemoInstall

nwsapi

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nwsapi - npm Package Compare versions

Comparing version 2.0.7 to 2.0.8

dist/lint.log

2

package.json
{
"name": "nwsapi",
"version": "2.0.7",
"version": "2.0.8",
"description": "Fast CSS Selectors API Engine",

@@ -5,0 +5,0 @@ "homepage": "http://javascript.nwbox.com/nwsapi/",

@@ -8,5 +8,5 @@ /*

* Author: Diego Perini <diego.perini at gmail com>
* Version: 2.0.7
* Version: 2.0.8
* Created: 20070722
* Release: 20180719
* Release: 20180727
*

@@ -34,3 +34,3 @@ * License:

var version = 'nwsapi-2.0.6',
var version = 'nwsapi-2.0.8',

@@ -57,23 +57,23 @@ doc = global.document,

reOptimizer,
reSimpleNot,
reValidator,
struct_1 = '(root|empty|(?:(?:first|last|only)(?:-child|-of-type)))\\b',
struct_2 = '(nth(?:-last)?(?:-child|-of-type))(?:\\(\\s?(even|odd|(?:[-+]?\\d*)(?:n[-+]?\\d*)?)\\s?(?:\\)|$))',
struct_1 = '(?:root|empty|scope)|(?:(?:first|last|only)(?:-child|-of-type))',
struct_2 = '(?:nth(?:-last)?(?:-child|-of-type))',
pseudo_1 = 'any-link|link|visited|target|active|focus|hover',
pseudo_2 = 'checked|disabled|enabled|selected|local-link(?:\\(\\d*(?:\\)|$))?|lang\\(([-\\w]{2,})(?:\\)|$)',
pseudo_3 = 'default|indeterminate|optional|required|valid|invalid|in-range|out-of-range|read-only|read-write|placeholder-shown',
pseudo_4 = 'after|before|first-letter|first-line',
pseudo_5 = 'selection|backdrop|placeholder',
params_1 = '(?:\\(\\s?(even|odd|(?:[-+]?\\d*)(?:n[-+]?\\d*)?)\\s?(?:\\)|$))',
negation = '|(?:matches|not)\\(\\s?(:' + struct_2 + params_1 + '|[^()]*|[^\\(]*\\([^\\)]*\\))\\s?(?:\\)|$)',
pseudo_1 = '(dir|lang)\\x28\\s?([-\\w]{2,})\\s?(?:\\x29|$)',
pseudo_2 = ':?(after|before|first-letter|first-line|selection|backdrop|placeholder)\\b',
noparm_1 = '(link|visited|target|scope|hover|active|focus|enabled|disabled|read-only|read-write|placeholder-shown)\\b',
noparm_2 = '(default|checked|indeterminate|required|optional|valid|invalid|in-range|out-of-range)\\b',
logicals = '(matches|not)\\x28\\s?([^()]*|[^\\x28]*\\x28[^\\x29]*\\x29)\\s?(?:\\x29|$)',
Patterns = {
struct_n: RegExp('^:(' + struct_1 + ')?(.*)', 'i'),
struct_p: RegExp('^:(' + struct_2 + params_1 + ')?(.*)', 'i'),
spseudos: RegExp('^:(' + struct_1 + '|' + struct_2 + params_1 + ')?(.*)', 'i'),
dpseudos: RegExp('^:(' + pseudo_1 + '|' + pseudo_2 + negation + ')?(.*)', 'i'),
epseudos: RegExp('^:(:?(?:' + pseudo_4 + ')|:(?:' + pseudo_5 + '))?(.*)', 'i'),
hpseudos: RegExp('^:(' + pseudo_3 + ')?(.*)', 'i'),
// pseudo-classes
struct_n: RegExp('^:(?:' + struct_1 + ')(.*)', 'i'),
struct_p: RegExp('^:(?:' + struct_2 + ')(.*)', 'i'),
hpseudos: RegExp('^:(?:' + pseudo_1 + ')(.*)', 'i'),
epseudos: RegExp('^:(?:' + pseudo_2 + ')(.*)', 'i'),
lpseudos: RegExp('^:(?:' + logicals + ')(.*)', 'i'),
fpseudos: RegExp('^:(?:' + noparm_1 + ')(.*)', 'i'),
ipseudos: RegExp('^:(?:' + noparm_2 + ')(.*)', 'i'),
// combinators symbols
children: RegExp('^' + WSP + '?\\>' + WSP + '?(.*)'),

@@ -83,2 +83,3 @@ adjacent: RegExp('^' + WSP + '?\\+' + WSP + '?(.*)'),

ancestor: RegExp('^' + WSP + '+(.*)'),
// universal & namespace
universal: RegExp('^\\*(.*)'),

@@ -88,5 +89,17 @@ namespace: RegExp('^(\\w+|\\*)?\\|(.*)')

// regexp to aproximate detection of RTL languages (Arabic)
RTL = RegExp('^[\\u0591-\\u08ff\\ufb1d-\\ufdfd\\ufe70-\\ufefc ]+$'),
// emulate firefox error strings
qsNotArgs = 'Not enough arguments',
qsInvalid = ' is not a valid selector',
// detect structural pseudo-classes in selectors
reNthElem = RegExp('(:nth(?:-last)?-child)', 'i'),
reNthType = RegExp('(:nth(?:-last)?-of-type)', 'i'),
// placeholder for global regexp
reOptimizer, reSimpleNot, reValidator,
// special handling configuration flags
Config = {

@@ -745,3 +758,3 @@

// build conditional code to check components of selector strings
// build code to check components of selector strings
compileSelector =

@@ -752,4 +765,4 @@ function(expression, source, mode, callback, not) {

// D is the default inverted negation flag
var a, b, n, f, name, x_error = '', NS,
N = not ? '!' : '', D = not ? '' : '!', pseudo,
var a, b, n, f, name, NS,
N = not ? '!' : '', D = not ? '' : '!',
compat, expr, match, result, status, symbol, test,

@@ -808,3 +821,3 @@ type, selector = expression, selector_string, vars;

} else {
emit('\'' + selector_string + '\' is not a valid selector');
emit('\'' + selector_string + '\'' + qsInvalid);
}

@@ -820,3 +833,3 @@ break;

if (match[2] && !(test = Operators[match[2]])) {
emit('unsupported operator in attribute selector \'' + selector + '\'');
emit('\'' + selector_string + '\'' + qsInvalid);
return '';

@@ -875,14 +888,10 @@ }

// *** Structural pseudo-classes
// :root, :scope, :empty,
// *** tree-structural pseudo-classes
// :root, :empty
// :first-child, :last-child, :only-child,
// :first-of-type, :last-of-type, :only-of-type,
// :nth-child(), :nth-last-child(), :nth-of-type(), :nth-last-of-type()
case ':':
if ((match = selector.match(Patterns.struct_n)) && match[1]) {
pseudo = match[1].match(/^[-\w]+/)[0].toLowerCase();
switch (pseudo) {
case 'scope':
source = 'if((s.from.compareDocumentPosition(e)&20)==20){' + source + '}';
break;
if ((match = selector.match(Patterns.struct_n))) {
match[1] = match[1].toLowerCase();
switch (match[1]) {
case 'root':

@@ -893,4 +902,8 @@ // there can only be one :root element, so exit the loop once found

case 'empty':
// matches elements that don't contain elements or text nodes
source = 'n=e.firstChild;while(n&&!(/1|3/).test(n.nodeType)){n=n.nextSibling}if(' + D + 'n){' + source + '}';
break;
// *** child-indexed pseudo-classes
// :first-child, :last-child, :only-child
case 'only-child':

@@ -905,2 +918,5 @@ source = 'if(' + N + '(!e.nextElementSibling&&!e.previousElementSibling)){' + source + '}';

break;
// *** typed child-indexed pseudo-classes
// :only-of-type, :last-of-type, :first-of-type
case 'only-of-type':

@@ -918,3 +934,3 @@ source = 'o=e.nodeName;' +

default:
emit('\'' + selector_string + '\' is not a valid selector' + x_error);
emit('\'' + selector_string + '\'' + qsInvalid);
break;

@@ -924,5 +940,8 @@ }

else if ((match = selector.match(Patterns.struct_p)) && match[1]) {
pseudo = match[1].match(/^[-\w]+/)[0].toLowerCase();
switch (pseudo) {
// *** child-indexed & typed child-indexed pseudo-classes
// :nth-child, :nth-of-type, :nth-last-child, :nth-last-of-type
// 4 cases: 1 (nth) x 4 (child, of-type, last-child, last-of-type)
else if ((match = selector.match(Patterns.struct_p))) {
match[1] = match[1].toLowerCase();
switch (match[1]) {
case 'nth-child':

@@ -932,3 +951,2 @@ case 'nth-of-type':

case 'nth-last-of-type':
// 4 cases: 1 (nth) x 4 (child, of-type, last-child, last-of-type)
expr = /-of-type/i.test(match[1]);

@@ -967,7 +985,7 @@ if (match[1] && match[2]) {

} else {
emit('\'' + selector_string + '\' is not a valid selector' + x_error);
emit('\'' + selector_string + '\'' + qsInvalid);
}
break;
default:
emit('\'' + selector_string + '\' is not a valid selector' + x_error);
emit('\'' + selector_string + '\'' + qsInvalid);
break;

@@ -977,42 +995,56 @@ }

else if ((match = selector.match(Patterns.dpseudos)) && match[1]) {
pseudo = match[1].match(/^[-\w]+/)[0].toLowerCase();
switch (pseudo) {
// *** logical combination pseudo-classes
// :matches( s1, [ s2, ... ]), :not( s1, [ s2, ... ])
else if ((match = selector.match(Patterns.lpseudos))) {
match[1] = match[1].toLowerCase();
switch (match[1]) {
case 'matches':
expr = match[3].replace(REX.TrimSpaces, '');
expr = match[2].replace(REX.TrimSpaces, '');
source = 'if(s.match("' + expr.replace(/\x22/g, '\\"') + '",e,f)){' + source + '}';
break;
case 'not':
if (Config.SIMPLENOT && !reSimpleNot.test(match[3])) {
emit('\'' + selector + '\' is not a valid selector');
if (Config.SIMPLENOT && !reSimpleNot.test(match[2])) {
emit('\'' + selector_string + '\'' + qsInvalid);
return '';
}
expr = match[3].replace(REX.TrimSpaces, '');
expr = match[2].replace(REX.TrimSpaces, '');
source = compileSelector(expr, source, false, callback, true);
break;
case 'checked':
source = 'if(' + N + '(/^input$/i.test(e.nodeName)&&' +
'("|radio|checkbox|".includes("|"+e.type+"|")&&e.checked)||' +
'(/^option$/i.test(e.nodeName)&&(e.selected||e.checked))' +
')){' + source + '}';
default:
emit('\'' + selector_string + '\'' + qsInvalid);
break;
case 'disabled':
// https://www.w3.org/TR/html5/forms.html#enabling-and-disabling-form-controls:-the-disabled-attribute
source = 'if(' + N + '(("form" in e||/^optgroup$/i.test(e.nodeName))&&"disabled" in e&&' +
'(e.disabled===true||(n=s.ancestor("fieldset",e))&&(n=s.first("legend",n))&&!n.contains(e))' +
')){' + source + '}';
}
}
// *** linguistic pseudo-classes
// :dir( ltr / rtl ), :lang( en )
else if ((match = selector.match(Patterns.hpseudos))) {
match[1] = match[1].toLowerCase();
switch (match[1]) {
case 'dir':
source = 'var p;if(' + N + '(' +
'(/' + match[2] + '/i.test(e.dir))||(p=s.ancestor("[dir]", e))&&' +
'(/' + match[2] + '/i.test(p.dir))||(e.dir==""||e.dir=="auto")&&' +
'(' + (match[2] == 'ltr' ? '!':'')+ RTL +'.test(e.textContent)))' +
'){' + source + '};';
break;
case 'enabled':
source = 'if(' + N + '(("form" in e||/^optgroup$/i.test(e.nodeName))&&"disabled" in e &&e.disabled===false' +
')){' + source + '}';
break;
case 'lang':
source = 'var p=null;if(' + N + '(e.isConnected&&(e.lang==""&&' +
'(p=s.ancestor("[lang]",e))&&p.lang=="' + match[2] + '")||' +
'/(?:^|-)' + match[2] + '(?:-|$)/i.test(e.lang))' +
expr = '(?:^|-)' + match[2] + '(?:-|$)';
source = 'var p;if(' + N + '(' +
'(e.isConnected&&(e.lang==""&&(p=s.ancestor("[lang]",e)))&&' +
'(p.lang=="' + match[2] + '")||/'+ expr +'/i.test(e.lang)))' +
'){' + source + '};';
break;
case 'target':
source = 'if(' + N + '((s.doc.compareDocumentPosition(e)&16)&&s.doc.location.hash&&e.id==s.doc.location.hash.slice(1))){' + source + '}';
default:
emit('\'' + selector_string + '\'' + qsInvalid);
break;
}
}
// *** location, user actiond and input pseudo-classes
else if ((match = selector.match(Patterns.fpseudos))) {
match[1] = match[1].toLowerCase();
switch (match[1]) {
// *** location pseudo-classes
// :link, :visited, :target, :scope
case 'link':

@@ -1024,8 +1056,21 @@ source = 'if(' + N + '(/^a|area|link$/i.test(e.nodeName)&&e.hasAttribute("href"))){' + source + '}';

break;
case 'active':
source = 'hasFocus' in doc && doc.hasFocus() ? 'if(' + N + '(e===s.doc.activeElement)){' + source + '}' : source;
case 'target':
source = 'if(' + N + '((s.doc.compareDocumentPosition(e)&16)&&s.doc.location.hash&&e.id==s.doc.location.hash.slice(1))){' + source + '}';
break;
case 'scope':
source = 'if((s.from.compareDocumentPosition(e)&20)==20){' + source + '}';
break;
// *** user actions pseudo-classes
// :hover, :active, :focus
case 'hover':
source = 'hasFocus' in doc && doc.hasFocus() ? 'if(' + N + '(e===s.doc.hoverElement)){' + source + '}' : source;
source = 'hasFocus' in doc && doc.hasFocus() ?
'if(' + N + '(e===s.doc.hoverElement)){' + source + '}' :
'if(' + D + 'true){' + source + '}';
break;
case 'active':
source = 'hasFocus' in doc && doc.hasFocus() ?
'if(' + N + '(e===s.doc.activeElement)){' + source + '}' :
'if(' + D + 'true){' + source + '}';
break;
case 'focus':

@@ -1036,7 +1081,40 @@ source = 'hasFocus' in doc ?

break;
case 'selected':
source = 'if(' + N + '(/^option$/i.test(e.nodeName)&&(e.selected||e.checked))){' + source + '}';
// *** user interface and form pseudo-classes
// :enabled, :disabled, :read-only, :read-write, :placeholder-shown
case 'enabled':
source = 'if(' + N + '(("form" in e||/^optgroup$/i.test(e.nodeName))&&"disabled" in e &&e.disabled===false' +
')){' + source + '}';
break;
case 'disabled':
// https://www.w3.org/TR/html5/forms.html#enabling-and-disabling-form-controls:-the-disabled-attribute
source = 'if(' + N + '(("form" in e||/^optgroup$/i.test(e.nodeName))&&"disabled" in e&&' +
'(e.disabled===true||(n=s.ancestor("fieldset",e))&&(n=s.first("legend",n))&&!n.contains(e))' +
')){' + source + '}';
break;
case 'read-only':
source =
'if(' + N + '(' +
'(/^textarea$/i.test(e.nodeName)&&(e.readOnly||e.disabled))||' +
'("|password|text|".includes("|"+e.type+"|")&&e.readOnly)' +
')){' + source + '}';
break;
case 'read-write':
source =
'if(' + N + '(' +
'((/^textarea$/i.test(e.nodeName)&&!e.readOnly&&!e.disabled)||' +
'("|password|text|".includes("|"+e.type+"|")&&!e.readOnly&&!e.disabled))||' +
'(e.hasAttribute("contenteditable")||(s.doc.designMode=="on"))' +
')){' + source + '}';
break;
case 'placeholder-shown':
source =
'if(' + N + '(' +
'(/^input|textarea$/i.test(e.nodeName))&&e.hasAttribute("placeholder")&&' +
'("|textarea|password|number|search|email|text|tel|url|".includes("|"+e.type+"|"))&&' +
'(!s.match(":focus",e))' +
')){' + source + '}';
break;
default:
emit('\'' + selector_string + '\' is not a valid selector' + x_error);
emit('\'' + selector_string + '\'' + qsInvalid);
break;

@@ -1046,6 +1124,8 @@ }

// Level 4 pseudo-classes for form validation (was web-forms)
else if ((match = selector.match(Patterns.hpseudos)) && match[1]) {
pseudo = match[1].match(/^[-\w]+/)[0].toLowerCase();
switch (pseudo) {
// *** input pseudo-classes for form validation (was web-forms)
// :default, :checked, :indeterminate, :valid, :invalid
// :in-range, :out-of-range, :required, :optional
else if ((match = selector.match(Patterns.ipseudos))) {
match[1] = match[1].toLowerCase();
switch (match[1]) {
case 'default':

@@ -1068,2 +1148,8 @@ source =

break;
case 'checked':
source = 'if(' + N + '(/^input$/i.test(e.nodeName)&&' +
'("|radio|checkbox|".includes("|"+e.type+"|")&&e.checked)||' +
'(/^option$/i.test(e.nodeName)&&(e.selected||e.checked))' +
')){' + source + '}';
break;
case 'indeterminate':

@@ -1076,29 +1162,14 @@ source =

break;
case 'optional':
case 'required':
source =
'if(' + N +
'(/^input|select|textarea$/i.test(e.nodeName)&&!e.required)' +
'(/^input|select|textarea$/i.test(e.nodeName)&&e.required)' +
'){' + source + '}';
break;
case 'required':
case 'optional':
source =
'if(' + N +
'(/^input|select|textarea$/i.test(e.nodeName)&&e.required)' +
'(/^input|select|textarea$/i.test(e.nodeName)&&!e.required)' +
'){' + source + '}';
break;
case 'read-write':
source =
'if(' + N + '(' +
'((/^textarea$/i.test(e.nodeName)&&!e.readOnly&&!e.disabled)||' +
'("|password|text|".includes("|"+e.type+"|")&&!e.readOnly&&!e.disabled))||' +
'(e.hasAttribute("contenteditable")||(s.doc.designMode=="on"))' +
')){' + source + '}';
break;
case 'read-only':
source =
'if(' + N + '(' +
'(/^textarea$/i.test(e.nodeName)&&(e.readOnly||e.disabled))||' +
'("|password|text|".includes("|"+e.type+"|")&&e.readOnly)' +
')){' + source + '}';
break;
case 'invalid':

@@ -1140,12 +1211,5 @@ source =

break;
case 'placeholder-shown':
source =
'if(' + N + '(' +
'(/^input|textarea$/i.test(e.nodeName))&&e.hasAttribute("placeholder")&&' +
'("|textarea|password|number|search|email|text|tel|url|".includes("|"+e.type+"|"))&&' +
'(!s.match(":focus",e))' +
')){' + source + '}';
break;
default:
emit('\'' + selector_string + '\' is not a valid selector' + x_error);
emit('\'' + selector_string + '\'' + qsInvalid);
break;

@@ -1156,3 +1220,3 @@ }

// allow pseudo-elements as :after/:before (single or double colon)
else if ((match = selector.match(Patterns.epseudos)) && match[1]) {
else if ((match = selector.match(Patterns.epseudos))) {
source = 'if(' + D + '(/1|11/).test(e.nodeType)){' + source + '}';

@@ -1169,3 +1233,3 @@ }

for (expr in Selectors) {
if ((match = selector.match(Selectors[expr].Expression)) && match[1]) {
if ((match = selector.match(Selectors[expr].Expression))) {
result = Selectors[expr].Callback(match, source, mode, callback);

@@ -1204,3 +1268,3 @@ if ('match' in result) { match = result.match; }

default:
emit('\'' + selector_string + '\' is not a valid selector' + x_error);
emit('\'' + selector_string + '\'' + qsInvalid);
break;

@@ -1212,3 +1276,3 @@

if (!match) {
emit('\'' + selector_string + '\' is not a valid selector' + x_error);
emit('\'' + selector_string + '\'' + qsInvalid);
return '';

@@ -1263,6 +1327,6 @@ }

if (arguments.length === 0) {
emit('not enough arguments', TypeError);
emit(qsNotArgs, TypeError);
return Config.VERBOSITY ? undefined : false;
} else if (arguments[1] === '') {
emit('\'\' is not a valid selector');
emit('\'\'' + qsInvalid);
return Config.VERBOSITY ? undefined : false;

@@ -1285,7 +1349,7 @@ }

if (groups.indexOf('') > -1) {
emit('invalid or illegal string specified');
emit(qsInvalid);
return Config.VERBOSITY ? undefined : false;
}
} else {
emit('\'' + selector + '\' is not a valid selector');
emit('\'' + selector + '\'' + qsInvalid);
return Config.VERBOSITY ? undefined : false;

@@ -1305,3 +1369,3 @@ }

if (arguments.length === 0) {
emit('not enough arguments', TypeError);
emit(qsNotArgs, TypeError);
}

@@ -1342,6 +1406,6 @@ return select(selector, context,

if (arguments.length === 0) {
emit('not enough arguments', TypeError);
emit(qsNotArgs, TypeError);
return Config.VERBOSITY ? undefined : none;
} else if (arguments[0] === '') {
emit('\'\' is not a valid selector');
emit('\'\'' + qsInvalid);
return Config.VERBOSITY ? undefined : none;

@@ -1366,7 +1430,7 @@ } else if (lastContext !== context) {

if (groups.indexOf('') > -1) {
emit('invalid or illegal string specified');
emit(qsInvalid);
return Config.VERBOSITY ? undefined : none;
}
} else {
emit('\'' + selector + '\' is not a valid selector');
emit('\'' + selector + '\'' + qsInvalid);
return Config.VERBOSITY ? undefined : none;

@@ -1373,0 +1437,0 @@ }

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