Socket
Socket
Sign inDemoInstall

nwsapi

Package Overview
Dependencies
0
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.0.1

3

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

@@ -20,2 +20,3 @@ "homepage": "http://javascript.nwbox.com/nwsapi/",

],
"license": "MIT",
"author": {

@@ -22,0 +23,0 @@ "name": "Diego Perini",

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

* Author: Diego Perini <diego.perini at gmail com>
* Version: 2.0.0
* Version: 2.0.1
* Created: 20070722
* Release: 20180517
* Release: 20180526
*

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

var version = 'nwsapi-2.0.0',
var version = 'nwsapi-2.0.1',

@@ -64,8 +64,8 @@ doc = global.document,

pseudo_1 = 'any-link|link|visited|target|active|focus|hover',
pseudo_2 = 'checked|disabled|enabled|selected|local-link(?:\\(\\d*\\))?|lang\\(([-\\w]{2,})\\)',
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?\\)',
params_1 = '(?:\\(\\s?(even|odd|(?:[-+]?\\d*n?)(?:[-+]?\\d+)?)\\s?(?:\\)|$))',
negation = '|(?:matches|not)\\(\\s?(:' + struct_2 + params_1 + '|[^()]*)\\s?(?:\\)|$)',

@@ -90,8 +90,10 @@ Patterns = {

// special handling flags
Config = {
BUGFIX_ID: true,
FASTCOMMA: true,
IDS_DUPES: true,
MIXEDCASE: true,
SVG_LCASE: true,
SIMPLENOT: true,

@@ -104,10 +106,7 @@ USE_HTML5: true,

MIXED_NS,
MIXEDCASE,
NAMESPACE,
QUIRKS_MODE,
HAS_DUPE_IDS,
HTML_DOCUMENT,
ATTR_ID = 'e.id',
ATTR_STD_OPS = {

@@ -117,4 +116,2 @@ '=': 1, '^=': 1, '$=': 1, '|=': 1, '*=': 1, '~=': 1

FIX_ID = '(typeof(e.id)=="string"?e.id:e.getAttribute("id"))',
HTML_TABLE = {

@@ -180,9 +177,8 @@ 'accept': 1, 'accept-charset': 1, 'align': 1, 'alink': 1, 'axis': 1,

// performed before the next select operation
HAS_DUPE_IDS = undefined;
root = doc.documentElement;
HTML_DOCUMENT = isHTML(doc);
MIXEDCASE = Config.MIXEDCASE;
QUIRKS_MODE = HTML_DOCUMENT &&
doc.compatMode.indexOf('CSS') < 0;
NAMESPACE = root && root.namespaceURI;
ATTR_ID = Config.BUGFIX_ID ? FIX_ID : 'e.id';
Snapshot.doc = doc;

@@ -298,3 +294,3 @@ Snapshot.root = root;

natives = mapped;
if (HAS_DUPE_IDS) natives['#'] = mapped['@'];
if (Config.IDS_DUPES) natives['#'] = mapped['@'];
delete natives['@'];

@@ -306,37 +302,2 @@ return natives;

// check context for duplicate Ids
hasDuplicateId =
function(context) {
var i = 0, e, r = Object();
e = byTag('*', context);
while (e[i]) {
if (e[i].id) {
if (!r[e[i].id]) {
r[e[i].id] = true;
} else return true;
}
++i;
}
return false;
},
// check context for mixed content
hasMixedNamespace =
function(context) {
var d = context.ownerDocument || context,
dns, all_nodes, dns_nodes;
if (root) {
// the root element namespace
dns = root.namespaceURI;
} else {
// default html/xhtml namespace
dns = 'http://www.w3.org/1999/xhtml';
}
// check to see if all nodes are in the same namespace
all_nodes = d.getElementsByTagNameNS('*', '*').length;
dns_nodes = d.getElementsByTagNameNS(dns, '*').length;
return all_nodes != dns_nodes;
},
// validate memoized HTMLCollections

@@ -363,20 +324,12 @@ validate =

// recursive DOM LTR traversal, configurable by replacing
// the conditional part (@) to accept returned elements
// the conditional part (@) that accept returned elements
walk =
'"use strict"; var i = 0, r = []; return function w(e) {' +
'if (@) { r[i] = e; ++i; } e = e.firstElementChild;' +
'while (e) { w(e); e = e.nextElementSibling; }' +
'return r; };',
'"use strict"; var i = 0, r = Array(); return function treewalk(e) {' +
'if (e.nodeType == 1 && @) { r[i++] = e; } e = e.firstElementChild;' +
'while (e) { treewalk(e); e = e.nextElementSibling; } return r; };',
// coditional tests to accept returned elements in the
// cross document methods: byId, byTag, byCls, byTagCls
idTest = 't.test(' + FIX_ID + ')',
tagMatch = 'a||t.test(e.nodeName)',
clsMatch = 'c.test(e.getAttribute?' +
'e.getAttribute("class"):e.className)',
// getElementById from context
byId =
function(ids, context) {
var element, elements, nIds = '', reIds, resolver;
var element, resolver, test, reIds;

@@ -386,4 +339,4 @@ if (typeof ids == 'string') { ids = [ ids ]; }

// if duplicates are disallowed use DOM API to collect the nodes
if (!HAS_DUPE_IDS && ids.length < 2 && method['#'] in context) {
element = context.getElementById(unescapeIdentifier(ids[0]));
if (!Config.IDS_DUPES && ids.length < 2 && method['#'] in context) {
element = context.getElementById(ids[0]);
return element ? [ element ] : none;

@@ -393,13 +346,12 @@ }

// multiple ids names
ids.map(function(e) { nIds += '|' + e.replace(REX.RegExpChar, '\\$&'); });
reIds = RegExp('^(?:' + nIds.slice(1) + ')$', 'i');
if (ids.length > 1) {
test = 't.test(e.getAttribute("id"))';
reIds = RegExp('^(?:' + ids.join('|') + ')$', 'i');
} else {
test = 'e.getAttribute("id")==t';
}
// for non-elements contexts start from first element child
context.nodeType != 1 && (context = context.firstElementChild);
// build the resolver and execute it
resolver = Function('t', walk.replace('@', idTest))(reIds);
elements = resolver(context);
return elements;
resolver = Function('t', walk.replace('@', test))(reIds || ids[0]);
return resolver(context);
},

@@ -412,3 +364,3 @@

function(tag, context) {
var elements, resolver, nTag = '', reTag, any;
var resolver, test, reTag;

@@ -419,20 +371,18 @@ if (typeof tag == 'string') { tag = [ tag ]; }

if (tag.length < 2 && method['*'] in context) {
return context[method['*'] + 'NS']('*', tag[0]);
return context[method['*']](tag[0]);
}
// multiple tag names
tag.map(function(e) {
if (e == '*') { any = true; }
else nTag += '|' + e.replace(REX.RegExpChar, '\\$&');
});
reTag = RegExp('^(?:' + nTag.slice(1) + ')$', 'i');
if (tag.includes('*')) {
test = 'true';
} else if (tag.length > 1) {
test = 't.test(e.nodeName)';
reTag = RegExp('^(?:' + tag.join('|') + ')$', 'i');
} else {
test = 'e.nodeName==t';
}
// build the resolver and execute it
resolver = Function('t, a', walk.replace('@', tagMatch))(reTag, any);
elements = resolver(context);
// remove possible non-element nodes from the collected nodes
if (elements[0] && elements[0].nodeType != 1) { elements.shift(); }
return elements;
resolver = Function('t', walk.replace('@', test))(reTag || tag[0]);
return resolver(context);
},

@@ -445,3 +395,3 @@

function(cls, context) {
var elements, resolver, nCls = '', reCls, cs;
var resolver, test, reCls, cs;

@@ -452,3 +402,3 @@ if (typeof cls == 'string') { cls = [ cls ]; }

if (cls.length < 2 && method['.'] in context) {
return context[method['.']](unescapeIdentifier(cls[0]));
return context[method['.']](cls[0]);
}

@@ -460,10 +410,8 @@

// multiple class names
cls.map(function(e) { nCls += '|' + e.replace(REX.RegExpChar, '\\$&'); });
reCls = RegExp('(^|\\s)' + nCls.slice(1) + '(\\s|$)', cs);
test = 'c.test(e.getAttribute("class"))';
reCls = RegExp('(^|\\s)' + cls.join('|') + '(\\s|$)', cs);
// build the resolver and execute it
resolver = Function('c', walk.replace('@', clsMatch))(reCls);
elements = resolver(context);
return elements;
resolver = Function('c', walk.replace('@', test))(reCls || cls[0]);
return resolver(context);
},

@@ -497,12 +445,16 @@

nthElement = (function() {
var idx, len, set, parent, parents = Array(), nodes = Array();
var idx = 0, len = 0, set = 0, parent = undefined, parents = Array(), nodes = Array();
return function(element, dir) {
// ensure caches are emptied after each run, invoking with dir = 2
if (dir == 2) {
idx = 0; len = 0; set = 0; nodes.length = 0;
parents.length = 0; parent = undefined;
return -1;
}
var e, i, j, k, l;
// ensure caches are emptied after each run, invoking with dir = 2
if (dir == 2) { nodes.length = 0; parents.length = 0; parent = null; return -1; }
if (parent === element.parentNode) {
if (parent === element.parentElement) {
i = set; j = idx; l = len;
} else {
l = parents.length;
parent = element.parentNode;
parent = element.parentElement;
for (i = -1, j = 0, k = l - 1; l > j; ++j, --k) {

@@ -515,4 +467,3 @@ if (parents[j] === parent) { i = j; break; }

l = 0; nodes[i] = Array();
e = parent.firstElementChild;
e = parent && parent.firstElementChild || element;
while (e) { nodes[i][l] = e; if (e === element) j = l; e = e.nextElementSibling; ++l; }

@@ -539,12 +490,16 @@ set = i; idx = 0; len = l;

nthOfType = (function() {
var idx, len, set, parent, parents = Array(), nodes = Array();
var idx = 0, len = 0, set = 0, parent = undefined, parents = Array(), nodes = Array();
return function(element, dir) {
// ensure caches are emptied after each run, invoking with dir = 2
if (dir == 2) { nodes.length = 0; parents.length = 0; parent = null; return -1; }
if (dir == 2) {
idx = 0; len = 0; set = 0; nodes.length = 0;
parents.length = 0; parent = undefined;
return -1;
}
var e, i, j, k, l, name = element.nodeName;
if (nodes[set] && nodes[set][name] && parent === element.parentNode) {
if (nodes[set] && nodes[set][name] && parent === element.parentElement) {
i = set; j = idx; l = len;
} else {
l = parents.length;
parent = element.parentNode;
parent = element.parentElement;
for (i = -1, j = 0, k = l - 1; l > j; ++j, --k) {

@@ -558,3 +513,3 @@ if (parents[j] === parent) { i = j; break; }

l = 0; nodes[i][name] = Array();
e = parent.firstElementChild;
e = parent && parent.firstElementChild || element;
while (e) { if (e === element) j = l; if (e.nodeName == name) { nodes[i][name][l] = e; ++l; } e = e.nextElementSibling; }

@@ -599,3 +554,7 @@ set = i; idx = j; len = l;

} else if (i == 'FASTCOMMA') {
set_compat();
compat = set_compat();
} else if (i == 'IDS_DUPES') {
domapi = set_domapi();
} else if (i == 'SVG_LCASE') {
Config.MIXEDCASE = Config[i];
}

@@ -635,2 +594,16 @@ }

// NOTE: SPECIAL CASES IN CSS SYNTAX PARSING RULES
//
// The <EOF-token> https://drafts.csswg.org/css-syntax/#typedef-eof-token
// allow mangled|unclosed selector syntax at the end of selectors strings
//
// These are the non capturing representations of each character: ' " ] )
//
// (?:\\'|$) - missing close double quotes
// (?:\\"|$) - missing close single quote
// (?:\\]|$) - missing close square bracket
// (?:\\)|$) - missing close round parens
//
// use the above four patterns to find instances throughout the code
var identifier =

@@ -654,8 +627,8 @@ // doesn't start with a digit

pseudoparms = '(?:[-+]?\\d*)(?:n[-+]?\\d*)',
doublequote = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"',
singlequote = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'",
doublequote = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*(?:"|$)',
singlequote = "'[^'\\\\]*(?:\\\\.[^'\\\\]*)*(?:'|$)",
attrparser = identifier + '|' + doublequote + '|' + singlequote,
attrvalues = '([\\x22\\x27]?)((?!\\3)*|(?:\\\\?.)*?)\\3',
attrvalues = '([\\x22\\x27]?)((?!\\3)*|(?:\\\\?.)*?)(?:\\3|$)',

@@ -675,5 +648,2 @@ attributes =

WSP + '?' + '(i)?' + WSP + '?' +
// see <EOF-token> https://drafts.csswg.org/css-syntax/#typedef-eof-token
// allow mangled|unclosed selector syntax if at the end of the qSA string
// needed to pass current WP tests and mimic browsers behavior 'a[href=#'
'(?:\\]|$)',

@@ -684,3 +654,3 @@

pseudoclass =
'(?:\\(' +
'(?:\\(' + WSP + '*' +
'(?:' + pseudoparms + '?)?|' +

@@ -692,7 +662,7 @@ // universal * &

'(?::' + identifier +
'(?:\\(' + pseudoparms + '?\\))?|' +
'(?:\\(' + pseudoparms + '?(?:\\)|$))?|' +
')|' +
'(?:[.#]?' + identifier + ')|' +
'(?:' + attributes + ')' +
')+\\))*',
')+' + '(?:' + WSP + '*)(?:\\)|$))*',

@@ -720,9 +690,9 @@ standardValidator =

'(?!:not)' +
'(?:[.:#]?' +
'(?:' + identifier + ')+|' +
'(?:\\([^()]*\\))' + ')+|' +
'(?:' + attributes + ')+|' +
'(?:' + WSP + '*[.:#]?' +
'(?:' + identifier + WSP + '*)+|' +
'(?:\\([^()]*(?:\\)|$))' + ')+|' +
'(?:' + WSP + '*' + attributes + WSP + '*)+|' +
')$');
reOptimizer = RegExp('(?:([.:#*]?)(' + identifier + ')(?::[-\\w]+|\\[.+\\]|\\(.+\\))*)$');
reOptimizer = RegExp('(?:([.:#*]?)(' + identifier + ')(?::[-\\w]+|\\[[^\\]]+(?:\\]|$)|\\([^\\)]+(?:\\)|$))*)$');

@@ -769,5 +739,2 @@ Patterns.id = RegExp('^#(' + identifier + ')(.*)');

// detect contexts having mixed namespaces elements
MIXED_NS = hasMixedNamespace(lastContext);
selector = groups.join(', ');

@@ -860,4 +827,3 @@ key = selector + '_' + (mode ? '1' : '0') + (callback ? '1' : '0');

match = selector.match(Patterns.id);
compat = HTML_DOCUMENT ? ATTR_ID : 'e.getAttribute("id")';
source = 'if(' + N + '(' + compat + '=="' + convertEscapes(match[1]) + '"' +
source = 'if(' + N + '(e.getAttribute("id")=="' + convertEscapes(match[1]) + '"' +
')){' + source + '}';

@@ -868,4 +834,3 @@ break;

match = selector.match(Patterns.className);
compat = HTML_DOCUMENT ? 'e.className' : 'e.getAttribute("class")';
source = 'if(' + N + '(/(^|\\s)' + match[1] + '(\\s|$)/.test(' + compat + ')' +
source = 'if(' + N + '(/(^|\\s)' + match[1] + '(\\s|$)/.test(e.getAttribute("class"))' +
')){' + source + '}';

@@ -878,3 +843,3 @@ break;

source = 'if(' + N + '(' +
(!HTML_DOCUMENT || MIXED_NS || lastContext.nodeType == 11 ?
(!HTML_DOCUMENT || MIXEDCASE || lastContext.nodeType == 11 ?
'/^' + match[1] + '$/i.test(e.nodeName)' :

@@ -901,3 +866,3 @@ 'e.nodeName=="' + compat + '"') +

match = selector.match(Patterns.attribute);
NS = !MIXED_NS && match[0].match(/(\*|\w+)\|[-\w]+/);
NS = !MIXEDCASE && match[0].match(/(\*|\w+)\|[-\w]+/);
name = match[1];

@@ -924,3 +889,3 @@ expr = name.split(':');

source = 'if(' + N + '(' + (!match[2] ?
(MIXED_NS && NS ? 's.hasAttributeNS(e,"' + name + '")' : 'e.hasAttribute("' + name + '")') :
(MIXEDCASE && NS ? 's.hasAttributeNS(e,"' + name + '")' : 'e.hasAttribute("' + name + '")') :
!match[4] && ATTR_STD_OPS[match[2]] && match[2] != '~=' ? 'e.getAttribute("' + name + '")==""' :

@@ -983,9 +948,9 @@ '(/' + test.p1 + match[4] + test.p2 + '/' + type + ').test(e.getAttribute("' + name + '"))==' + test.p3) +

case 'only-child':
source = 'if(' + N + '(e.parentNode.firstElementChild===e.parentNode.lastElementChild)){' + source + '}';
source = 'if(' + N + '(!e.nextElementSibling&&!e.previousElementSibling)){' + source + '}';
break;
case 'last-child':
source = 'if(' + N + '(e===e.parentNode.lastElementChild)){' + source + '}';
source = 'if(' + N + '(!e.nextElementSibling)){' + source + '}';
break;
case 'first-child':
source = 'if(' + N + '(e===e.parentNode.firstElementChild)){' + source + '}';
source = 'if(' + N + '(!e.previousElementSibling)){' + source + '}';
break;

@@ -1023,2 +988,8 @@ case 'only-of-type':

break;
} else if (match[2] == '1') {
test = type ? 'next' : 'previous';
source = expr ? 'n=e;o=e.nodeName;' +
'while((n=n.' + test + 'ElementSibling)&&n.nodeName!=o);if(' + D + 'n){' + source + '}' :
'if(' + N + '!e.' + test + 'ElementSibling){' + source + '}';
break;
} else if (match[2] == 'even' || match[2] == '2n0' || match[2] == '2n+0' || match[2] == '2n') {

@@ -1391,8 +1362,10 @@ test = 'n%2==0';

var groups, resolver, token;
var groups, resolver;
if (selector) {
context || (context = doc);
if ((resolver = selectResolvers[selector])) {
if (resolver.context === context && resolver.usrcall === callback) {
if (selector){
if (!callback && (resolver = selectResolvers[selector])) {
if (resolver.context === context) {
return resolver.factory(resolver.builder, callback, context);

@@ -1406,9 +1379,2 @@ }

context || (context = doc);
if (HAS_DUPE_IDS === undefined) {
HAS_DUPE_IDS = hasDuplicateId(context);
domapi = set_domapi();
}
// arguments validation

@@ -1453,3 +1419,3 @@ if (arguments.length === 0) {

// save/reuse factory and closure collection
if (!selectResolvers[selector]) {
if (!selectResolvers[selector] && !callback) {
selectResolvers[selector] = {

@@ -1462,3 +1428,2 @@ builder: resolver.builder,

}
return resolver.factory(resolver.builder, callback, context);

@@ -1473,4 +1438,4 @@ },

return selector.slice(0, index) +
(' >+~'.indexOf(selector[index - 1]) > -1 ?
(':['.indexOf(selector[index + length + 1]) > -1 ?
(' >+~'.indexOf(selector.charAt(index - 1)) > -1 ?
(':['.indexOf(selector.charAt(index + length + 1)) > -1 ?
'*' : '') : '') + selector.slice(index + length - (token[1] == '*' ? 1 : 0));

@@ -1491,3 +1456,3 @@ },

} else {
items = { '#': Array(), '.': Array(), '*': Array() };
var id = '', cn = '', tn = '', ni = 0, nc = 0, nt = 0;
for (i = 0, l = selector.length; l > i; ++i) {

@@ -1497,6 +1462,12 @@ if ((token = selector[i].match(reOptimizer)) && (ident = token[2])) {

}
if (items[symbol]) items[symbol].push(ident);
if (symbol == '#') { ++ni; id += i === 0 ? ident : ',' + ident; }
if (symbol == '.') { ++nc; cn += i === 0 ? ident : ',' + ident; }
if (symbol == '*') { ++nt; tn += i === 0 ? ident : ',' + ident; }
}
if (items[symbol] && items[symbol].length == l) {
builder = compat[symbol](context, items[symbol]);
if (ni == l) {
builder = compat['#'](context, id.split(','));
} else if (nc == l) {
builder = compat['.'](context, cn.split(','));
} else if (nt == l) {
builder = compat['*'](context, tn.split(','));
} else {

@@ -1503,0 +1474,0 @@ builder = compat['*'](context, '*');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc