first commit

This commit is contained in:
DanielRamirezGe
2020-01-14 20:43:08 -06:00
parent 3557894f7f
commit 5eecfbf6cd
26326 changed files with 2434803 additions and 0 deletions
+11
View File
@@ -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.
+4
View File
@@ -0,0 +1,4 @@
export * from "./parse";
export { default as parse } from "./parse";
export { default as stringify } from "./stringify";
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC"}
+10
View File
@@ -0,0 +1,10 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./parse"));
var parse_1 = require("./parse");
exports.parse = parse_1.default;
var stringify_1 = require("./stringify");
exports.stringify = stringify_1.default;
+38
View File
@@ -0,0 +1,38 @@
export default parse;
export interface Options {
lowerCaseAttributeNames?: boolean;
lowerCaseTags?: boolean;
xmlMode?: boolean;
}
export declare type Selector = PseudoSelector | PseudoElement | AttributeSelector | TagSelector | UniversalSelector | Traversal;
export interface AttributeSelector {
type: "attribute";
name: string;
action: AttributeAction;
value: string;
ignoreCase: boolean;
}
declare type DataType = Selector[][] | null | string;
export interface PseudoSelector {
type: "pseudo";
name: string;
data: DataType;
}
export interface PseudoElement {
type: "pseudo-element";
name: string;
}
export interface TagSelector {
type: "tag";
name: string;
}
export interface UniversalSelector {
type: "universal";
}
export interface Traversal {
type: TraversalType;
}
export declare type AttributeAction = "any" | "element" | "end" | "equals" | "exists" | "hyphen" | "not" | "start";
export declare type TraversalType = "adjacent" | "child" | "descendant" | "parent" | "sibling";
declare function parse(selector: string, options?: Options): Selector[][];
//# sourceMappingURL=parse.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAEA,eAAe,KAAK,CAAC;AAErB,MAAM,WAAW,OAAO;IACpB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,oBAAY,QAAQ,GACd,cAAc,GACd,aAAa,GACb,iBAAiB,GACjB,WAAW,GACX,iBAAiB,GACjB,SAAS,CAAC;AAEhB,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;CACvB;AAED,aAAK,QAAQ,GAAG,QAAQ,EAAE,EAAE,GAAG,IAAI,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,aAAa,CAAC;CACvB;AAED,oBAAY,eAAe,GACrB,KAAK,GACL,SAAS,GACT,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,KAAK,GACL,OAAO,CAAC;AAEd,oBAAY,aAAa,GACnB,UAAU,GACV,OAAO,GACP,YAAY,GACZ,QAAQ,GACR,SAAS,CAAC;AA2DhB,iBAAS,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,EAAE,EAAE,CAUhE"}
+229
View File
@@ -0,0 +1,229 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = parse;
var reName = /^(?:\\([\da-f]{1,6}\s?|(\s)|.)|[\w\-\u00b0-\uFFFF])+/, reEscape = /\\([\da-f]{1,6}\s?|(\s)|.)/gi,
//modified version of https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L87
reAttr = /^\s*((?:\\.|[\w\u00b0-\uFFFF-])+)\s*(?:(\S?)=\s*(?:(['"])([^]*?)\3|(#?(?:\\.|[\w\u00b0-\uFFFF-])*)|)|)\s*(i)?\]/;
var actionTypes = {
undefined: "exists",
"": "equals",
"~": "element",
"^": "start",
$: "end",
"*": "any",
"!": "not",
"|": "hyphen"
};
var Traversals = {
">": "child",
"<": "parent",
"~": "sibling",
"+": "adjacent"
};
var attribSelectors = {
"#": ["id", "equals"],
".": ["class", "element"]
};
//pseudos, whose data-property is parsed as well
var unpackPseudos = new Set(["has", "not", "matches"]);
var stripQuotesFromPseudos = new Set(["contains", "icontains"]);
var quotes = new Set(['"', "'"]);
//unescape function taken from https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L152
function funescape(_, escaped, escapedWhitespace) {
var high = parseInt(escaped, 16) - 0x10000;
// NaN means non-codepoint
return high !== high || escapedWhitespace
? escaped
: high < 0
? // BMP codepoint
String.fromCharCode(high + 0x10000)
: // Supplemental Plane codepoint (surrogate pair)
String.fromCharCode((high >> 10) | 0xd800, (high & 0x3ff) | 0xdc00);
}
function unescapeCSS(str) {
return str.replace(reEscape, 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 Error("Unmatched selector: " + selector);
}
return subselects;
}
function parseSelector(subselects, selector, options) {
var tokens = [], sawWS = false;
function getName() {
var match = selector.match(reName);
if (!match) {
throw new Error("Expected name, found " + selector);
}
var sub = match[0];
selector = selector.substr(sub.length);
return unescapeCSS(sub);
}
function stripWhitespace(start) {
while (isWhitespace(selector.charAt(start)))
start++;
selector = selector.substr(start);
}
function isEscaped(pos) {
var slashCount = 0;
while (selector.charAt(--pos) === "\\")
slashCount++;
return (slashCount & 1) === 1;
}
stripWhitespace(0);
while (selector !== "") {
var firstChar = selector.charAt(0);
if (isWhitespace(firstChar)) {
sawWS = true;
stripWhitespace(1);
}
else if (firstChar in Traversals) {
tokens.push({ type: Traversals[firstChar] });
sawWS = false;
stripWhitespace(1);
}
else if (firstChar === ",") {
if (tokens.length === 0) {
throw new Error("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) {
var _a = attribSelectors[firstChar], name_1 = _a[0], action = _a[1];
selector = selector.substr(1);
tokens.push({
type: "attribute",
name: name_1,
action: action,
value: getName(),
ignoreCase: false
});
}
else if (firstChar === "[") {
selector = selector.substr(1);
var data = selector.match(reAttr);
if (!data) {
throw new Error("Malformed attribute selector: " + selector);
}
selector = selector.substr(data[0].length);
var name_2 = unescapeCSS(data[1]);
if (!options ||
("lowerCaseAttributeNames" in options
? options.lowerCaseAttributeNames
: !options.xmlMode)) {
name_2 = name_2.toLowerCase();
}
tokens.push({
type: "attribute",
name: name_2,
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);
var name_3 = getName().toLowerCase();
var data = null;
if (selector.charAt(0) === "(") {
if (unpackPseudos.has(name_3)) {
var quot = selector.charAt(1);
var quoted = quotes.has(quot);
selector = selector.substr(quoted ? 2 : 1);
data = [];
selector = parseSelector(data, selector, options);
if (quoted) {
if (selector.charAt(0) !== quot) {
throw new Error("Unmatched quotes in :" + name_3);
}
else {
selector = selector.substr(1);
}
}
if (selector.charAt(0) !== ")") {
throw new Error("Missing closing parenthesis in :" + name_3 + " (" + selector + ")");
}
selector = selector.substr(1);
}
else {
var pos = 1, counter = 1;
for (; counter > 0 && pos < selector.length; pos++) {
if (selector.charAt(pos) === "(" && !isEscaped(pos))
counter++;
else if (selector.charAt(pos) === ")" &&
!isEscaped(pos))
counter--;
}
if (counter) {
throw new Error("Parenthesis not matched");
}
data = selector.substr(1, pos - 2);
selector = selector.substr(pos);
if (stripQuotesFromPseudos.has(name_3)) {
var quot = data.charAt(0);
if (quot === data.slice(-1) && quotes.has(quot)) {
data = data.slice(1, -1);
}
data = unescapeCSS(data);
}
}
}
tokens.push({ type: "pseudo", name: name_3, data: data });
}
else if (reName.test(selector)) {
var name_4 = getName();
if (!options ||
("lowerCaseTags" in options
? options.lowerCaseTags
: !options.xmlMode)) {
name_4 = name_4.toLowerCase();
}
tokens.push({ type: "tag", name: name_4 });
}
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 Error("Empty sub-selector");
}
subselects.push(tokens);
}
+3
View File
@@ -0,0 +1,3 @@
import { Selector } from "./parse";
export default function stringify(token: Selector[][]): string;
//# sourceMappingURL=stringify.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"stringify.d.ts","sourceRoot":"","sources":["../src/stringify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAqBnC,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,MAAM,CAE7D"}
+67
View File
@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var actionTypes = {
equals: "",
element: "~",
start: "^",
end: "$",
any: "*",
not: "!",
hyphen: "|"
};
var simpleSelectors = {
child: " > ",
parent: " < ",
sibling: " ~ ",
adjacent: " + ",
descendant: " ",
universal: "*"
};
function stringify(token) {
return token.map(stringifySubselector).join(", ");
}
exports.default = stringify;
function stringifySubselector(token) {
return token.map(stringifyToken).join("");
}
function stringifyToken(token) {
if (token.type in simpleSelectors)
return simpleSelectors[token.type];
if (token.type === "tag")
return escapeName(token.name);
if (token.type === "pseudo-element")
return "::" + escapeName(token.name);
if (token.type === "attribute") {
if (token.action === "exists") {
return "[" + escapeName(token.name) + "]";
}
if (token.name === "id" &&
token.action === "equals" &&
!token.ignoreCase) {
return "#" + escapeName(token.value);
}
if (token.name === "class" &&
token.action === "element" &&
!token.ignoreCase) {
return "." + escapeName(token.value);
}
var atributeName = escapeName(token.name);
var action = actionTypes[token.action];
var value = escapeName(token.value);
var ignoreCase = token.ignoreCase ? "i" : "";
return "[" + atributeName + action + "='" + value + "'" + ignoreCase + "]";
}
if (token.type === "pseudo") {
if (token.data === null)
return ":" + escapeName(token.name);
if (typeof token.data === "string") {
return ":" + escapeName(token.name) + "(" + token.data + ")";
}
return ":" + escapeName(token.name) + "(" + stringify(token.data) + ")";
}
throw new Error("Unknown type");
}
function escapeName(str) {
//TODO
return str;
}
+81
View File
@@ -0,0 +1,81 @@
{
"_from": "css-what@^3.2.1",
"_id": "css-what@3.2.1",
"_inBundle": false,
"_integrity": "sha512-WwOrosiQTvyms+Ti5ZC5vGEK0Vod3FTt1ca+payZqvKuGJF+dq7bG63DstxtN0dpm6FxY27a/zS3Wten+gEtGw==",
"_location": "/css-what",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "css-what@^3.2.1",
"name": "css-what",
"escapedName": "css-what",
"rawSpec": "^3.2.1",
"saveSpec": null,
"fetchSpec": "^3.2.1"
},
"_requiredBy": [
"/css-select"
],
"_resolved": "https://registry.npmjs.org/css-what/-/css-what-3.2.1.tgz",
"_shasum": "f4a8f12421064621b456755e34a03a2c22df5da1",
"_spec": "css-what@^3.2.1",
"_where": "/home/george/citwa/red_de_investigacion_front/first/node_modules/css-select",
"author": {
"name": "Felix Böhm",
"email": "me@feedic.com",
"url": "http://feedic.com"
},
"bugs": {
"url": "https://github.com/fb55/css-what/issues"
},
"bundleDependencies": false,
"dependencies": {},
"deprecated": false,
"description": "a CSS selector parser",
"devDependencies": {
"@types/jest": "^24.0.16",
"@types/node": "^12.6.2",
"@typescript-eslint/eslint-plugin": "^1.12.0",
"@typescript-eslint/parser": "^1.12.0",
"coveralls": "^3.0.5",
"eslint": "^6.0.1",
"eslint-config-prettier": "^6.0.0",
"jest": "^24.8.0",
"prettier": "^1.18.2",
"ts-jest": "^24.0.2",
"typescript": "^3.5.3"
},
"engines": {
"node": ">= 6"
},
"files": [
"lib/**/*"
],
"homepage": "https://github.com/fb55/css-what#readme",
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
},
"license": "BSD-2-Clause",
"main": "lib/index.js",
"name": "css-what",
"optionalDependencies": {},
"prettier": {
"tabWidth": 4
},
"repository": {
"url": "git+https://github.com/fb55/css-what.git"
},
"scripts": {
"build": "tsc",
"coverage": "cat coverage/lcov.info | coveralls",
"format": "prettier --write '**/*.{ts,md,json}'",
"lint": "eslint --ext=js,ts src",
"prepare": "npm run build",
"test": "jest --coverage -u && npm run lint"
},
"types": "lib/index.d.ts",
"version": "3.2.1"
}
+70
View File
@@ -0,0 +1,70 @@
# 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
const CSSwhat = require("css-what")
CSSwhat.parse("foo[bar]:baz")
~> [
[
{ type: "tag", name: "foo" },
{
type: "attribute",
name: "bar",
action: "exists",
value: "",
ignoreCase: false
},
{ type: "pseudo", name: "baz", data: null }
]
]
```
## API
**`CSSwhat.parse(str, options)` - Parses `str`, optionally 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 }` |
| `pseudo-element` | `name` | `::name` | `{ type: 'pseudo-element', name: 'name' }` |
| `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 }` |
| `child` | - | `>` | `{ type: 'child' }` |
| `parent` | - | `<` | `{ type: 'parent' }` |
| `sibling` | - | `~` | `{ type: 'sibling' }` |
| `adjacent` | - | `+` | `{ type: 'adjacent' }` |
| `descendant` | - | | `{ type: 'descendant' }` |
**Options:**
- `lowerCaseTags`: When false, tag names will not be lowercased. Defaults to `true`.
- `lowerCaseAttributeNames`: When false, attribute names will not be lowercased. Defaults to `true`.
- `xmlMode`: When `true`, `xmlMode` implies both `lowerCaseTags` and `lowerCaseAttributeNames` are set to `false`.
**`CSSwhat.stringify(selector)` - Turns `selector` back into a string.**
---
License: BSD-2-Clause
## Security contact information
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure.
## `css-what` for enterprise
Available as part of the Tidelift Subscription
The maintainers of `css-what` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-css-what?utm_source=npm-css-what&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)