aboutsummaryrefslogtreecommitdiff
path: root/node_modules/css-what
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
commitde98e0b232509d5f40c135d540a70e415272ff85 (patch)
treea79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/css-what
parente0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff)
node_modules
Diffstat (limited to 'node_modules/css-what')
-rw-r--r--node_modules/css-what/LICENSE11
-rw-r--r--node_modules/css-what/index.js267
-rw-r--r--node_modules/css-what/package.json44
-rw-r--r--node_modules/css-what/readme.md46
4 files changed, 368 insertions, 0 deletions
diff --git a/node_modules/css-what/LICENSE b/node_modules/css-what/LICENSE
new file mode 100644
index 000000000..c464f863e
--- /dev/null
+++ b/node_modules/css-what/LICENSE
@@ -0,0 +1,11 @@
+Copyright (c) Felix Böhm
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/node_modules/css-what/index.js b/node_modules/css-what/index.js
new file mode 100644
index 000000000..859324c3f
--- /dev/null
+++ b/node_modules/css-what/index.js
@@ -0,0 +1,267 @@
+"use strict";
+
+module.exports = parse;
+
+var re_name = /^(?:\\.|[\w\-\u00c0-\uFFFF])+/,
+ re_escape = /\\([\da-f]{1,6}\s?|(\s)|.)/ig,
+ //modified version of https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L87
+ re_attr = /^\s*((?:\\.|[\w\u00c0-\uFFFF\-])+)\s*(?:(\S?)=\s*(?:(['"])(.*?)\3|(#?(?:\\.|[\w\u00c0-\uFFFF\-])*)|)|)\s*(i)?\]/;
+
+var actionTypes = {
+ __proto__: null,
+ "undefined": "exists",
+ "": "equals",
+ "~": "element",
+ "^": "start",
+ "$": "end",
+ "*": "any",
+ "!": "not",
+ "|": "hyphen"
+};
+
+var simpleSelectors = {
+ __proto__: null,
+ ">": "child",
+ "<": "parent",
+ "~": "sibling",
+ "+": "adjacent"
+};
+
+var attribSelectors = {
+ __proto__: null,
+ "#": ["id", "equals"],
+ ".": ["class", "element"]
+};
+
+//pseudos, whose data-property is parsed as well
+var unpackPseudos = {
+ __proto__: null,
+ "has": true,
+ "not": true,
+ "matches": true
+};
+
+var stripQuotesFromPseudos = {
+ __proto__: null,
+ "contains": true,
+ "icontains": true
+};
+
+var quotes = {
+ __proto__: null,
+ "\"": true,
+ "'": true
+};
+
+//unescape function taken from https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L139
+function funescape( _, escaped, escapedWhitespace ) {
+ var high = "0x" + escaped - 0x10000;
+ // NaN means non-codepoint
+ // Support: Firefox
+ // Workaround erroneous numeric interpretation of +"0x"
+ return high !== high || escapedWhitespace ?
+ escaped :
+ // BMP codepoint
+ high < 0 ?
+ String.fromCharCode( high + 0x10000 ) :
+ // Supplemental Plane codepoint (surrogate pair)
+ String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
+}
+
+function unescapeCSS(str){
+ return str.replace(re_escape, funescape);
+}
+
+function isWhitespace(c){
+ return c === " " || c === "\n" || c === "\t" || c === "\f" || c === "\r";
+}
+
+function parse(selector, options){
+ var subselects = [];
+
+ selector = parseSelector(subselects, selector + "", options);
+
+ if(selector !== ""){
+ throw new SyntaxError("Unmatched selector: " + selector);
+ }
+
+ return subselects;
+}
+
+function parseSelector(subselects, selector, options){
+ var tokens = [],
+ sawWS = false,
+ data, firstChar, name, quot;
+
+ function getName(){
+ var sub = selector.match(re_name)[0];
+ selector = selector.substr(sub.length);
+ return unescapeCSS(sub);
+ }
+
+ function stripWhitespace(start){
+ while(isWhitespace(selector.charAt(start))) start++;
+ selector = selector.substr(start);
+ }
+
+ stripWhitespace(0);
+
+ while(selector !== ""){
+ firstChar = selector.charAt(0);
+
+ if(isWhitespace(firstChar)){
+ sawWS = true;
+ stripWhitespace(1);
+ } else if(firstChar in simpleSelectors){
+ tokens.push({type: simpleSelectors[firstChar]});
+ sawWS = false;
+
+ stripWhitespace(1);
+ } else if(firstChar === ","){
+ if(tokens.length === 0){
+ throw new SyntaxError("empty sub-selector");
+ }
+ subselects.push(tokens);
+ tokens = [];
+ sawWS = false;
+ stripWhitespace(1);
+ } else {
+ if(sawWS){
+ if(tokens.length > 0){
+ tokens.push({type: "descendant"});
+ }
+ sawWS = false;
+ }
+
+ if(firstChar === "*"){
+ selector = selector.substr(1);
+ tokens.push({type: "universal"});
+ } else if(firstChar in attribSelectors){
+ selector = selector.substr(1);
+ tokens.push({
+ type: "attribute",
+ name: attribSelectors[firstChar][0],
+ action: attribSelectors[firstChar][1],
+ value: getName(),
+ ignoreCase: false
+ });
+ } else if(firstChar === "["){
+ selector = selector.substr(1);
+ data = selector.match(re_attr);
+ if(!data){
+ throw new SyntaxError("Malformed attribute selector: " + selector);
+ }
+ selector = selector.substr(data[0].length);
+ name = unescapeCSS(data[1]);
+
+ if(
+ !options || (
+ "lowerCaseAttributeNames" in options ?
+ options.lowerCaseAttributeNames :
+ !options.xmlMode
+ )
+ ){
+ name = name.toLowerCase();
+ }
+
+ tokens.push({
+ type: "attribute",
+ name: name,
+ action: actionTypes[data[2]],
+ value: unescapeCSS(data[4] || data[5] || ""),
+ ignoreCase: !!data[6]
+ });
+
+ } else if(firstChar === ":"){
+ if(selector.charAt(1) === ":"){
+ selector = selector.substr(2);
+ tokens.push({type: "pseudo-element", name: getName().toLowerCase()});
+ continue;
+ }
+
+ selector = selector.substr(1);
+
+ name = getName().toLowerCase();
+ data = null;
+
+ if(selector.charAt(0) === "("){
+ if(name in unpackPseudos){
+ quot = selector.charAt(1);
+ var quoted = quot in quotes;
+
+ selector = selector.substr(quoted + 1);
+
+ data = [];
+ selector = parseSelector(data, selector, options);
+
+ if(quoted){
+ if(selector.charAt(0) !== quot){
+ throw new SyntaxError("unmatched quotes in :" + name);
+ } else {
+ selector = selector.substr(1);
+ }
+ }
+
+ if(selector.charAt(0) !== ")"){
+ throw new SyntaxError("missing closing parenthesis in :" + name + " " + selector);
+ }
+
+ selector = selector.substr(1);
+ } else {
+ var pos = 1, counter = 1;
+
+ for(; counter > 0 && pos < selector.length; pos++){
+ if(selector.charAt(pos) === "(") counter++;
+ else if(selector.charAt(pos) === ")") counter--;
+ }
+
+ if(counter){
+ throw new SyntaxError("parenthesis not matched");
+ }
+
+ data = selector.substr(1, pos - 2);
+ selector = selector.substr(pos);
+
+ if(name in stripQuotesFromPseudos){
+ quot = data.charAt(0);
+
+ if(quot === data.slice(-1) && quot in quotes){
+ data = data.slice(1, -1);
+ }
+
+ data = unescapeCSS(data);
+ }
+ }
+ }
+
+ tokens.push({type: "pseudo", name: name, data: data});
+ } else if(re_name.test(selector)){
+ name = getName();
+
+ if(!options || ("lowerCaseTags" in options ? options.lowerCaseTags : !options.xmlMode)){
+ name = name.toLowerCase();
+ }
+
+ tokens.push({type: "tag", name: name});
+ } else {
+ if(tokens.length && tokens[tokens.length - 1].type === "descendant"){
+ tokens.pop();
+ }
+ addToken(subselects, tokens);
+ return selector;
+ }
+ }
+ }
+
+ addToken(subselects, tokens);
+
+ return selector;
+}
+
+function addToken(subselects, tokens){
+ if(subselects.length > 0 && tokens.length === 0){
+ throw new SyntaxError("empty sub-selector");
+ }
+
+ subselects.push(tokens);
+}
diff --git a/node_modules/css-what/package.json b/node_modules/css-what/package.json
new file mode 100644
index 000000000..b55c98ca5
--- /dev/null
+++ b/node_modules/css-what/package.json
@@ -0,0 +1,44 @@
+{
+ "author": "Felix Böhm <me@feedic.com> (http://feedic.com)",
+ "name": "css-what",
+ "description": "a CSS selector parser",
+ "version": "2.1.0",
+ "repository": {
+ "url": "https://github.com/fb55/css-what"
+ },
+ "main": "./index.js",
+ "files": [
+ "index.js"
+ ],
+ "scripts": {
+ "test": "node tests/test.js && jshint *.js"
+ },
+ "dependencies": {},
+ "devDependencies": {
+ "jshint": "2"
+ },
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ },
+ "license": "BSD-like",
+ "jshintConfig": {
+ "eqeqeq": true,
+ "freeze": true,
+ "latedef": "nofunc",
+ "noarg": true,
+ "nonbsp": true,
+ "quotmark": "double",
+ "undef": true,
+ "unused": true,
+ "trailing": true,
+ "eqnull": true,
+ "proto": true,
+ "smarttabs": true,
+ "node": true,
+ "globals": {
+ "describe": true,
+ "it": true
+ }
+ }
+}
diff --git a/node_modules/css-what/readme.md b/node_modules/css-what/readme.md
new file mode 100644
index 000000000..736e59128
--- /dev/null
+++ b/node_modules/css-what/readme.md
@@ -0,0 +1,46 @@
+# css-what [![Build Status](https://secure.travis-ci.org/fb55/css-what.svg?branch=master)](http://travis-ci.org/fb55/css-what)
+
+a CSS selector parser
+
+## Example
+
+```js
+require('css-what')('foo[bar]:baz')
+
+~> [ [ { type: 'tag', name: 'foo' },
+ { type: 'attribute',
+ name: 'bar',
+ action: 'exists',
+ value: '',
+ ignoreCase: false },
+ { type: 'pseudo',
+ name: 'baz',
+ data: null } ] ]
+```
+
+## API
+
+__`CSSwhat(selector, options)` - Parses `str`, with the passed `options`.__
+
+The function returns a two-dimensional array. The first array represents selectors separated by commas (eg. `sub1, sub2`), the second contains the relevant tokens for that selector. Possible token types are:
+
+name | attributes | example | output
+---- | ---------- | ------- | ------
+`tag`| `name` | `div` | `{ type: 'tag', name: 'div' }`
+`universal`| - | `*` | `{ type: 'universal' }`
+`pseudo`| `name`, `data`|`:name(data)`| `{ type: 'pseudo', name: 'name', data: 'data' }`
+`pseudo`| `name`, `data`|`:name`| `{ type: 'pseudo', name: 'name', data: null }`
+`attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr]`|`{ type: 'attribute', name: 'attr', action: 'exists', value: '', ignoreCase: false }`
+`attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr=val]`|`{ type: 'attribute', name: 'attr', action: 'equals', value: 'val', ignoreCase: false }`
+`attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr^=val]`|`{ type: 'attribute', name: 'attr', action: 'start', value: 'val', ignoreCase: false }`
+`attribute`|`name`, `action`, `value`, `ignoreCase`|`[attr$=val]`|`{ type: 'attribute', name: 'attr', action: 'end', value: 'val', ignoreCase: false }`
+
+//TODO complete list
+
+__Options:__
+
+- `xmlMode`: When enabled, tag names will be case-sensitive (meaning they won't be lowercased).
+
+---
+
+License: BSD-like