@blackglory/match 0.3.6 → 0.4.1
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 +86 -36
- 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 +3 -4
- package/lib/match-element.js +9 -11
- package/lib/match-element.js.map +1 -1
- package/lib/match.d.ts +3 -4
- package/lib/match.js +9 -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 +10 -12
- package/lib/matchers/child-nodes.js.map +1 -1
- package/lib/matchers/children.d.ts +1 -1
- package/lib/matchers/children.js +10 -12
- 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 +11 -15
- 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 +9 -13
- 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 +8 -12
- package/lib/matchers/xpath.js.map +1 -1
- package/lib/types.d.ts +7 -6
- package/lib/types.js +1 -2
- 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 +10 -10
- package/lib/utils/match-one-by-one.js.map +1 -1
- package/lib/utils/merge-in-place.d.ts +2 -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 +9 -5
- package/src/match.ts +9 -5
- package/src/matchers/any-of.ts +1 -1
- package/src/matchers/child-nodes.ts +6 -5
- package/src/matchers/children.ts +6 -5
- package/src/matchers/css.ts +4 -4
- package/src/matchers/element.ts +42 -17
- package/src/matchers/multiple.ts +3 -3
- package/src/matchers/node.ts +35 -13
- package/src/matchers/optional.ts +5 -3
- 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 +13 -9
- package/src/matchers/xpath.ts +10 -10
- package/src/types.ts +7 -4
- package/src/utils/match-multiple.ts +1 -1
- package/src/utils/match-one-by-one.ts +3 -3
- package/src/utils/merge-in-place.ts +3 -3
- package/lib/utils/concat.d.ts +0 -1
- package/lib/utils/concat.js +0 -14
- package/lib/utils/concat.js.map +0 -1
- package/src/utils/concat.ts +0 -9
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,63 @@ yarn add @blackglory/match
|
|
|
11
9
|
```
|
|
12
10
|
|
|
13
11
|
## Usage
|
|
14
|
-
|
|
12
|
+
### Match only
|
|
15
13
|
```ts
|
|
16
14
|
import { matchElement, element, css, childNodes, textNode, children, multiple } from '@blackglory/match'
|
|
15
|
+
import { parseNodes, getBySelector } from 'extra-dom'
|
|
16
|
+
|
|
17
|
+
const div = parseNodes(`
|
|
18
|
+
<div>
|
|
19
|
+
<header>Heading</header>
|
|
20
|
+
<article>
|
|
21
|
+
<p>Paragraph1</p>
|
|
22
|
+
<p>Paragraph2</p>
|
|
23
|
+
</article>
|
|
24
|
+
</div>
|
|
25
|
+
`.trim())[0] as Element
|
|
26
|
+
const header = getBySelector.call(div, 'header')
|
|
27
|
+
|
|
28
|
+
const result = matchElement(
|
|
29
|
+
header
|
|
30
|
+
, element(
|
|
31
|
+
css`header`
|
|
32
|
+
, childNodes(
|
|
33
|
+
textNode()
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
, element(
|
|
37
|
+
css`article`
|
|
38
|
+
, children(
|
|
39
|
+
multiple([1, Infinity], element(
|
|
40
|
+
css`p`
|
|
41
|
+
, childNodes(
|
|
42
|
+
textNode()
|
|
43
|
+
)
|
|
44
|
+
))
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
// {}
|
|
49
|
+
```
|
|
17
50
|
|
|
18
|
-
|
|
51
|
+
### Match and collect nodes
|
|
52
|
+
```ts
|
|
53
|
+
import { matchElement, element, css, childNodes, textNode, children, multiple } from '@blackglory/match'
|
|
54
|
+
import { parseNodes, getBySelector } from 'extra-dom'
|
|
55
|
+
|
|
56
|
+
const div = parseNodes(`
|
|
57
|
+
<div>
|
|
58
|
+
<header>Heading</header>
|
|
59
|
+
<article>
|
|
60
|
+
<p>Paragraph1</p>
|
|
61
|
+
<p>Paragraph2</p>
|
|
62
|
+
</article>
|
|
63
|
+
</div>
|
|
64
|
+
`.trim())[0] as Element
|
|
65
|
+
const header = getBySelector.call(div, 'header')
|
|
66
|
+
|
|
67
|
+
const result = matchElement(
|
|
68
|
+
header
|
|
19
69
|
, element(
|
|
20
70
|
css`header`
|
|
21
71
|
, childNodes(
|
|
@@ -23,7 +73,7 @@ const result = matchElement(node
|
|
|
23
73
|
)
|
|
24
74
|
)
|
|
25
75
|
, element(
|
|
26
|
-
css`
|
|
76
|
+
css`article`
|
|
27
77
|
, children(
|
|
28
78
|
multiple([1, Infinity], element(
|
|
29
79
|
css`p`
|
|
@@ -34,11 +84,16 @@ const result = matchElement(node
|
|
|
34
84
|
)
|
|
35
85
|
)
|
|
36
86
|
)
|
|
37
|
-
// {
|
|
87
|
+
// {
|
|
88
|
+
// heading: [object Text "Heading"]
|
|
89
|
+
// , paragraph: [
|
|
90
|
+
// [object Text "Paragraph1"]
|
|
91
|
+
// , [object Text "Paragraph2"]
|
|
92
|
+
// ]
|
|
93
|
+
// }
|
|
38
94
|
```
|
|
39
95
|
|
|
40
96
|
## API
|
|
41
|
-
|
|
42
97
|
```ts
|
|
43
98
|
interface IContext {
|
|
44
99
|
readonly document: Document
|
|
@@ -78,29 +133,25 @@ type ISkipMatcher<T extends Node> = (
|
|
|
78
133
|
```
|
|
79
134
|
|
|
80
135
|
### match
|
|
81
|
-
|
|
82
136
|
```ts
|
|
83
137
|
function match(
|
|
84
138
|
this: void | Document
|
|
85
139
|
, node: Node
|
|
86
140
|
, ...matchers: Array<IMatcher<Node>>
|
|
87
|
-
):
|
|
141
|
+
): Record<string, Arrayable<Node>> | null
|
|
88
142
|
```
|
|
89
143
|
|
|
90
144
|
### matchElement
|
|
91
|
-
|
|
92
145
|
```ts
|
|
93
146
|
function matchElement(
|
|
94
147
|
this: void | Document
|
|
95
148
|
, element: Element
|
|
96
149
|
, ...matchers: Array<IMatcher<Element>>
|
|
97
|
-
):
|
|
150
|
+
): Record<string, Arrayable<Node>> | null
|
|
98
151
|
```
|
|
99
152
|
|
|
100
153
|
### Matchers
|
|
101
|
-
|
|
102
154
|
#### anyOf
|
|
103
|
-
|
|
104
155
|
```ts
|
|
105
156
|
function anyOf<T extends Node>(
|
|
106
157
|
...matchers: [
|
|
@@ -112,39 +163,45 @@ function anyOf<T extends Node>(
|
|
|
112
163
|
```
|
|
113
164
|
|
|
114
165
|
#### childNodes
|
|
115
|
-
|
|
116
166
|
```ts
|
|
117
167
|
function childNodes(...matchers: Array<IMatcher<Node>>): INestedMatcher<Node>
|
|
118
168
|
```
|
|
119
169
|
|
|
120
170
|
#### children
|
|
121
|
-
|
|
122
171
|
```ts
|
|
123
172
|
function children(...matchers: Array<IMatcher<Element>>): INestedMatcher<Element>
|
|
124
173
|
```
|
|
125
174
|
|
|
126
175
|
#### css
|
|
127
|
-
|
|
128
176
|
```ts
|
|
129
|
-
function css(
|
|
177
|
+
function css(
|
|
178
|
+
strings: TemplateStringsArray
|
|
179
|
+
, ...values: string[]
|
|
180
|
+
): ITerminalMatcher<Element>
|
|
130
181
|
function css(selector: string): ITerminalMatcher<Element>
|
|
131
182
|
```
|
|
132
183
|
|
|
133
184
|
#### element
|
|
134
|
-
|
|
135
185
|
```ts
|
|
136
186
|
function element(
|
|
137
187
|
strings: TemplateStringsArray
|
|
138
188
|
, ...values: string[]
|
|
139
|
-
): (
|
|
140
|
-
|
|
141
|
-
INestedMatcher<
|
|
142
|
-
|
|
143
|
-
|
|
189
|
+
): (
|
|
190
|
+
...matchers: Array<
|
|
191
|
+
| INestedMatcher<Element>
|
|
192
|
+
| ITerminalMatcher<Element>
|
|
193
|
+
>
|
|
194
|
+
) => INestedMatcher<Node>
|
|
195
|
+
function element(
|
|
196
|
+
name: string
|
|
197
|
+
, ...matchers: Array<INestedMatcher<Element>>
|
|
198
|
+
): INestedMatcher<Node>
|
|
199
|
+
function element(
|
|
200
|
+
...matchers: Array<INestedMatcher<Element>>
|
|
201
|
+
): INestedMatcher<Node>
|
|
144
202
|
```
|
|
145
203
|
|
|
146
204
|
#### multiple
|
|
147
|
-
|
|
148
205
|
```ts
|
|
149
206
|
interface IMultipleOptions {
|
|
150
207
|
greedy: boolean
|
|
@@ -158,12 +215,13 @@ function multiple<T extends Node>(
|
|
|
158
215
|
```
|
|
159
216
|
|
|
160
217
|
#### node
|
|
161
|
-
|
|
162
218
|
```ts
|
|
163
219
|
function node(
|
|
164
220
|
strings: TemplateStringsArray
|
|
165
221
|
, ...values: string[]
|
|
166
|
-
): (
|
|
222
|
+
): (
|
|
223
|
+
...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>
|
|
224
|
+
) => INestedMatcher<Node>
|
|
167
225
|
function node(
|
|
168
226
|
name: string
|
|
169
227
|
, ...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>
|
|
@@ -174,7 +232,6 @@ function node(
|
|
|
174
232
|
```
|
|
175
233
|
|
|
176
234
|
#### optional
|
|
177
|
-
|
|
178
235
|
```ts
|
|
179
236
|
function optional<T extends Node>(
|
|
180
237
|
matcher: INestedMatcher<T> | ITerminalMatcher<T>
|
|
@@ -182,7 +239,6 @@ function optional<T extends Node>(
|
|
|
182
239
|
```
|
|
183
240
|
|
|
184
241
|
#### repeat
|
|
185
|
-
|
|
186
242
|
```ts
|
|
187
243
|
function repeat<T extends Node>(
|
|
188
244
|
times: number
|
|
@@ -191,7 +247,6 @@ function repeat<T extends Node>(
|
|
|
191
247
|
```
|
|
192
248
|
|
|
193
249
|
#### tap
|
|
194
|
-
|
|
195
250
|
```ts
|
|
196
251
|
function tap<T extends Node, U extends ReturnType<IMatcher<any>>>(
|
|
197
252
|
matcher: (this: IReadonlyContext, node: T) => U
|
|
@@ -200,7 +255,6 @@ function tap<T extends Node, U extends ReturnType<IMatcher<any>>>(
|
|
|
200
255
|
```
|
|
201
256
|
|
|
202
257
|
#### textContentEquals
|
|
203
|
-
|
|
204
258
|
```ts
|
|
205
259
|
interface ITextContentEqualsOptions {
|
|
206
260
|
caseSensitive?: boolean
|
|
@@ -217,14 +271,13 @@ function textContentEquals(
|
|
|
217
271
|
```
|
|
218
272
|
|
|
219
273
|
#### textContentIncludes
|
|
220
|
-
|
|
221
274
|
```ts
|
|
222
275
|
interface ITextContentIncludesOptions {
|
|
223
276
|
caseSensitive?: boolean
|
|
224
277
|
trim?: boolean
|
|
225
278
|
}
|
|
226
279
|
|
|
227
|
-
|
|
280
|
+
function textContentIncludes(
|
|
228
281
|
searchString: string
|
|
229
282
|
, {
|
|
230
283
|
caseSensitive = true
|
|
@@ -234,20 +287,18 @@ export function textContentIncludes(
|
|
|
234
287
|
```
|
|
235
288
|
|
|
236
289
|
#### textContentMatches
|
|
237
|
-
|
|
238
290
|
```ts
|
|
239
291
|
interface ITextContentMatchesOptions {
|
|
240
292
|
trim?: boolean
|
|
241
293
|
}
|
|
242
294
|
|
|
243
|
-
|
|
295
|
+
function textContentMatches(
|
|
244
296
|
pattern: RegExp
|
|
245
297
|
, { trim = false }: ITextContentMatchesOptions = {}
|
|
246
298
|
): ITerminalMatcher<Node>
|
|
247
299
|
```
|
|
248
300
|
|
|
249
301
|
#### textNode
|
|
250
|
-
|
|
251
302
|
```ts
|
|
252
303
|
function textNode(
|
|
253
304
|
strings: TemplateStringsArray
|
|
@@ -263,7 +314,6 @@ function textNode(
|
|
|
263
314
|
```
|
|
264
315
|
|
|
265
316
|
#### xpath
|
|
266
|
-
|
|
267
317
|
```ts
|
|
268
318
|
function xpath(
|
|
269
319
|
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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { IMatcher } from './types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} | null;
|
|
1
|
+
import { IMatcher } from './types.js';
|
|
2
|
+
import { Arrayable } from '@blackglory/prelude';
|
|
3
|
+
export declare function matchElement(this: void | Document, element: Element, ...matchers: Array<IMatcher<Element>>): Record<string, Arrayable<Node>> | null;
|
package/lib/match-element.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
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)
|
|
6
|
+
? this
|
|
7
|
+
: globalThis.document;
|
|
9
8
|
const context = {
|
|
10
9
|
document,
|
|
11
10
|
collection: {},
|
|
12
|
-
next:
|
|
11
|
+
next: nextElementSibling
|
|
13
12
|
};
|
|
14
|
-
if (
|
|
13
|
+
if (matchOneByOne(context, element, ...matchers)) {
|
|
15
14
|
return context.collection;
|
|
16
15
|
}
|
|
17
16
|
else {
|
|
18
17
|
return null;
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
|
-
exports.matchElement = matchElement;
|
|
22
20
|
//# 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;AAGnE,MAAM,UAAU,YAAY,CAE1B,OAAgB,EAChB,GAAG,QAAkC;IAErC,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC;QAClB,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAA;IAEpC,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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { IMatcher } from './types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} | null;
|
|
1
|
+
import { IMatcher } from './types.js';
|
|
2
|
+
import { Arrayable } from '@blackglory/prelude';
|
|
3
|
+
export declare function match(this: void | Document, node: Node, ...matchers: Array<IMatcher<Node>>): Record<string, Arrayable<Node>> | null;
|
package/lib/match.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
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)
|
|
6
|
+
? this
|
|
7
|
+
: globalThis.document;
|
|
9
8
|
const context = {
|
|
10
9
|
document,
|
|
11
10
|
collection: {},
|
|
12
|
-
next:
|
|
11
|
+
next: nextSibling
|
|
13
12
|
};
|
|
14
|
-
if (
|
|
13
|
+
if (matchOneByOne(context, node, ...matchers)) {
|
|
15
14
|
return context.collection;
|
|
16
15
|
}
|
|
17
16
|
else {
|
|
18
17
|
return null;
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
|
-
exports.match = match;
|
|
22
20
|
//# 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;AAGpD,MAAM,UAAU,KAAK,CAEnB,IAAU,EACV,GAAG,QAA+B;IAElC,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC;QAClB,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAA;IAEpC,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,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const next_sibling_1 = require("../utils/next-sibling");
|
|
7
|
-
function childNodes(...matchers) {
|
|
1
|
+
import { isEmptyArray } from '@blackglory/prelude';
|
|
2
|
+
import { matchOneByOne } from "../utils/match-one-by-one.js";
|
|
3
|
+
import { mergeInPlace } from "../utils/merge-in-place.js";
|
|
4
|
+
import { nextSibling } from "../utils/next-sibling.js";
|
|
5
|
+
export function childNodes(...matchers) {
|
|
8
6
|
return function (node) {
|
|
9
|
-
|
|
7
|
+
// 空matchers意味着"childNodes应该为空".
|
|
8
|
+
if (isEmptyArray(matchers)) {
|
|
10
9
|
return node.childNodes.length === 0;
|
|
11
10
|
}
|
|
12
11
|
if (node.childNodes.length === 0)
|
|
@@ -14,14 +13,13 @@ function childNodes(...matchers) {
|
|
|
14
13
|
const context = {
|
|
15
14
|
...this,
|
|
16
15
|
collection: {},
|
|
17
|
-
next:
|
|
16
|
+
next: nextSibling
|
|
18
17
|
};
|
|
19
|
-
const result =
|
|
18
|
+
const result = matchOneByOne(context, node.childNodes[0], ...matchers);
|
|
20
19
|
if (result) {
|
|
21
|
-
|
|
20
|
+
mergeInPlace(this.collection, context.collection);
|
|
22
21
|
}
|
|
23
22
|
return result;
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
|
-
exports.childNodes = childNodes;
|
|
27
25
|
//# 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":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,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,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,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,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const next_element_sibling_1 = require("../utils/next-element-sibling");
|
|
7
|
-
function children(...matchers) {
|
|
1
|
+
import { isEmptyArray } from '@blackglory/prelude';
|
|
2
|
+
import { matchOneByOne } from "../utils/match-one-by-one.js";
|
|
3
|
+
import { mergeInPlace } from "../utils/merge-in-place.js";
|
|
4
|
+
import { nextElementSibling } from "../utils/next-element-sibling.js";
|
|
5
|
+
export function children(...matchers) {
|
|
8
6
|
return function (element) {
|
|
9
|
-
|
|
7
|
+
// 空matchers意味着"children应该为空".
|
|
8
|
+
if (isEmptyArray(matchers)) {
|
|
10
9
|
return element.children.length === 0;
|
|
11
10
|
}
|
|
12
11
|
if (element.children.length === 0)
|
|
@@ -14,14 +13,13 @@ function children(...matchers) {
|
|
|
14
13
|
const context = {
|
|
15
14
|
...this,
|
|
16
15
|
collection: {},
|
|
17
|
-
next:
|
|
16
|
+
next: nextElementSibling
|
|
18
17
|
};
|
|
19
|
-
const result =
|
|
18
|
+
const result = matchOneByOne(context, element.children[0], ...matchers);
|
|
20
19
|
if (result) {
|
|
21
|
-
|
|
20
|
+
mergeInPlace(this.collection, context.collection);
|
|
22
21
|
}
|
|
23
22
|
return result;
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
|
-
exports.children = children;
|
|
27
25
|
//# 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":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,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,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3B,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 'extra-tags';
|
|
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);
|
|
14
11
|
return css(selector);
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
|
-
exports.css = css;
|
|
18
14
|
//# sourceMappingURL=css.js.map
|