@blackglory/match 0.3.5 → 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 -0
- package/lib/index.js +18 -0
- package/lib/index.js.map +1 -0
- package/lib/{es2015/match-element.d.ts → match-element.d.ts} +1 -1
- package/lib/match-element.js +18 -0
- package/lib/match-element.js.map +1 -0
- package/lib/{es2015/match.d.ts → match.d.ts} +1 -1
- package/lib/match.js +18 -0
- package/lib/match.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/any-of.d.ts +1 -1
- package/lib/matchers/any-of.js +6 -0
- package/lib/matchers/any-of.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/child-nodes.d.ts +1 -1
- package/lib/matchers/child-nodes.js +24 -0
- package/lib/matchers/child-nodes.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/children.d.ts +1 -1
- package/lib/matchers/children.js +24 -0
- package/lib/matchers/children.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/css.d.ts +1 -1
- package/lib/matchers/css.js +14 -0
- package/lib/matchers/css.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/element.d.ts +1 -1
- package/lib/matchers/element.js +30 -0
- package/lib/matchers/element.js.map +1 -0
- package/lib/{es2018/matchers → matchers}/multiple.d.ts +1 -1
- package/lib/matchers/multiple.js +39 -0
- package/lib/matchers/multiple.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/node.d.ts +1 -1
- package/lib/matchers/node.js +27 -0
- package/lib/matchers/node.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/optional.d.ts +1 -1
- package/lib/matchers/optional.js +5 -0
- package/lib/matchers/optional.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/repeat.d.ts +1 -1
- package/lib/matchers/repeat.js +16 -0
- package/lib/matchers/repeat.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/tap.d.ts +1 -1
- package/lib/matchers/tap.js +8 -0
- package/lib/matchers/tap.js.map +1 -0
- package/lib/{es2018/matchers → matchers}/text-content-equals.d.ts +1 -1
- package/lib/matchers/text-content-equals.js +16 -0
- package/lib/matchers/text-content-equals.js.map +1 -0
- package/lib/{es2018/matchers → matchers}/text-content-includes.d.ts +1 -1
- package/lib/matchers/text-content-includes.js +16 -0
- package/lib/matchers/text-content-includes.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/text-content-matches.d.ts +1 -1
- package/lib/matchers/text-content-matches.js +12 -0
- package/lib/matchers/text-content-matches.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/text-node.d.ts +1 -1
- package/lib/matchers/text-node.js +30 -0
- package/lib/matchers/text-node.js.map +1 -0
- package/lib/{es2015/matchers → matchers}/xpath.d.ts +1 -1
- package/lib/{es2015/matchers → matchers}/xpath.js +7 -11
- package/lib/matchers/xpath.js.map +1 -0
- package/lib/types.d.ts +18 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/{es2015/utils → utils}/concat.js +1 -5
- package/lib/utils/concat.js.map +1 -0
- package/lib/{es2015/utils → utils}/match-multiple.d.ts +4 -1
- package/lib/utils/match-multiple.js +20 -0
- package/lib/utils/match-multiple.js.map +1 -0
- package/lib/{es2015/utils → utils}/match-one-by-one.d.ts +1 -1
- package/lib/{es2015/utils → utils}/match-one-by-one.js +9 -9
- package/lib/utils/match-one-by-one.js.map +1 -0
- package/lib/utils/merge-in-place.d.ts +1 -0
- package/lib/{es2015/utils → utils}/merge-in-place.js +5 -9
- package/lib/utils/merge-in-place.js.map +1 -0
- package/lib/utils/next-element-sibling.js +7 -0
- package/lib/utils/next-element-sibling.js.map +1 -0
- package/lib/utils/next-sibling.js +7 -0
- package/lib/utils/next-sibling.js.map +1 -0
- package/package.json +34 -49
- package/src/index.ts +18 -0
- package/src/match-element.ts +23 -0
- package/src/match.ts +23 -0
- package/src/matchers/any-of.ts +13 -0
- package/src/matchers/child-nodes.ts +33 -0
- package/src/matchers/children.ts +35 -0
- package/src/matchers/css.ts +24 -0
- package/src/matchers/element.ts +49 -0
- package/src/matchers/multiple.ts +59 -0
- package/src/matchers/node.ts +50 -0
- package/src/matchers/optional.ts +6 -0
- package/src/matchers/repeat.ts +25 -0
- package/src/matchers/tap.ts +12 -0
- package/src/matchers/text-content-equals.ts +28 -0
- package/src/matchers/text-content-includes.ts +28 -0
- package/src/matchers/text-content-matches.ts +20 -0
- package/src/matchers/text-node.ts +52 -0
- package/src/matchers/xpath.ts +54 -0
- package/src/types.ts +39 -0
- package/src/utils/concat.ts +9 -0
- package/src/utils/match-multiple.ts +27 -0
- package/src/utils/match-one-by-one.ts +47 -0
- package/src/utils/merge-in-place.ts +26 -0
- package/src/utils/next-element-sibling.ts +10 -0
- package/src/utils/next-sibling.ts +7 -0
- package/dist/es2015/index.min.mjs +0 -2
- package/dist/es2015/index.min.mjs.map +0 -1
- package/dist/es2015/index.mjs +0 -4445
- package/dist/es2015/index.mjs.map +0 -1
- package/dist/es2015/index.umd.js +0 -4471
- package/dist/es2015/index.umd.js.map +0 -1
- package/dist/es2015/index.umd.min.js +0 -2
- package/dist/es2015/index.umd.min.js.map +0 -1
- package/dist/es2018/index.min.mjs +0 -2
- package/dist/es2018/index.min.mjs.map +0 -1
- package/dist/es2018/index.mjs +0 -4453
- package/dist/es2018/index.mjs.map +0 -1
- package/dist/es2018/index.umd.js +0 -4479
- package/dist/es2018/index.umd.js.map +0 -1
- package/dist/es2018/index.umd.min.js +0 -2
- package/dist/es2018/index.umd.min.js.map +0 -1
- package/lib/es2015/index.d.ts +0 -17
- package/lib/es2015/index.js +0 -38
- package/lib/es2015/index.js.map +0 -1
- package/lib/es2015/match-element.js +0 -22
- package/lib/es2015/match-element.js.map +0 -1
- package/lib/es2015/match.js +0 -22
- package/lib/es2015/match.js.map +0 -1
- package/lib/es2015/matchers/any-of.js +0 -10
- package/lib/es2015/matchers/any-of.js.map +0 -1
- package/lib/es2015/matchers/child-nodes.js +0 -23
- package/lib/es2015/matchers/child-nodes.js.map +0 -1
- package/lib/es2015/matchers/children.js +0 -23
- package/lib/es2015/matchers/children.js.map +0 -1
- package/lib/es2015/matchers/css.js +0 -18
- package/lib/es2015/matchers/css.js.map +0 -1
- package/lib/es2015/matchers/element.js +0 -34
- package/lib/es2015/matchers/element.js.map +0 -1
- package/lib/es2015/matchers/multiple.d.ts +0 -10
- package/lib/es2015/matchers/multiple.js +0 -42
- package/lib/es2015/matchers/multiple.js.map +0 -1
- package/lib/es2015/matchers/node.js +0 -31
- package/lib/es2015/matchers/node.js.map +0 -1
- package/lib/es2015/matchers/optional.js +0 -9
- package/lib/es2015/matchers/optional.js.map +0 -1
- package/lib/es2015/matchers/repeat.js +0 -20
- package/lib/es2015/matchers/repeat.js.map +0 -1
- package/lib/es2015/matchers/tap.js +0 -12
- package/lib/es2015/matchers/tap.js.map +0 -1
- package/lib/es2015/matchers/text-content-equals.d.ts +0 -7
- package/lib/es2015/matchers/text-content-equals.js +0 -20
- package/lib/es2015/matchers/text-content-equals.js.map +0 -1
- package/lib/es2015/matchers/text-content-includes.d.ts +0 -7
- package/lib/es2015/matchers/text-content-includes.js +0 -20
- package/lib/es2015/matchers/text-content-includes.js.map +0 -1
- package/lib/es2015/matchers/text-content-matches.js +0 -16
- package/lib/es2015/matchers/text-content-matches.js.map +0 -1
- package/lib/es2015/matchers/text-node.js +0 -34
- package/lib/es2015/matchers/text-node.js.map +0 -1
- package/lib/es2015/matchers/xpath.js.map +0 -1
- package/lib/es2015/types.d.ts +0 -18
- package/lib/es2015/types.js +0 -3
- package/lib/es2015/types.js.map +0 -1
- package/lib/es2015/utils/concat.js.map +0 -1
- package/lib/es2015/utils/match-multiple.js +0 -21
- package/lib/es2015/utils/match-multiple.js.map +0 -1
- package/lib/es2015/utils/match-one-by-one.js.map +0 -1
- package/lib/es2015/utils/merge-in-place.d.ts +0 -5
- package/lib/es2015/utils/merge-in-place.js.map +0 -1
- package/lib/es2015/utils/next-element-sibling.js +0 -11
- package/lib/es2015/utils/next-element-sibling.js.map +0 -1
- package/lib/es2015/utils/next-sibling.js +0 -11
- package/lib/es2015/utils/next-sibling.js.map +0 -1
- package/lib/es2018/index.d.ts +0 -17
- package/lib/es2018/index.js +0 -38
- package/lib/es2018/index.js.map +0 -1
- package/lib/es2018/match-element.d.ts +0 -4
- package/lib/es2018/match-element.js +0 -22
- package/lib/es2018/match-element.js.map +0 -1
- package/lib/es2018/match.d.ts +0 -4
- package/lib/es2018/match.js +0 -22
- package/lib/es2018/match.js.map +0 -1
- package/lib/es2018/matchers/any-of.d.ts +0 -6
- package/lib/es2018/matchers/any-of.js +0 -10
- package/lib/es2018/matchers/any-of.js.map +0 -1
- package/lib/es2018/matchers/child-nodes.d.ts +0 -2
- package/lib/es2018/matchers/child-nodes.js +0 -27
- package/lib/es2018/matchers/child-nodes.js.map +0 -1
- package/lib/es2018/matchers/children.d.ts +0 -2
- package/lib/es2018/matchers/children.js +0 -27
- package/lib/es2018/matchers/children.js.map +0 -1
- package/lib/es2018/matchers/css.d.ts +0 -3
- package/lib/es2018/matchers/css.js +0 -18
- package/lib/es2018/matchers/css.js.map +0 -1
- package/lib/es2018/matchers/element.d.ts +0 -4
- package/lib/es2018/matchers/element.js +0 -34
- package/lib/es2018/matchers/element.js.map +0 -1
- package/lib/es2018/matchers/multiple.js +0 -42
- package/lib/es2018/matchers/multiple.js.map +0 -1
- package/lib/es2018/matchers/node.d.ts +0 -4
- package/lib/es2018/matchers/node.js +0 -31
- package/lib/es2018/matchers/node.js.map +0 -1
- package/lib/es2018/matchers/optional.d.ts +0 -2
- package/lib/es2018/matchers/optional.js +0 -9
- package/lib/es2018/matchers/optional.js.map +0 -1
- package/lib/es2018/matchers/repeat.d.ts +0 -2
- package/lib/es2018/matchers/repeat.js +0 -20
- package/lib/es2018/matchers/repeat.js.map +0 -1
- package/lib/es2018/matchers/tap.d.ts +0 -2
- package/lib/es2018/matchers/tap.js +0 -12
- package/lib/es2018/matchers/tap.js.map +0 -1
- package/lib/es2018/matchers/text-content-equals.js +0 -20
- package/lib/es2018/matchers/text-content-equals.js.map +0 -1
- package/lib/es2018/matchers/text-content-includes.js +0 -20
- package/lib/es2018/matchers/text-content-includes.js.map +0 -1
- package/lib/es2018/matchers/text-content-matches.d.ts +0 -6
- package/lib/es2018/matchers/text-content-matches.js +0 -16
- package/lib/es2018/matchers/text-content-matches.js.map +0 -1
- package/lib/es2018/matchers/text-node.d.ts +0 -4
- package/lib/es2018/matchers/text-node.js +0 -34
- package/lib/es2018/matchers/text-node.js.map +0 -1
- package/lib/es2018/matchers/xpath.d.ts +0 -3
- package/lib/es2018/matchers/xpath.js +0 -34
- package/lib/es2018/matchers/xpath.js.map +0 -1
- package/lib/es2018/types.d.ts +0 -18
- package/lib/es2018/types.js +0 -3
- package/lib/es2018/types.js.map +0 -1
- package/lib/es2018/utils/concat.d.ts +0 -1
- package/lib/es2018/utils/concat.js +0 -14
- package/lib/es2018/utils/concat.js.map +0 -1
- package/lib/es2018/utils/match-multiple.d.ts +0 -2
- package/lib/es2018/utils/match-multiple.js +0 -21
- package/lib/es2018/utils/match-multiple.js.map +0 -1
- package/lib/es2018/utils/match-one-by-one.d.ts +0 -2
- package/lib/es2018/utils/match-one-by-one.js +0 -38
- package/lib/es2018/utils/match-one-by-one.js.map +0 -1
- package/lib/es2018/utils/merge-in-place.d.ts +0 -5
- package/lib/es2018/utils/merge-in-place.js +0 -31
- package/lib/es2018/utils/merge-in-place.js.map +0 -1
- package/lib/es2018/utils/next-element-sibling.d.ts +0 -1
- package/lib/es2018/utils/next-element-sibling.js +0 -11
- package/lib/es2018/utils/next-element-sibling.js.map +0 -1
- package/lib/es2018/utils/next-sibling.d.ts +0 -1
- package/lib/es2018/utils/next-sibling.js +0 -11
- package/lib/es2018/utils/next-sibling.js.map +0 -1
- /package/lib/{es2015/utils → utils}/concat.d.ts +0 -0
- /package/lib/{es2015/utils → utils}/next-element-sibling.d.ts +0 -0
- /package/lib/{es2015/utils → utils}/next-sibling.d.ts +0 -0
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
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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";
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
|
6
|
+
const context = {
|
|
7
|
+
document,
|
|
8
|
+
collection: {},
|
|
9
|
+
next: nextElementSibling
|
|
10
|
+
};
|
|
11
|
+
if (matchOneByOne(context, element, ...matchers)) {
|
|
12
|
+
return context.collection;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=match-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
|
6
|
+
const context = {
|
|
7
|
+
document,
|
|
8
|
+
collection: {},
|
|
9
|
+
next: nextSibling
|
|
10
|
+
};
|
|
11
|
+
if (matchOneByOne(context, node, ...matchers)) {
|
|
12
|
+
return context.collection;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=match.js.map
|
package/lib/match.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -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>,
|
|
@@ -0,0 +1 @@
|
|
|
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>;
|
|
@@ -0,0 +1,24 @@
|
|
|
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) {
|
|
5
|
+
return function (node) {
|
|
6
|
+
// 空matchers意味着"childNodes应该为空".
|
|
7
|
+
if (matchers.length === 0) {
|
|
8
|
+
return node.childNodes.length === 0;
|
|
9
|
+
}
|
|
10
|
+
if (node.childNodes.length === 0)
|
|
11
|
+
return false;
|
|
12
|
+
const context = {
|
|
13
|
+
...this,
|
|
14
|
+
collection: {},
|
|
15
|
+
next: nextSibling
|
|
16
|
+
};
|
|
17
|
+
const result = matchOneByOne(context, node.childNodes[0], ...matchers);
|
|
18
|
+
if (result) {
|
|
19
|
+
mergeInPlace(this.collection, context.collection);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=child-nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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>;
|
|
@@ -0,0 +1,24 @@
|
|
|
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) {
|
|
5
|
+
return function (element) {
|
|
6
|
+
// 空matchers意味着"children应该为空".
|
|
7
|
+
if (matchers.length === 0) {
|
|
8
|
+
return element.children.length === 0;
|
|
9
|
+
}
|
|
10
|
+
if (element.children.length === 0)
|
|
11
|
+
return false;
|
|
12
|
+
const context = {
|
|
13
|
+
...this,
|
|
14
|
+
collection: {},
|
|
15
|
+
next: nextElementSibling
|
|
16
|
+
};
|
|
17
|
+
const result = matchOneByOne(context, element.children[0], ...matchers);
|
|
18
|
+
if (result) {
|
|
19
|
+
mergeInPlace(this.collection, context.collection);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=children.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -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>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { concat } from "../utils/concat.js";
|
|
2
|
+
import { isString } from '@blackglory/prelude';
|
|
3
|
+
export function css(...args) {
|
|
4
|
+
if (isString(args[0])) {
|
|
5
|
+
const [selector] = args;
|
|
6
|
+
return (element) => element.matches(selector);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const [strings, ...values] = args;
|
|
10
|
+
const selector = concat(strings, values).join('');
|
|
11
|
+
return css(selector);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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>;
|
|
@@ -0,0 +1,30 @@
|
|
|
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])) {
|
|
7
|
+
const [strings, ...values] = args;
|
|
8
|
+
const name = concat(strings, values).join('');
|
|
9
|
+
return (...matchers) => element(name, ...matchers);
|
|
10
|
+
}
|
|
11
|
+
if (isString(args[0])) {
|
|
12
|
+
const [name, ...matchers] = args;
|
|
13
|
+
return function (_element) {
|
|
14
|
+
const result = element(...matchers).call(this, _element);
|
|
15
|
+
if (result) {
|
|
16
|
+
mergeInPlace(this.collection, { [name]: _element });
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const [...matchers] = args;
|
|
22
|
+
return function (element) {
|
|
23
|
+
if (isntElement(element))
|
|
24
|
+
return false;
|
|
25
|
+
if (matchers.length === 0)
|
|
26
|
+
return true;
|
|
27
|
+
return matchers.every(match => match.call(this, element));
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { countup } from 'extra-generator';
|
|
2
|
+
import { assert } from '@blackglory/prelude';
|
|
3
|
+
import { matchMultiple } from "../utils/match-multiple.js";
|
|
4
|
+
export var Range;
|
|
5
|
+
(function (Range) {
|
|
6
|
+
Range[Range["Min"] = 0] = "Min";
|
|
7
|
+
Range[Range["Max"] = 1] = "Max";
|
|
8
|
+
})(Range || (Range = {}));
|
|
9
|
+
export function multiple([min, max], matcher, options = { greedy: true }) {
|
|
10
|
+
assert(Number.isInteger(min), 'parameter min must be an integer');
|
|
11
|
+
assert(Number.isInteger(max) || max === Infinity, 'parameter max must be an integer or Infinity');
|
|
12
|
+
assert(min >= 0, 'parameter min must be greater than or equal to 0');
|
|
13
|
+
assert(min <= max, 'parameter max must be greater than or equal to min');
|
|
14
|
+
return function* (node) {
|
|
15
|
+
if (options.greedy) {
|
|
16
|
+
let ubound = max;
|
|
17
|
+
while (true) {
|
|
18
|
+
const round = matchMultiple.call(this, node, ubound, matcher);
|
|
19
|
+
if (round < min)
|
|
20
|
+
break;
|
|
21
|
+
yield round;
|
|
22
|
+
ubound = round - 1;
|
|
23
|
+
if (ubound < min)
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
for (const ubound of countup(min, max)) {
|
|
29
|
+
const result = matchMultiple.call(this, node, ubound, matcher);
|
|
30
|
+
// 如果匹配的节点数量少于ubound, 说明匹配失败, 即使尝试更长的匹配也不会成功.
|
|
31
|
+
if (result < ubound)
|
|
32
|
+
break;
|
|
33
|
+
if (result === ubound)
|
|
34
|
+
yield ubound;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=multiple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiple.js","sourceRoot":"","sources":["../../src/matchers/multiple.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,mCAAgC;AAExD,MAAM,CAAN,IAAY,KAGX;AAHD,WAAY,KAAK;IACf,+BAAO,CAAA;IACP,+BAAO,CAAA;AACT,CAAC,EAHW,KAAK,KAAL,KAAK,QAGhB;AAOD,MAAM,UAAU,QAAQ,CACtB,CAAC,GAAG,EAAE,GAAG,CAA6B,EACtC,OAAgD,EAChD,UAA4B,EAAE,MAAM,EAAE,IAAI,EAAE;IAE5C,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,kCAAkC,CAAC,CAAA;IACjE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,QAAQ,EAAE,8CAA8C,CAAC,CAAA;IACjG,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,kDAAkD,CAAC,CAAA;IACpE,MAAM,CAAC,GAAG,IAAI,GAAG,EAAE,oDAAoD,CAAC,CAAA;IAExE,OAAO,QAAQ,CAAC,EAA0B,IAAO;QAC/C,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,IAAI,MAAM,GAAG,GAAG,CAAA;YAChB,OAAO,IAAI,EAAE,CAAC;gBACZ,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAC9B,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAwD,CACzD,CAAA;gBAED,IAAI,KAAK,GAAG,GAAG;oBAAE,MAAK;gBACtB,MAAM,KAAK,CAAA;gBAEX,MAAM,GAAG,KAAK,GAAG,CAAC,CAAA;gBAClB,IAAI,MAAM,GAAG,GAAG;oBAAE,MAAK;YACzB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;gBACvC,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAC/B,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAsD,CACvD,CAAA;gBAED,6CAA6C;gBAC7C,IAAI,MAAM,GAAG,MAAM;oBAAE,MAAK;gBAE1B,IAAI,MAAM,KAAK,MAAM;oBAAE,MAAM,MAAM,CAAA;YACrC,CAAC;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INestedMatcher, ITerminalMatcher } from
|
|
1
|
+
import { INestedMatcher, ITerminalMatcher } from "../types.js";
|
|
2
2
|
export declare function node(strings: TemplateStringsArray, ...values: string[]): (...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>) => INestedMatcher<Node>;
|
|
3
3
|
export declare function node(name: string, ...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>): INestedMatcher<Node>;
|
|
4
4
|
export declare function node(...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>): INestedMatcher<Node>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isArray, isString } from '@blackglory/prelude';
|
|
2
|
+
import { concat } from "../utils/concat.js";
|
|
3
|
+
import { mergeInPlace } from "../utils/merge-in-place.js";
|
|
4
|
+
export function node(...args) {
|
|
5
|
+
if (isArray(args[0])) {
|
|
6
|
+
const [strings, ...values] = args;
|
|
7
|
+
const name = concat(strings, values).join('');
|
|
8
|
+
return (...matchers) => node(name, ...matchers);
|
|
9
|
+
}
|
|
10
|
+
if (isString(args[0])) {
|
|
11
|
+
const [name, ...matchers] = args;
|
|
12
|
+
return function (_node) {
|
|
13
|
+
const result = node(...matchers).call(this, _node);
|
|
14
|
+
if (result) {
|
|
15
|
+
mergeInPlace(this.collection, { [name]: _node });
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const [...matchers] = args;
|
|
21
|
+
return function (node) {
|
|
22
|
+
if (matchers.length === 0)
|
|
23
|
+
return true;
|
|
24
|
+
return matchers.every(match => match.call(this, node));
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/matchers/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,2BAAwB;AACzC,OAAO,EAAE,YAAY,EAAE,mCAAgC;AAavD,MAAM,UAAU,IAAI,CAAC,GAAG,IAG6C;IAEnE,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,QAA8D,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAA;IACvG,CAAC;IAED,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,GACvB,IAAyF,CAAA;QAE3F,OAAO,UAAkC,KAAW;YAClD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YAClD,IAAI,MAAM,EAAE,CAAC;gBACX,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;YAClD,CAAC;YACD,OAAO,MAAM,CAAA;QACf,CAAC,CAAA;IACH,CAAC;IAED,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,IAA2E,CAAA;IAEjG,OAAO,UAAkC,IAAU;QACjD,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,IAAI,CAAC,CAAC,CAAA;IACxD,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { INestedMatcher, ITerminalMatcher, ISkipMatcher } from
|
|
1
|
+
import { INestedMatcher, ITerminalMatcher, ISkipMatcher } from "../types.js";
|
|
2
2
|
export declare function optional<T extends Node>(matcher: INestedMatcher<T> | ITerminalMatcher<T>): ISkipMatcher<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../../src/matchers/optional.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,MAAM,UAAU,QAAQ,CAAiB,OAAgD;IACvF,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;AACpD,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { INestedMatcher, ITerminalMatcher, ISkipMatcher } from
|
|
1
|
+
import { INestedMatcher, ITerminalMatcher, ISkipMatcher } from "../types.js";
|
|
2
2
|
export declare function repeat<T extends Node>(times: number, matcher: INestedMatcher<T> | ITerminalMatcher<T>): ISkipMatcher<T>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { assert } from '@blackglory/prelude';
|
|
2
|
+
import { matchMultiple } from "../utils/match-multiple.js";
|
|
3
|
+
export function repeat(times, matcher) {
|
|
4
|
+
assert(Number.isInteger(times), 'parameter times must be an integer');
|
|
5
|
+
assert(times >= 0, 'parameter number must be greater than or equal to 0');
|
|
6
|
+
return function (node) {
|
|
7
|
+
const result = matchMultiple.call(this, node, times, matcher);
|
|
8
|
+
if (result === times) {
|
|
9
|
+
return times;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=repeat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repeat.js","sourceRoot":"","sources":["../../src/matchers/repeat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,mCAAgC;AAExD,MAAM,UAAU,MAAM,CACpB,KAAa,EACb,OAAgD;IAEhD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,oCAAoC,CAAC,CAAA;IACrE,MAAM,CAAC,KAAK,IAAI,CAAC,EAAE,qDAAqD,CAAC,CAAA;IAEzE,OAAO,UAAkC,IAAO;QAC9C,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAC/B,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,OAAwD,CACzD,CAAA;QACD,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;YACrB,OAAO,KAAK,CAAA;QACd,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IReadonlyContext, IMatcher } from
|
|
1
|
+
import { IReadonlyContext, IMatcher } from "../types.js";
|
|
2
2
|
export declare function tap<T extends Node, U extends ReturnType<IMatcher<any>>>(matcher: (this: IReadonlyContext, node: T) => U, callback: (value: U) => void): (this: IReadonlyContext, node: T) => U;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tap.js","sourceRoot":"","sources":["../../src/matchers/tap.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,CACjB,OAA+C,EAC/C,QAA4B;IAE5B,OAAO,UAAkC,IAAO;QAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QACvC,QAAQ,CAAC,MAAM,CAAC,CAAA;QAChB,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isNull } from '@blackglory/prelude';
|
|
2
|
+
export function textContentEquals(text, { caseSensitive = true, trim = false } = {}) {
|
|
3
|
+
return (node) => {
|
|
4
|
+
if (isNull(node.textContent))
|
|
5
|
+
return false;
|
|
6
|
+
let textContent = node.textContent;
|
|
7
|
+
if (!caseSensitive) {
|
|
8
|
+
textContent = textContent.toLowerCase();
|
|
9
|
+
text = text.toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
if (trim)
|
|
12
|
+
textContent = textContent.trim();
|
|
13
|
+
return textContent === text;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=text-content-equals.js.map
|