source: trip-planner-front/node_modules/css-select/lib/attributes.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.1 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.attributeRules = void 0;
4var boolbase_1 = require("boolbase");
5/**
6 * All reserved characters in a regex, used for escaping.
7 *
8 * Taken from XRegExp, (c) 2007-2020 Steven Levithan under the MIT license
9 * https://github.com/slevithan/xregexp/blob/95eeebeb8fac8754d54eafe2b4743661ac1cf028/src/xregexp.js#L794
10 */
11var reChars = /[-[\]{}()*+?.,\\^$|#\s]/g;
12function escapeRegex(value) {
13 return value.replace(reChars, "\\$&");
14}
15/**
16 * Attribute selectors
17 */
18exports.attributeRules = {
19 equals: function (next, data, _a) {
20 var adapter = _a.adapter;
21 var name = data.name;
22 var value = data.value;
23 if (data.ignoreCase) {
24 value = value.toLowerCase();
25 return function (elem) {
26 var attr = adapter.getAttributeValue(elem, name);
27 return (attr != null &&
28 attr.length === value.length &&
29 attr.toLowerCase() === value &&
30 next(elem));
31 };
32 }
33 return function (elem) {
34 return adapter.getAttributeValue(elem, name) === value && next(elem);
35 };
36 },
37 hyphen: function (next, data, _a) {
38 var adapter = _a.adapter;
39 var name = data.name;
40 var value = data.value;
41 var len = value.length;
42 if (data.ignoreCase) {
43 value = value.toLowerCase();
44 return function hyphenIC(elem) {
45 var attr = adapter.getAttributeValue(elem, name);
46 return (attr != null &&
47 (attr.length === len || attr.charAt(len) === "-") &&
48 attr.substr(0, len).toLowerCase() === value &&
49 next(elem));
50 };
51 }
52 return function hyphen(elem) {
53 var attr = adapter.getAttributeValue(elem, name);
54 return (attr != null &&
55 (attr.length === len || attr.charAt(len) === "-") &&
56 attr.substr(0, len) === value &&
57 next(elem));
58 };
59 },
60 element: function (next, _a, _b) {
61 var name = _a.name, value = _a.value, ignoreCase = _a.ignoreCase;
62 var adapter = _b.adapter;
63 if (/\s/.test(value)) {
64 return boolbase_1.falseFunc;
65 }
66 var regex = new RegExp("(?:^|\\s)" + escapeRegex(value) + "(?:$|\\s)", ignoreCase ? "i" : "");
67 return function element(elem) {
68 var attr = adapter.getAttributeValue(elem, name);
69 return (attr != null &&
70 attr.length >= value.length &&
71 regex.test(attr) &&
72 next(elem));
73 };
74 },
75 exists: function (next, _a, _b) {
76 var name = _a.name;
77 var adapter = _b.adapter;
78 return function (elem) { return adapter.hasAttrib(elem, name) && next(elem); };
79 },
80 start: function (next, data, _a) {
81 var adapter = _a.adapter;
82 var name = data.name;
83 var value = data.value;
84 var len = value.length;
85 if (len === 0) {
86 return boolbase_1.falseFunc;
87 }
88 if (data.ignoreCase) {
89 value = value.toLowerCase();
90 return function (elem) {
91 var attr = adapter.getAttributeValue(elem, name);
92 return (attr != null &&
93 attr.length >= len &&
94 attr.substr(0, len).toLowerCase() === value &&
95 next(elem));
96 };
97 }
98 return function (elem) {
99 var _a;
100 return !!((_a = adapter.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.startsWith(value)) &&
101 next(elem);
102 };
103 },
104 end: function (next, data, _a) {
105 var adapter = _a.adapter;
106 var name = data.name;
107 var value = data.value;
108 var len = -value.length;
109 if (len === 0) {
110 return boolbase_1.falseFunc;
111 }
112 if (data.ignoreCase) {
113 value = value.toLowerCase();
114 return function (elem) {
115 var _a;
116 return ((_a = adapter
117 .getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.substr(len).toLowerCase()) === value && next(elem);
118 };
119 }
120 return function (elem) {
121 var _a;
122 return !!((_a = adapter.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.endsWith(value)) &&
123 next(elem);
124 };
125 },
126 any: function (next, data, _a) {
127 var adapter = _a.adapter;
128 var name = data.name, value = data.value;
129 if (value === "") {
130 return boolbase_1.falseFunc;
131 }
132 if (data.ignoreCase) {
133 var regex_1 = new RegExp(escapeRegex(value), "i");
134 return function anyIC(elem) {
135 var attr = adapter.getAttributeValue(elem, name);
136 return (attr != null &&
137 attr.length >= value.length &&
138 regex_1.test(attr) &&
139 next(elem));
140 };
141 }
142 return function (elem) {
143 var _a;
144 return !!((_a = adapter.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.includes(value)) &&
145 next(elem);
146 };
147 },
148 not: function (next, data, _a) {
149 var adapter = _a.adapter;
150 var name = data.name;
151 var value = data.value;
152 if (value === "") {
153 return function (elem) {
154 return !!adapter.getAttributeValue(elem, name) && next(elem);
155 };
156 }
157 else if (data.ignoreCase) {
158 value = value.toLowerCase();
159 return function (elem) {
160 var attr = adapter.getAttributeValue(elem, name);
161 return ((attr == null ||
162 attr.length !== value.length ||
163 attr.toLowerCase() !== value) &&
164 next(elem));
165 };
166 }
167 return function (elem) {
168 return adapter.getAttributeValue(elem, name) !== value && next(elem);
169 };
170 },
171};
Note: See TracBrowser for help on using the repository browser.