@blackglory/match 0.3.6 → 0.4.0
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/README.md +21 -32
- package/lib/index.d.ts +17 -17
- package/lib/index.js +17 -37
- package/lib/index.js.map +1 -1
- package/lib/match-element.d.ts +1 -1
- package/lib/match-element.js +7 -11
- package/lib/match-element.js.map +1 -1
- package/lib/match.d.ts +1 -1
- package/lib/match.js +7 -11
- package/lib/match.js.map +1 -1
- package/lib/matchers/any-of.d.ts +1 -1
- package/lib/matchers/any-of.js +1 -5
- package/lib/matchers/any-of.js.map +1 -1
- package/lib/matchers/child-nodes.d.ts +1 -1
- package/lib/matchers/child-nodes.js +8 -11
- package/lib/matchers/child-nodes.js.map +1 -1
- package/lib/matchers/children.d.ts +1 -1
- package/lib/matchers/children.js +8 -11
- package/lib/matchers/children.js.map +1 -1
- package/lib/matchers/css.d.ts +1 -1
- package/lib/matchers/css.js +5 -9
- package/lib/matchers/css.js.map +1 -1
- package/lib/matchers/element.d.ts +1 -1
- package/lib/matchers/element.js +10 -14
- package/lib/matchers/element.js.map +1 -1
- package/lib/matchers/multiple.d.ts +1 -1
- package/lib/matchers/multiple.js +14 -17
- package/lib/matchers/multiple.js.map +1 -1
- package/lib/matchers/node.d.ts +1 -1
- package/lib/matchers/node.js +8 -12
- package/lib/matchers/node.js.map +1 -1
- package/lib/matchers/optional.d.ts +1 -1
- package/lib/matchers/optional.js +3 -7
- package/lib/matchers/optional.js.map +1 -1
- package/lib/matchers/repeat.d.ts +1 -1
- package/lib/matchers/repeat.js +6 -10
- package/lib/matchers/repeat.js.map +1 -1
- package/lib/matchers/tap.d.ts +1 -1
- package/lib/matchers/tap.js +1 -5
- package/lib/matchers/tap.js.map +1 -1
- package/lib/matchers/text-content-equals.d.ts +1 -1
- package/lib/matchers/text-content-equals.js +3 -7
- package/lib/matchers/text-content-equals.js.map +1 -1
- package/lib/matchers/text-content-includes.d.ts +1 -1
- package/lib/matchers/text-content-includes.js +3 -7
- package/lib/matchers/text-content-includes.js.map +1 -1
- package/lib/matchers/text-content-matches.d.ts +1 -1
- package/lib/matchers/text-content-matches.js +3 -7
- package/lib/matchers/text-content-matches.js.map +1 -1
- package/lib/matchers/text-node.d.ts +1 -1
- package/lib/matchers/text-node.js +10 -14
- package/lib/matchers/text-node.js.map +1 -1
- package/lib/matchers/xpath.d.ts +1 -1
- package/lib/matchers/xpath.js +7 -11
- package/lib/matchers/xpath.js.map +1 -1
- package/lib/types.d.ts +4 -4
- package/lib/types.js +1 -2
- package/lib/utils/concat.js +1 -5
- package/lib/utils/concat.js.map +1 -1
- package/lib/utils/match-multiple.d.ts +4 -1
- package/lib/utils/match-multiple.js +6 -7
- package/lib/utils/match-multiple.js.map +1 -1
- package/lib/utils/match-one-by-one.d.ts +1 -1
- package/lib/utils/match-one-by-one.js +9 -9
- package/lib/utils/match-one-by-one.js.map +1 -1
- package/lib/utils/merge-in-place.d.ts +1 -5
- package/lib/utils/merge-in-place.js +5 -9
- package/lib/utils/merge-in-place.js.map +1 -1
- package/lib/utils/next-element-sibling.js +2 -6
- package/lib/utils/next-element-sibling.js.map +1 -1
- package/lib/utils/next-sibling.js +2 -6
- package/lib/utils/next-sibling.js.map +1 -1
- package/package.json +30 -29
- package/src/index.ts +17 -17
- package/src/match-element.ts +3 -3
- package/src/match.ts +3 -3
- package/src/matchers/any-of.ts +1 -1
- package/src/matchers/child-nodes.ts +4 -4
- package/src/matchers/children.ts +4 -4
- package/src/matchers/css.ts +3 -3
- package/src/matchers/element.ts +4 -4
- package/src/matchers/multiple.ts +3 -3
- package/src/matchers/node.ts +4 -4
- package/src/matchers/optional.ts +2 -2
- package/src/matchers/repeat.ts +3 -3
- package/src/matchers/tap.ts +1 -1
- package/src/matchers/text-content-equals.ts +2 -2
- package/src/matchers/text-content-includes.ts +2 -2
- package/src/matchers/text-content-matches.ts +2 -2
- package/src/matchers/text-node.ts +4 -4
- package/src/matchers/xpath.ts +4 -4
- package/src/utils/match-multiple.ts +1 -1
- package/src/utils/match-one-by-one.ts +2 -2
- package/src/utils/merge-in-place.ts +3 -3
package/README.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# match
|
|
2
|
-
|
|
3
2
|
A module for matching elements from pages.
|
|
4
3
|
|
|
5
4
|
## Install
|
|
6
|
-
|
|
7
5
|
```sh
|
|
8
6
|
npm install --save @blackglory/match
|
|
9
7
|
# or
|
|
@@ -11,11 +9,11 @@ yarn add @blackglory/match
|
|
|
11
9
|
```
|
|
12
10
|
|
|
13
11
|
## Usage
|
|
14
|
-
|
|
15
12
|
```ts
|
|
16
13
|
import { matchElement, element, css, childNodes, textNode, children, multiple } from '@blackglory/match'
|
|
17
14
|
|
|
18
|
-
const result = matchElement(
|
|
15
|
+
const result = matchElement(
|
|
16
|
+
node
|
|
19
17
|
, element(
|
|
20
18
|
css`header`
|
|
21
19
|
, childNodes(
|
|
@@ -38,7 +36,6 @@ const result = matchElement(node
|
|
|
38
36
|
```
|
|
39
37
|
|
|
40
38
|
## API
|
|
41
|
-
|
|
42
39
|
```ts
|
|
43
40
|
interface IContext {
|
|
44
41
|
readonly document: Document
|
|
@@ -78,7 +75,6 @@ type ISkipMatcher<T extends Node> = (
|
|
|
78
75
|
```
|
|
79
76
|
|
|
80
77
|
### match
|
|
81
|
-
|
|
82
78
|
```ts
|
|
83
79
|
function match(
|
|
84
80
|
this: void | Document
|
|
@@ -88,7 +84,6 @@ function match(
|
|
|
88
84
|
```
|
|
89
85
|
|
|
90
86
|
### matchElement
|
|
91
|
-
|
|
92
87
|
```ts
|
|
93
88
|
function matchElement(
|
|
94
89
|
this: void | Document
|
|
@@ -98,9 +93,7 @@ function matchElement(
|
|
|
98
93
|
```
|
|
99
94
|
|
|
100
95
|
### Matchers
|
|
101
|
-
|
|
102
96
|
#### anyOf
|
|
103
|
-
|
|
104
97
|
```ts
|
|
105
98
|
function anyOf<T extends Node>(
|
|
106
99
|
...matchers: [
|
|
@@ -112,39 +105,42 @@ function anyOf<T extends Node>(
|
|
|
112
105
|
```
|
|
113
106
|
|
|
114
107
|
#### childNodes
|
|
115
|
-
|
|
116
108
|
```ts
|
|
117
109
|
function childNodes(...matchers: Array<IMatcher<Node>>): INestedMatcher<Node>
|
|
118
110
|
```
|
|
119
111
|
|
|
120
112
|
#### children
|
|
121
|
-
|
|
122
113
|
```ts
|
|
123
114
|
function children(...matchers: Array<IMatcher<Element>>): INestedMatcher<Element>
|
|
124
115
|
```
|
|
125
116
|
|
|
126
117
|
#### css
|
|
127
|
-
|
|
128
118
|
```ts
|
|
129
|
-
function css(
|
|
119
|
+
function css(
|
|
120
|
+
strings: TemplateStringsArray
|
|
121
|
+
, ...values: string[]
|
|
122
|
+
): ITerminalMatcher<Element>
|
|
130
123
|
function css(selector: string): ITerminalMatcher<Element>
|
|
131
124
|
```
|
|
132
125
|
|
|
133
126
|
#### element
|
|
134
|
-
|
|
135
127
|
```ts
|
|
136
128
|
function element(
|
|
137
129
|
strings: TemplateStringsArray
|
|
138
130
|
, ...values: string[]
|
|
139
|
-
): (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
function element(
|
|
143
|
-
|
|
131
|
+
): (
|
|
132
|
+
...matchers: Array<INestedMatcher<Element> | ITerminalMatcher<Element>>
|
|
133
|
+
) => INestedMatcher<Node>
|
|
134
|
+
function element(
|
|
135
|
+
name: string
|
|
136
|
+
, ...matchers: Array<INestedMatcher<Element>>
|
|
137
|
+
): INestedMatcher<Node>
|
|
138
|
+
function element(
|
|
139
|
+
...matchers: Array<INestedMatcher<Element>>
|
|
140
|
+
): INestedMatcher<Node>
|
|
144
141
|
```
|
|
145
142
|
|
|
146
143
|
#### multiple
|
|
147
|
-
|
|
148
144
|
```ts
|
|
149
145
|
interface IMultipleOptions {
|
|
150
146
|
greedy: boolean
|
|
@@ -158,12 +154,13 @@ function multiple<T extends Node>(
|
|
|
158
154
|
```
|
|
159
155
|
|
|
160
156
|
#### node
|
|
161
|
-
|
|
162
157
|
```ts
|
|
163
158
|
function node(
|
|
164
159
|
strings: TemplateStringsArray
|
|
165
160
|
, ...values: string[]
|
|
166
|
-
): (
|
|
161
|
+
): (
|
|
162
|
+
...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>
|
|
163
|
+
) => INestedMatcher<Node>
|
|
167
164
|
function node(
|
|
168
165
|
name: string
|
|
169
166
|
, ...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>
|
|
@@ -174,7 +171,6 @@ function node(
|
|
|
174
171
|
```
|
|
175
172
|
|
|
176
173
|
#### optional
|
|
177
|
-
|
|
178
174
|
```ts
|
|
179
175
|
function optional<T extends Node>(
|
|
180
176
|
matcher: INestedMatcher<T> | ITerminalMatcher<T>
|
|
@@ -182,7 +178,6 @@ function optional<T extends Node>(
|
|
|
182
178
|
```
|
|
183
179
|
|
|
184
180
|
#### repeat
|
|
185
|
-
|
|
186
181
|
```ts
|
|
187
182
|
function repeat<T extends Node>(
|
|
188
183
|
times: number
|
|
@@ -191,7 +186,6 @@ function repeat<T extends Node>(
|
|
|
191
186
|
```
|
|
192
187
|
|
|
193
188
|
#### tap
|
|
194
|
-
|
|
195
189
|
```ts
|
|
196
190
|
function tap<T extends Node, U extends ReturnType<IMatcher<any>>>(
|
|
197
191
|
matcher: (this: IReadonlyContext, node: T) => U
|
|
@@ -200,7 +194,6 @@ function tap<T extends Node, U extends ReturnType<IMatcher<any>>>(
|
|
|
200
194
|
```
|
|
201
195
|
|
|
202
196
|
#### textContentEquals
|
|
203
|
-
|
|
204
197
|
```ts
|
|
205
198
|
interface ITextContentEqualsOptions {
|
|
206
199
|
caseSensitive?: boolean
|
|
@@ -217,14 +210,13 @@ function textContentEquals(
|
|
|
217
210
|
```
|
|
218
211
|
|
|
219
212
|
#### textContentIncludes
|
|
220
|
-
|
|
221
213
|
```ts
|
|
222
214
|
interface ITextContentIncludesOptions {
|
|
223
215
|
caseSensitive?: boolean
|
|
224
216
|
trim?: boolean
|
|
225
217
|
}
|
|
226
218
|
|
|
227
|
-
|
|
219
|
+
function textContentIncludes(
|
|
228
220
|
searchString: string
|
|
229
221
|
, {
|
|
230
222
|
caseSensitive = true
|
|
@@ -234,20 +226,18 @@ export function textContentIncludes(
|
|
|
234
226
|
```
|
|
235
227
|
|
|
236
228
|
#### textContentMatches
|
|
237
|
-
|
|
238
229
|
```ts
|
|
239
230
|
interface ITextContentMatchesOptions {
|
|
240
231
|
trim?: boolean
|
|
241
232
|
}
|
|
242
233
|
|
|
243
|
-
|
|
234
|
+
function textContentMatches(
|
|
244
235
|
pattern: RegExp
|
|
245
236
|
, { trim = false }: ITextContentMatchesOptions = {}
|
|
246
237
|
): ITerminalMatcher<Node>
|
|
247
238
|
```
|
|
248
239
|
|
|
249
240
|
#### textNode
|
|
250
|
-
|
|
251
241
|
```ts
|
|
252
242
|
function textNode(
|
|
253
243
|
strings: TemplateStringsArray
|
|
@@ -263,7 +253,6 @@ function textNode(
|
|
|
263
253
|
```
|
|
264
254
|
|
|
265
255
|
#### xpath
|
|
266
|
-
|
|
267
256
|
```ts
|
|
268
257
|
function xpath(
|
|
269
258
|
strings: TemplateStringsArray
|
package/lib/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export { match } from './match';
|
|
2
|
-
export { matchElement } from './match-element';
|
|
3
|
-
export { anyOf } from
|
|
4
|
-
export { childNodes } from
|
|
5
|
-
export { children } from
|
|
6
|
-
export { css } from
|
|
7
|
-
export { element } from
|
|
8
|
-
export { multiple } from
|
|
9
|
-
export { node } from
|
|
10
|
-
export { optional } from
|
|
11
|
-
export { repeat } from
|
|
12
|
-
export { tap } from
|
|
13
|
-
export { textContentEquals } from
|
|
14
|
-
export { textContentIncludes } from
|
|
15
|
-
export { textContentMatches } from
|
|
16
|
-
export { textNode } from
|
|
17
|
-
export { xpath } from
|
|
1
|
+
export { match } from './match.js';
|
|
2
|
+
export { matchElement } from './match-element.js';
|
|
3
|
+
export { anyOf } from "./matchers/any-of.js";
|
|
4
|
+
export { childNodes } from "./matchers/child-nodes.js";
|
|
5
|
+
export { children } from "./matchers/children.js";
|
|
6
|
+
export { css } from "./matchers/css.js";
|
|
7
|
+
export { element } from "./matchers/element.js";
|
|
8
|
+
export { multiple } from "./matchers/multiple.js";
|
|
9
|
+
export { node } from "./matchers/node.js";
|
|
10
|
+
export { optional } from "./matchers/optional.js";
|
|
11
|
+
export { repeat } from "./matchers/repeat.js";
|
|
12
|
+
export { tap } from "./matchers/tap.js";
|
|
13
|
+
export { textContentEquals } from "./matchers/text-content-equals.js";
|
|
14
|
+
export { textContentIncludes } from "./matchers/text-content-includes.js";
|
|
15
|
+
export { textContentMatches } from "./matchers/text-content-matches.js";
|
|
16
|
+
export { textNode } from "./matchers/text-node.js";
|
|
17
|
+
export { xpath } from "./matchers/xpath.js";
|
package/lib/index.js
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var multiple_1 = require("./matchers/multiple");
|
|
19
|
-
Object.defineProperty(exports, "multiple", { enumerable: true, get: function () { return multiple_1.multiple; } });
|
|
20
|
-
var node_1 = require("./matchers/node");
|
|
21
|
-
Object.defineProperty(exports, "node", { enumerable: true, get: function () { return node_1.node; } });
|
|
22
|
-
var optional_1 = require("./matchers/optional");
|
|
23
|
-
Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return optional_1.optional; } });
|
|
24
|
-
var repeat_1 = require("./matchers/repeat");
|
|
25
|
-
Object.defineProperty(exports, "repeat", { enumerable: true, get: function () { return repeat_1.repeat; } });
|
|
26
|
-
var tap_1 = require("./matchers/tap");
|
|
27
|
-
Object.defineProperty(exports, "tap", { enumerable: true, get: function () { return tap_1.tap; } });
|
|
28
|
-
var text_content_equals_1 = require("./matchers/text-content-equals");
|
|
29
|
-
Object.defineProperty(exports, "textContentEquals", { enumerable: true, get: function () { return text_content_equals_1.textContentEquals; } });
|
|
30
|
-
var text_content_includes_1 = require("./matchers/text-content-includes");
|
|
31
|
-
Object.defineProperty(exports, "textContentIncludes", { enumerable: true, get: function () { return text_content_includes_1.textContentIncludes; } });
|
|
32
|
-
var text_content_matches_1 = require("./matchers/text-content-matches");
|
|
33
|
-
Object.defineProperty(exports, "textContentMatches", { enumerable: true, get: function () { return text_content_matches_1.textContentMatches; } });
|
|
34
|
-
var text_node_1 = require("./matchers/text-node");
|
|
35
|
-
Object.defineProperty(exports, "textNode", { enumerable: true, get: function () { return text_node_1.textNode; } });
|
|
36
|
-
var xpath_1 = require("./matchers/xpath");
|
|
37
|
-
Object.defineProperty(exports, "xpath", { enumerable: true, get: function () { return xpath_1.xpath; } });
|
|
1
|
+
export { match } from './match.js';
|
|
2
|
+
export { matchElement } from './match-element.js';
|
|
3
|
+
export { anyOf } from "./matchers/any-of.js";
|
|
4
|
+
export { childNodes } from "./matchers/child-nodes.js";
|
|
5
|
+
export { children } from "./matchers/children.js";
|
|
6
|
+
export { css } from "./matchers/css.js";
|
|
7
|
+
export { element } from "./matchers/element.js";
|
|
8
|
+
export { multiple } from "./matchers/multiple.js";
|
|
9
|
+
export { node } from "./matchers/node.js";
|
|
10
|
+
export { optional } from "./matchers/optional.js";
|
|
11
|
+
export { repeat } from "./matchers/repeat.js";
|
|
12
|
+
export { tap } from "./matchers/tap.js";
|
|
13
|
+
export { textContentEquals } from "./matchers/text-content-equals.js";
|
|
14
|
+
export { textContentIncludes } from "./matchers/text-content-includes.js";
|
|
15
|
+
export { textContentMatches } from "./matchers/text-content-matches.js";
|
|
16
|
+
export { textNode } from "./matchers/text-node.js";
|
|
17
|
+
export { xpath } from "./matchers/xpath.js";
|
|
38
18
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,KAAK,EAAE,6BAA2B;AAC3C,OAAO,EAAE,UAAU,EAAE,kCAAgC;AACrD,OAAO,EAAE,QAAQ,EAAE,+BAA6B;AAChD,OAAO,EAAE,GAAG,EAAE,0BAAwB;AACtC,OAAO,EAAE,OAAO,EAAE,8BAA4B;AAC9C,OAAO,EAAE,QAAQ,EAAE,+BAA6B;AAChD,OAAO,EAAE,IAAI,EAAE,2BAAyB;AACxC,OAAO,EAAE,QAAQ,EAAE,+BAA6B;AAChD,OAAO,EAAE,MAAM,EAAE,6BAA2B;AAC5C,OAAO,EAAE,GAAG,EAAE,0BAAwB;AACtC,OAAO,EAAE,iBAAiB,EAAE,0CAAwC;AACpE,OAAO,EAAE,mBAAmB,EAAE,4CAA0C;AACxE,OAAO,EAAE,kBAAkB,EAAE,2CAAyC;AACtE,OAAO,EAAE,QAAQ,EAAE,gCAA8B;AACjD,OAAO,EAAE,KAAK,EAAE,4BAA0B"}
|
package/lib/match-element.d.ts
CHANGED
package/lib/match-element.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const next_element_sibling_1 = require("./utils/next-element-sibling");
|
|
7
|
-
function matchElement(element, ...matchers) {
|
|
8
|
-
const document = (0, extra_dom_1.isDocument)(this) ? this : globalThis.document;
|
|
1
|
+
import { isDocument } from 'extra-dom';
|
|
2
|
+
import { matchOneByOne } from "./utils/match-one-by-one.js";
|
|
3
|
+
import { nextElementSibling } from "./utils/next-element-sibling.js";
|
|
4
|
+
export function matchElement(element, ...matchers) {
|
|
5
|
+
const document = isDocument(this) ? this : globalThis.document;
|
|
9
6
|
const context = {
|
|
10
7
|
document,
|
|
11
8
|
collection: {},
|
|
12
|
-
next:
|
|
9
|
+
next: nextElementSibling
|
|
13
10
|
};
|
|
14
|
-
if (
|
|
11
|
+
if (matchOneByOne(context, element, ...matchers)) {
|
|
15
12
|
return context.collection;
|
|
16
13
|
}
|
|
17
14
|
else {
|
|
18
15
|
return null;
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
exports.matchElement = matchElement;
|
|
22
18
|
//# sourceMappingURL=match-element.js.map
|
package/lib/match-element.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match-element.js","sourceRoot":"","sources":["../src/match-element.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"match-element.js","sourceRoot":"","sources":["../src/match-element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE,oCAAkC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,wCAAsC;AAEnE,MAAM,UAAU,YAAY,CAE1B,OAAgB,EAChB,GAAG,QAAkC;IAErC,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAA;IAC9D,MAAM,OAAO,GAAa;QACxB,QAAQ;QACR,UAAU,EAAE,EAAE;QACd,IAAI,EAAE,kBAAkB;KACzB,CAAA;IAED,IAAI,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC;QACjD,OAAO,OAAO,CAAC,UAAU,CAAA;IAC3B,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
package/lib/match.d.ts
CHANGED
package/lib/match.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const next_sibling_1 = require("./utils/next-sibling");
|
|
7
|
-
function match(node, ...matchers) {
|
|
8
|
-
const document = (0, extra_dom_1.isDocument)(this) ? this : globalThis.document;
|
|
1
|
+
import { isDocument } from 'extra-dom';
|
|
2
|
+
import { matchOneByOne } from "./utils/match-one-by-one.js";
|
|
3
|
+
import { nextSibling } from "./utils/next-sibling.js";
|
|
4
|
+
export function match(node, ...matchers) {
|
|
5
|
+
const document = isDocument(this) ? this : globalThis.document;
|
|
9
6
|
const context = {
|
|
10
7
|
document,
|
|
11
8
|
collection: {},
|
|
12
|
-
next:
|
|
9
|
+
next: nextSibling
|
|
13
10
|
};
|
|
14
|
-
if (
|
|
11
|
+
if (matchOneByOne(context, node, ...matchers)) {
|
|
15
12
|
return context.collection;
|
|
16
13
|
}
|
|
17
14
|
else {
|
|
18
15
|
return null;
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
exports.match = match;
|
|
22
18
|
//# sourceMappingURL=match.js.map
|
package/lib/match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","sourceRoot":"","sources":["../src/match.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"match.js","sourceRoot":"","sources":["../src/match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE,oCAAkC;AAC1D,OAAO,EAAE,WAAW,EAAE,gCAA8B;AAEpD,MAAM,UAAU,KAAK,CAEnB,IAAU,EACV,GAAG,QAA+B;IAElC,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAA;IAC9D,MAAM,OAAO,GAAa;QACxB,QAAQ;QACR,UAAU,EAAE,EAAE;QACd,IAAI,EAAE,WAAW;KAClB,CAAA;IAED,IAAI,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC;QAC9C,OAAO,OAAO,CAAC,UAAU,CAAA;IAC3B,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
package/lib/matchers/any-of.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ITerminalMatcher, INestedMatcher } from
|
|
1
|
+
import { ITerminalMatcher, INestedMatcher } from "../types.js";
|
|
2
2
|
export declare function anyOf<T extends Node>(...matchers: [
|
|
3
3
|
INestedMatcher<T> | ITerminalMatcher<T>,
|
|
4
4
|
INestedMatcher<T> | ITerminalMatcher<T>,
|
package/lib/matchers/any-of.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.anyOf = void 0;
|
|
4
|
-
function anyOf(...matchers) {
|
|
1
|
+
export function anyOf(...matchers) {
|
|
5
2
|
return function (node) {
|
|
6
3
|
return matchers.some(match => match.call(this, node));
|
|
7
4
|
};
|
|
8
5
|
}
|
|
9
|
-
exports.anyOf = anyOf;
|
|
10
6
|
//# sourceMappingURL=any-of.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"any-of.js","sourceRoot":"","sources":["../../src/matchers/any-of.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"any-of.js","sourceRoot":"","sources":["../../src/matchers/any-of.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,KAAK,CACnB,GAAG,QAIF;IAED,OAAO,UAAkC,IAAO;QAC9C,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;IACvD,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { INestedMatcher, IMatcher } from
|
|
1
|
+
import { INestedMatcher, IMatcher } from "../types.js";
|
|
2
2
|
export declare function childNodes(...matchers: Array<IMatcher<Node>>): INestedMatcher<Node>;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const merge_in_place_1 = require("../utils/merge-in-place");
|
|
6
|
-
const next_sibling_1 = require("../utils/next-sibling");
|
|
7
|
-
function childNodes(...matchers) {
|
|
1
|
+
import { matchOneByOne } from "../utils/match-one-by-one.js";
|
|
2
|
+
import { mergeInPlace } from "../utils/merge-in-place.js";
|
|
3
|
+
import { nextSibling } from "../utils/next-sibling.js";
|
|
4
|
+
export function childNodes(...matchers) {
|
|
8
5
|
return function (node) {
|
|
6
|
+
// 空matchers意味着"childNodes应该为空".
|
|
9
7
|
if (matchers.length === 0) {
|
|
10
8
|
return node.childNodes.length === 0;
|
|
11
9
|
}
|
|
@@ -14,14 +12,13 @@ function childNodes(...matchers) {
|
|
|
14
12
|
const context = {
|
|
15
13
|
...this,
|
|
16
14
|
collection: {},
|
|
17
|
-
next:
|
|
15
|
+
next: nextSibling
|
|
18
16
|
};
|
|
19
|
-
const result =
|
|
17
|
+
const result = matchOneByOne(context, node.childNodes[0], ...matchers);
|
|
20
18
|
if (result) {
|
|
21
|
-
|
|
19
|
+
mergeInPlace(this.collection, context.collection);
|
|
22
20
|
}
|
|
23
21
|
return result;
|
|
24
22
|
};
|
|
25
23
|
}
|
|
26
|
-
exports.childNodes = childNodes;
|
|
27
24
|
//# sourceMappingURL=child-nodes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"child-nodes.js","sourceRoot":"","sources":["../../src/matchers/child-nodes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"child-nodes.js","sourceRoot":"","sources":["../../src/matchers/child-nodes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,qCAAkC;AAC1D,OAAO,EAAE,YAAY,EAAE,mCAAgC;AACvD,OAAO,EAAE,WAAW,EAAE,iCAA8B;AAEpD,MAAM,UAAU,UAAU,CAAC,GAAG,QAA+B;IAC3D,OAAO,UAAkC,IAAU;QACjD,gCAAgC;QAChC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAA;QACrC,CAAC;QAED,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QAE9C,MAAM,OAAO,GAAqB;YAChC,GAAG,IAAI;YACP,UAAU,EAAE,EAAE;YACd,IAAI,EAAE,WAAW;SAClB,CAAA;QAED,MAAM,MAAM,GAAG,aAAa,CAC1B,OAAO,EACP,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAClB,GAAG,QAAQ,CACZ,CAAA;QAED,IAAI,MAAM,EAAE,CAAC;YACX,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IMatcher, INestedMatcher } from
|
|
1
|
+
import { IMatcher, INestedMatcher } from "../types.js";
|
|
2
2
|
export declare function children(...matchers: Array<IMatcher<Element>>): INestedMatcher<Element>;
|
package/lib/matchers/children.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const merge_in_place_1 = require("../utils/merge-in-place");
|
|
6
|
-
const next_element_sibling_1 = require("../utils/next-element-sibling");
|
|
7
|
-
function children(...matchers) {
|
|
1
|
+
import { matchOneByOne } from "../utils/match-one-by-one.js";
|
|
2
|
+
import { mergeInPlace } from "../utils/merge-in-place.js";
|
|
3
|
+
import { nextElementSibling } from "../utils/next-element-sibling.js";
|
|
4
|
+
export function children(...matchers) {
|
|
8
5
|
return function (element) {
|
|
6
|
+
// 空matchers意味着"children应该为空".
|
|
9
7
|
if (matchers.length === 0) {
|
|
10
8
|
return element.children.length === 0;
|
|
11
9
|
}
|
|
@@ -14,14 +12,13 @@ function children(...matchers) {
|
|
|
14
12
|
const context = {
|
|
15
13
|
...this,
|
|
16
14
|
collection: {},
|
|
17
|
-
next:
|
|
15
|
+
next: nextElementSibling
|
|
18
16
|
};
|
|
19
|
-
const result =
|
|
17
|
+
const result = matchOneByOne(context, element.children[0], ...matchers);
|
|
20
18
|
if (result) {
|
|
21
|
-
|
|
19
|
+
mergeInPlace(this.collection, context.collection);
|
|
22
20
|
}
|
|
23
21
|
return result;
|
|
24
22
|
};
|
|
25
23
|
}
|
|
26
|
-
exports.children = children;
|
|
27
24
|
//# sourceMappingURL=children.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"children.js","sourceRoot":"","sources":["../../src/matchers/children.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"children.js","sourceRoot":"","sources":["../../src/matchers/children.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,qCAAkC;AAC1D,OAAO,EAAE,YAAY,EAAE,mCAAgC;AACvD,OAAO,EAAE,kBAAkB,EAAE,yCAAsC;AAEnE,MAAM,UAAU,QAAQ,CACtB,GAAG,QAAkC;IAErC,OAAO,UAAkC,OAAgB;QACvD,8BAA8B;QAC9B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAA;QACtC,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QAE/C,MAAM,OAAO,GAAqB;YAChC,GAAG,IAAI;YACP,UAAU,EAAE,EAAE;YACd,IAAI,EAAE,kBAAkB;SACzB,CAAA;QAED,MAAM,MAAM,GAAG,aAAa,CAC1B,OAAO,EACP,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EACnB,GAAG,QAAQ,CACZ,CAAA;QAED,IAAI,MAAM,EAAE,CAAC;YACX,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
package/lib/matchers/css.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ITerminalMatcher } from
|
|
1
|
+
import { ITerminalMatcher } from "../types.js";
|
|
2
2
|
export declare function css(strings: TemplateStringsArray, ...values: string[]): ITerminalMatcher<Element>;
|
|
3
3
|
export declare function css(selector: string): ITerminalMatcher<Element>;
|
package/lib/matchers/css.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const types_1 = require("@blackglory/types");
|
|
6
|
-
function css(...args) {
|
|
7
|
-
if ((0, types_1.isString)(args[0])) {
|
|
1
|
+
import { concat } from "../utils/concat.js";
|
|
2
|
+
import { isString } from '@blackglory/prelude';
|
|
3
|
+
export function css(...args) {
|
|
4
|
+
if (isString(args[0])) {
|
|
8
5
|
const [selector] = args;
|
|
9
6
|
return (element) => element.matches(selector);
|
|
10
7
|
}
|
|
11
8
|
else {
|
|
12
9
|
const [strings, ...values] = args;
|
|
13
|
-
const selector =
|
|
10
|
+
const selector = concat(strings, values).join('');
|
|
14
11
|
return css(selector);
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
|
-
exports.css = css;
|
|
18
14
|
//# sourceMappingURL=css.js.map
|
package/lib/matchers/css.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.js","sourceRoot":"","sources":["../../src/matchers/css.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"css.js","sourceRoot":"","sources":["../../src/matchers/css.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,2BAAwB;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAO9C,MAAM,UAAU,GAAG,CAAC,GAAG,IAE+B;IAEpD,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;QAEvB,OAAO,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACxD,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI,CAAA;QACjC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAEjD,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAA;IACtB,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INestedMatcher, ITerminalMatcher } from
|
|
1
|
+
import { INestedMatcher, ITerminalMatcher } from "../types.js";
|
|
2
2
|
export declare function element(strings: TemplateStringsArray, ...values: string[]): (...matchers: Array<INestedMatcher<Element> | ITerminalMatcher<Element>>) => INestedMatcher<Node>;
|
|
3
3
|
export declare function element(name: string, ...matchers: Array<INestedMatcher<Element>>): INestedMatcher<Node>;
|
|
4
4
|
export declare function element(...matchers: Array<INestedMatcher<Element>>): INestedMatcher<Node>;
|
package/lib/matchers/element.js
CHANGED
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const merge_in_place_1 = require("../utils/merge-in-place");
|
|
8
|
-
function element(...args) {
|
|
9
|
-
if ((0, types_1.isArray)(args[0])) {
|
|
1
|
+
import { isntElement } from 'extra-dom';
|
|
2
|
+
import { isArray, isString } from '@blackglory/prelude';
|
|
3
|
+
import { concat } from "../utils/concat.js";
|
|
4
|
+
import { mergeInPlace } from "../utils/merge-in-place.js";
|
|
5
|
+
export function element(...args) {
|
|
6
|
+
if (isArray(args[0])) {
|
|
10
7
|
const [strings, ...values] = args;
|
|
11
|
-
const name =
|
|
8
|
+
const name = concat(strings, values).join('');
|
|
12
9
|
return (...matchers) => element(name, ...matchers);
|
|
13
10
|
}
|
|
14
|
-
if (
|
|
11
|
+
if (isString(args[0])) {
|
|
15
12
|
const [name, ...matchers] = args;
|
|
16
13
|
return function (_element) {
|
|
17
14
|
const result = element(...matchers).call(this, _element);
|
|
18
15
|
if (result) {
|
|
19
|
-
|
|
16
|
+
mergeInPlace(this.collection, { [name]: _element });
|
|
20
17
|
}
|
|
21
18
|
return result;
|
|
22
19
|
};
|
|
23
20
|
}
|
|
24
21
|
const [...matchers] = args;
|
|
25
22
|
return function (element) {
|
|
26
|
-
if (
|
|
23
|
+
if (isntElement(element))
|
|
27
24
|
return false;
|
|
28
25
|
if (matchers.length === 0)
|
|
29
26
|
return true;
|
|
30
27
|
return matchers.every(match => match.call(this, element));
|
|
31
28
|
};
|
|
32
29
|
}
|
|
33
|
-
exports.element = element;
|
|
34
30
|
//# sourceMappingURL=element.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/matchers/element.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/matchers/element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,2BAAwB;AACzC,OAAO,EAAE,YAAY,EAAE,mCAAgC;AAUvD,MAAM,UAAU,OAAO,CAAC,GAAG,IAGgD;IAEzE,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,GACxB,IAA4D,CAAA;QAC9D,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAE7C,OAAO,CAAC,GAAG,QAAoE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAA;IAChH,CAAC;IAED,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,GACvB,IAA+F,CAAA;QAEjG,OAAO,UAAkC,QAAiB;YACxD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YACxD,IAAI,MAAM,EAAE,CAAC;gBACX,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;YACrD,CAAC;YACD,OAAO,MAAM,CAAA;QACf,CAAC,CAAA;IACH,CAAC;IAED,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,IAAiF,CAAA;IAEvG,OAAO,UAAkC,OAAgB;QACvD,IAAI,WAAW,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,CAAA;QACtC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QAEtC,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAA;IAC3D,CAAC,CAAA;AACH,CAAC"}
|