@common.js/object-scan 20.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +5 -0
- package/lib/core/compiler-iterator.js +109 -0
- package/lib/core/compiler.js +164 -0
- package/lib/core/context.js +149 -0
- package/lib/core/find-result.js +77 -0
- package/lib/core/find-util.js +92 -0
- package/lib/core/find.js +297 -0
- package/lib/core/node-util.js +94 -0
- package/lib/core/node.js +151 -0
- package/lib/core/parser-ref.js +59 -0
- package/lib/core/parser-result.js +218 -0
- package/lib/core/parser-value.js +24 -0
- package/lib/core/parser.js +205 -0
- package/lib/generic/assert.js +16 -0
- package/lib/generic/helper.js +85 -0
- package/lib/generic/iterator.js +97 -0
- package/lib/index.js +97 -0
- package/lib/index.min.js +1443 -0
- package/package.json +81 -0
package/lib/core/find.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _findUtilJs = require("./find-util.js");
|
|
12
|
+
var _findResultJs = /*#__PURE__*/ _interopRequireDefault(require("./find-result.js"));
|
|
13
|
+
function _arrayLikeToArray(arr, len) {
|
|
14
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
15
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
16
|
+
return arr2;
|
|
17
|
+
}
|
|
18
|
+
function _arrayWithoutHoles(arr) {
|
|
19
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
20
|
+
}
|
|
21
|
+
function _instanceof(left, right) {
|
|
22
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
23
|
+
return !!right[Symbol.hasInstance](left);
|
|
24
|
+
} else {
|
|
25
|
+
return left instanceof right;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function _interopRequireDefault(obj) {
|
|
29
|
+
return obj && obj.__esModule ? obj : {
|
|
30
|
+
default: obj
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function _iterableToArray(iter) {
|
|
34
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
35
|
+
}
|
|
36
|
+
function _nonIterableSpread() {
|
|
37
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
38
|
+
}
|
|
39
|
+
function _toConsumableArray(arr) {
|
|
40
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
41
|
+
}
|
|
42
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
43
|
+
if (!o) return;
|
|
44
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
45
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
46
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
47
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
48
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
49
|
+
}
|
|
50
|
+
var _default = function(haystack_, search_, ctx) {
|
|
51
|
+
var _loop = function() {
|
|
52
|
+
depth = stack.pop();
|
|
53
|
+
segment = stack.pop();
|
|
54
|
+
searches = stack.pop();
|
|
55
|
+
isMatch = stack.pop();
|
|
56
|
+
var diff = path.length - depth;
|
|
57
|
+
for(var idx = 0; idx < diff; idx += 1){
|
|
58
|
+
parents.pop();
|
|
59
|
+
path.pop();
|
|
60
|
+
}
|
|
61
|
+
if (diff === -1) {
|
|
62
|
+
parents.push(haystack);
|
|
63
|
+
path.push(segment);
|
|
64
|
+
haystack = haystack[segment];
|
|
65
|
+
} else if (segment !== null) {
|
|
66
|
+
path[path.length - 1] = segment;
|
|
67
|
+
haystack = parents[parents.length - 1][segment];
|
|
68
|
+
} else {
|
|
69
|
+
haystack = state.haystack;
|
|
70
|
+
}
|
|
71
|
+
if (isMatch) {
|
|
72
|
+
if (ctx.filterFn === undefined || ctx.filterFn(kwargs) !== false) {
|
|
73
|
+
result.onMatch(kwargs);
|
|
74
|
+
if (ctx.abort) {
|
|
75
|
+
stack.length = 0;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// eslint-disable-next-line no-continue
|
|
79
|
+
return "continue";
|
|
80
|
+
}
|
|
81
|
+
if (!searches.some(function(param) {
|
|
82
|
+
var matches = param.matches;
|
|
83
|
+
return matches;
|
|
84
|
+
})) {
|
|
85
|
+
// eslint-disable-next-line no-continue
|
|
86
|
+
return "continue";
|
|
87
|
+
}
|
|
88
|
+
var autoTraverseArray = ctx.useArraySelector === false && Array.isArray(haystack);
|
|
89
|
+
if (!autoTraverseArray && (0, _findUtilJs.isLastLeafMatch)(searches)) {
|
|
90
|
+
stack.push(true, searches, segment, depth);
|
|
91
|
+
isMatch = true;
|
|
92
|
+
}
|
|
93
|
+
if ((ctx.breakFn === undefined || ctx.breakFn(kwargs) !== true) && _instanceof(haystack, Object)) {
|
|
94
|
+
var _loop = function(kIdx, kLen) {
|
|
95
|
+
var key = keys[kIdx];
|
|
96
|
+
var searchesOut = [];
|
|
97
|
+
if (autoTraverseArray) {
|
|
98
|
+
var _searchesOut;
|
|
99
|
+
(_searchesOut = searchesOut).push.apply(_searchesOut, _toConsumableArray(searches));
|
|
100
|
+
if (depth === 0) {
|
|
101
|
+
var _searchesOut1;
|
|
102
|
+
(_searchesOut1 = searchesOut).push.apply(_searchesOut1, _toConsumableArray(search_.roots));
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
for(var sIdx = 0, sLen = searches.length; sIdx !== sLen; sIdx += 1){
|
|
106
|
+
var search = searches[sIdx];
|
|
107
|
+
if (search.recMatch(key)) {
|
|
108
|
+
searchesOut.push(search);
|
|
109
|
+
}
|
|
110
|
+
var children = search.children;
|
|
111
|
+
var eIdx = children.length;
|
|
112
|
+
// eslint-disable-next-line no-plusplus
|
|
113
|
+
while(eIdx--){
|
|
114
|
+
var child = children[eIdx];
|
|
115
|
+
if (child.typeMatch(key, isArray)) {
|
|
116
|
+
searchesOut.push(child);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (ctx.orderByNeedles) {
|
|
122
|
+
searchesOut.index = Buffer.from(searchesOut.map(function(param) {
|
|
123
|
+
var order = param.order;
|
|
124
|
+
return order;
|
|
125
|
+
}).sort());
|
|
126
|
+
var checkIdx = stack.length - 3;
|
|
127
|
+
var checkIdxMin = checkIdx - kIdx * 4;
|
|
128
|
+
while(checkIdx !== checkIdxMin && Buffer.compare(searchesOut.index, stack[checkIdx].index) === 1){
|
|
129
|
+
checkIdx -= 4;
|
|
130
|
+
}
|
|
131
|
+
stack.splice(checkIdx + 3, 0, false, searchesOut, key, depth + 1);
|
|
132
|
+
} else {
|
|
133
|
+
stack.push(false, searchesOut, key, depth + 1);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var isArray = Array.isArray(haystack);
|
|
137
|
+
var keys = isArray ? haystack.map(function(_, i) {
|
|
138
|
+
return i;
|
|
139
|
+
}).filter(function() {
|
|
140
|
+
return true;
|
|
141
|
+
}) : Object.keys(haystack);
|
|
142
|
+
if (!isArray && ctx.compareFn) {
|
|
143
|
+
keys.sort(ctx.compareFn(kwargs));
|
|
144
|
+
}
|
|
145
|
+
if (!ctx.reverse) {
|
|
146
|
+
keys.reverse();
|
|
147
|
+
}
|
|
148
|
+
for(var kIdx = 0, kLen = keys.length; kIdx < kLen; kIdx += 1)_loop(kIdx, kLen);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var state = {
|
|
152
|
+
haystack: haystack_,
|
|
153
|
+
context: ctx.context
|
|
154
|
+
};
|
|
155
|
+
if (ctx.beforeFn !== undefined) {
|
|
156
|
+
var r = ctx.beforeFn(state);
|
|
157
|
+
if (r !== undefined) {
|
|
158
|
+
state.haystack = r;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
var stack = [
|
|
162
|
+
false,
|
|
163
|
+
[
|
|
164
|
+
search_
|
|
165
|
+
],
|
|
166
|
+
null,
|
|
167
|
+
0
|
|
168
|
+
];
|
|
169
|
+
var path = [];
|
|
170
|
+
var parents = [];
|
|
171
|
+
var depth;
|
|
172
|
+
var segment;
|
|
173
|
+
var searches;
|
|
174
|
+
var isMatch;
|
|
175
|
+
var haystack = state.haystack;
|
|
176
|
+
var kwargs = {
|
|
177
|
+
getKey: function() {
|
|
178
|
+
var joined = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : ctx.joined;
|
|
179
|
+
return (0, _findUtilJs.formatPath)(path, joined);
|
|
180
|
+
},
|
|
181
|
+
get key () {
|
|
182
|
+
return kwargs.getKey();
|
|
183
|
+
},
|
|
184
|
+
getValue: function() {
|
|
185
|
+
return haystack;
|
|
186
|
+
},
|
|
187
|
+
get value () {
|
|
188
|
+
return kwargs.getValue();
|
|
189
|
+
},
|
|
190
|
+
getEntry: function() {
|
|
191
|
+
var joined = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : ctx.joined;
|
|
192
|
+
return [
|
|
193
|
+
(0, _findUtilJs.formatPath)(path, joined),
|
|
194
|
+
haystack
|
|
195
|
+
];
|
|
196
|
+
},
|
|
197
|
+
get entry () {
|
|
198
|
+
return kwargs.getEntry();
|
|
199
|
+
},
|
|
200
|
+
getIsMatch: function() {
|
|
201
|
+
return isMatch;
|
|
202
|
+
},
|
|
203
|
+
get isMatch () {
|
|
204
|
+
return kwargs.getIsMatch();
|
|
205
|
+
},
|
|
206
|
+
getMatchedBy: function() {
|
|
207
|
+
return (0, _findUtilJs.matchedBy)(searches);
|
|
208
|
+
},
|
|
209
|
+
get matchedBy () {
|
|
210
|
+
return kwargs.getMatchedBy();
|
|
211
|
+
},
|
|
212
|
+
getExcludedBy: function() {
|
|
213
|
+
return (0, _findUtilJs.excludedBy)(searches);
|
|
214
|
+
},
|
|
215
|
+
get excludedBy () {
|
|
216
|
+
return kwargs.getExcludedBy();
|
|
217
|
+
},
|
|
218
|
+
getTraversedBy: function() {
|
|
219
|
+
return (0, _findUtilJs.traversedBy)(searches);
|
|
220
|
+
},
|
|
221
|
+
get traversedBy () {
|
|
222
|
+
return kwargs.getTraversedBy();
|
|
223
|
+
},
|
|
224
|
+
getGproperty: function() {
|
|
225
|
+
return path[path.length - 2];
|
|
226
|
+
},
|
|
227
|
+
get gproperty () {
|
|
228
|
+
return kwargs.getGproperty();
|
|
229
|
+
},
|
|
230
|
+
getProperty: function() {
|
|
231
|
+
return path[path.length - 1];
|
|
232
|
+
},
|
|
233
|
+
get property () {
|
|
234
|
+
return kwargs.getProperty();
|
|
235
|
+
},
|
|
236
|
+
getGparent: function() {
|
|
237
|
+
return parents[parents.length - 2];
|
|
238
|
+
},
|
|
239
|
+
get gparent () {
|
|
240
|
+
return kwargs.getGparent();
|
|
241
|
+
},
|
|
242
|
+
getParent: function() {
|
|
243
|
+
return parents[parents.length - 1];
|
|
244
|
+
},
|
|
245
|
+
get parent () {
|
|
246
|
+
return kwargs.getParent();
|
|
247
|
+
},
|
|
248
|
+
getParents: function() {
|
|
249
|
+
return _toConsumableArray(parents).reverse();
|
|
250
|
+
},
|
|
251
|
+
get parents () {
|
|
252
|
+
return kwargs.getParents();
|
|
253
|
+
},
|
|
254
|
+
getIsCircular: function() {
|
|
255
|
+
return parents.includes(haystack);
|
|
256
|
+
},
|
|
257
|
+
get isCircular () {
|
|
258
|
+
return kwargs.getIsCircular();
|
|
259
|
+
},
|
|
260
|
+
getIsLeaf: function() {
|
|
261
|
+
return !_instanceof(haystack, Object);
|
|
262
|
+
},
|
|
263
|
+
get isLeaf () {
|
|
264
|
+
return kwargs.getIsLeaf();
|
|
265
|
+
},
|
|
266
|
+
getDepth: function() {
|
|
267
|
+
return path.length;
|
|
268
|
+
},
|
|
269
|
+
get depth () {
|
|
270
|
+
return kwargs.getDepth();
|
|
271
|
+
},
|
|
272
|
+
/* getResult: <defined-below> */ get result () {
|
|
273
|
+
return kwargs.getResult();
|
|
274
|
+
},
|
|
275
|
+
context: state.context
|
|
276
|
+
};
|
|
277
|
+
var result = (0, _findResultJs.default)(kwargs, ctx);
|
|
278
|
+
kwargs.getResult = function() {
|
|
279
|
+
return result.get();
|
|
280
|
+
};
|
|
281
|
+
if (ctx.useArraySelector || !Array.isArray(state.haystack)) {
|
|
282
|
+
var child = search_.get("");
|
|
283
|
+
if (child !== undefined) {
|
|
284
|
+
stack[1].push(child);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
do _loop();
|
|
288
|
+
while (stack.length !== 0);
|
|
289
|
+
state.result = result.get();
|
|
290
|
+
if (ctx.afterFn !== undefined) {
|
|
291
|
+
var r1 = ctx.afterFn(state);
|
|
292
|
+
if (r1 !== undefined) {
|
|
293
|
+
state.result = r1;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return state.result;
|
|
297
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
parseValue: function() {
|
|
13
|
+
return parseValue;
|
|
14
|
+
},
|
|
15
|
+
compileValue: function() {
|
|
16
|
+
return compileValue;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var _helperJs = require("../generic/helper.js");
|
|
20
|
+
var charsToEscape = [
|
|
21
|
+
"-",
|
|
22
|
+
"/",
|
|
23
|
+
"\\",
|
|
24
|
+
"^",
|
|
25
|
+
"$",
|
|
26
|
+
"*",
|
|
27
|
+
"+",
|
|
28
|
+
"?",
|
|
29
|
+
".",
|
|
30
|
+
"(",
|
|
31
|
+
")",
|
|
32
|
+
"|",
|
|
33
|
+
"[",
|
|
34
|
+
"]",
|
|
35
|
+
"{",
|
|
36
|
+
"}"
|
|
37
|
+
];
|
|
38
|
+
var parseValue = function(value) {
|
|
39
|
+
var regex = "";
|
|
40
|
+
var escaped = false;
|
|
41
|
+
var simple = true;
|
|
42
|
+
for(var idx = 0; idx < value.length; idx += 1){
|
|
43
|
+
var char = value[idx];
|
|
44
|
+
if (!escaped && char === "\\") {
|
|
45
|
+
escaped = true;
|
|
46
|
+
} else if (!escaped && char === "*") {
|
|
47
|
+
simple = false;
|
|
48
|
+
regex += ".*";
|
|
49
|
+
} else if (!escaped && char === "+") {
|
|
50
|
+
simple = false;
|
|
51
|
+
regex += ".+";
|
|
52
|
+
} else if (!escaped && char === "?") {
|
|
53
|
+
simple = false;
|
|
54
|
+
regex += ".";
|
|
55
|
+
} else {
|
|
56
|
+
if (charsToEscape.includes(char)) {
|
|
57
|
+
simple = false;
|
|
58
|
+
regex += "\\";
|
|
59
|
+
}
|
|
60
|
+
regex += char;
|
|
61
|
+
escaped = false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (simple) {
|
|
65
|
+
return {
|
|
66
|
+
test: function(v) {
|
|
67
|
+
return String(v) === regex;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (regex === ".+") {
|
|
72
|
+
return {
|
|
73
|
+
test: function(v) {
|
|
74
|
+
return v !== "";
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return new RegExp("^".concat(regex, "$"));
|
|
79
|
+
};
|
|
80
|
+
var compileValue = function(value) {
|
|
81
|
+
if ((value.startsWith("**(") || value.startsWith("++(")) && value.endsWith(")")) {
|
|
82
|
+
return (0, _helperJs.asRegex)(value.slice(3, -1));
|
|
83
|
+
}
|
|
84
|
+
if (value.startsWith("[(") && value.endsWith(")]")) {
|
|
85
|
+
return (0, _helperJs.asRegex)(value.slice(2, -2));
|
|
86
|
+
}
|
|
87
|
+
if (value.startsWith("(") && value.endsWith(")")) {
|
|
88
|
+
return (0, _helperJs.asRegex)(value.slice(1, -1));
|
|
89
|
+
}
|
|
90
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
91
|
+
return parseValue(value.slice(1, -1));
|
|
92
|
+
}
|
|
93
|
+
return parseValue(value);
|
|
94
|
+
};
|
package/lib/core/node.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Node", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Node;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _nodeUtilJs = require("./node-util.js");
|
|
12
|
+
function _classCallCheck(instance, Constructor) {
|
|
13
|
+
if (!(instance instanceof Constructor)) {
|
|
14
|
+
throw new TypeError("Cannot call a class as a function");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _defineProperties(target, props) {
|
|
18
|
+
for(var i = 0; i < props.length; i++){
|
|
19
|
+
var descriptor = props[i];
|
|
20
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
21
|
+
descriptor.configurable = true;
|
|
22
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
23
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
27
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
28
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
29
|
+
return Constructor;
|
|
30
|
+
}
|
|
31
|
+
var Node = /*#__PURE__*/ function() {
|
|
32
|
+
"use strict";
|
|
33
|
+
function Node(value, ctx) {
|
|
34
|
+
_classCallCheck(this, Node);
|
|
35
|
+
ctx.nodes.push(this);
|
|
36
|
+
this.value = value;
|
|
37
|
+
this.ctx = ctx;
|
|
38
|
+
this.order = ctx.counter;
|
|
39
|
+
this.children = [];
|
|
40
|
+
this.match = false;
|
|
41
|
+
this.matches = false;
|
|
42
|
+
this.needles = [];
|
|
43
|
+
this.leafNeedles = [];
|
|
44
|
+
this.leafNeedlesExclude = [];
|
|
45
|
+
this.leafNeedlesMatch = [];
|
|
46
|
+
this.isArrayTarget = value.startsWith("[") && value.endsWith("]");
|
|
47
|
+
this.isSimpleStarRec = value === "**";
|
|
48
|
+
this.isSimplePlusRec = value === "++";
|
|
49
|
+
this.isSimpleRec = this.isSimpleStarRec || this.isSimplePlusRec;
|
|
50
|
+
this.isRegexStarRec = value.startsWith("**(") && value.endsWith(")");
|
|
51
|
+
this.isRegexPlusRec = value.startsWith("++(") && value.endsWith(")");
|
|
52
|
+
this.isStarRec = this.isSimpleStarRec || this.isRegexStarRec;
|
|
53
|
+
this.isPlusRec = this.isSimplePlusRec || this.isRegexPlusRec;
|
|
54
|
+
this.isRec = this.isStarRec || this.isPlusRec;
|
|
55
|
+
this.isAnyArrayTarget = value === "[*]";
|
|
56
|
+
this.isAnyObjTarget = value === "*";
|
|
57
|
+
if (this.isSimpleRec || this.isAnyObjTarget || this.isAnyArrayTarget) {
|
|
58
|
+
this.regex = null;
|
|
59
|
+
} else {
|
|
60
|
+
var regex = ctx.regex;
|
|
61
|
+
if (!(value in regex)) {
|
|
62
|
+
regex[value] = (0, _nodeUtilJs.compileValue)(value);
|
|
63
|
+
}
|
|
64
|
+
this.regex = regex[value];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
_createClass(Node, [
|
|
68
|
+
{
|
|
69
|
+
key: "recMatch",
|
|
70
|
+
value: function recMatch(key) {
|
|
71
|
+
if (!this.isRec) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (this.isSimpleRec) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return this.regex.test(key);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
key: "typeMatch",
|
|
82
|
+
value: function typeMatch(key, isArray) {
|
|
83
|
+
if (this.isSimpleRec) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (this.isAnyArrayTarget) {
|
|
87
|
+
return isArray;
|
|
88
|
+
}
|
|
89
|
+
if (this.isAnyObjTarget) {
|
|
90
|
+
return !isArray;
|
|
91
|
+
}
|
|
92
|
+
if (isArray !== this.isArrayTarget && !this.isRec) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return this.regex.test(key);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
key: "add",
|
|
100
|
+
value: function add(v) {
|
|
101
|
+
this.children.push(v);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
key: "get",
|
|
106
|
+
value: function get(k) {
|
|
107
|
+
return this.children.find(function(param) {
|
|
108
|
+
var value = param.value;
|
|
109
|
+
return value === k;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
key: "markMatches",
|
|
115
|
+
value: function markMatches() {
|
|
116
|
+
this.matches = true;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
key: "addNeedle",
|
|
121
|
+
value: function addNeedle(needle) {
|
|
122
|
+
if (!this.needles.includes(needle)) {
|
|
123
|
+
this.needles.push(needle);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
key: "setRoots",
|
|
129
|
+
value: function setRoots(roots) {
|
|
130
|
+
this.roots = roots;
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
key: "finish",
|
|
135
|
+
value: function finish(needle, excluded, index) {
|
|
136
|
+
this.addNeedle(needle);
|
|
137
|
+
if (!this.leafNeedles.includes(needle)) {
|
|
138
|
+
this.leafNeedles.push(needle);
|
|
139
|
+
}
|
|
140
|
+
var target = excluded ? this.leafNeedlesExclude : this.leafNeedlesMatch;
|
|
141
|
+
if (!target.includes(needle)) {
|
|
142
|
+
target.push(needle);
|
|
143
|
+
}
|
|
144
|
+
this.match = !excluded;
|
|
145
|
+
this.matches = this.match;
|
|
146
|
+
this.index = index;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
]);
|
|
150
|
+
return Node;
|
|
151
|
+
}();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Ref", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Ref;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function _classCallCheck(instance, Constructor) {
|
|
12
|
+
if (!(instance instanceof Constructor)) {
|
|
13
|
+
throw new TypeError("Cannot call a class as a function");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _defineProperties(target, props) {
|
|
17
|
+
for(var i = 0; i < props.length; i++){
|
|
18
|
+
var descriptor = props[i];
|
|
19
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
20
|
+
descriptor.configurable = true;
|
|
21
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
22
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
26
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
27
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
28
|
+
return Constructor;
|
|
29
|
+
}
|
|
30
|
+
var Ref = /*#__PURE__*/ function() {
|
|
31
|
+
"use strict";
|
|
32
|
+
function Ref(type) {
|
|
33
|
+
var link = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
|
|
34
|
+
_classCallCheck(this, Ref);
|
|
35
|
+
this.left = link === null;
|
|
36
|
+
this.link = link === null ? new Ref(type, this) : link;
|
|
37
|
+
this.type = type;
|
|
38
|
+
this.isStarRec = this.type === "**";
|
|
39
|
+
this.node = null;
|
|
40
|
+
this.pointer = null;
|
|
41
|
+
}
|
|
42
|
+
_createClass(Ref, [
|
|
43
|
+
{
|
|
44
|
+
key: "setPointer",
|
|
45
|
+
value: function setPointer(pointer) {
|
|
46
|
+
this.pointer = pointer;
|
|
47
|
+
this.link.pointer = pointer;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
key: "setNode",
|
|
52
|
+
value: function setNode(node) {
|
|
53
|
+
this.node = node;
|
|
54
|
+
this.link.node = node;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
]);
|
|
58
|
+
return Ref;
|
|
59
|
+
}();
|