@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.
Files changed (242) hide show
  1. package/README.md +21 -32
  2. package/lib/index.d.ts +17 -0
  3. package/lib/index.js +18 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/{es2015/match-element.d.ts → match-element.d.ts} +1 -1
  6. package/lib/match-element.js +18 -0
  7. package/lib/match-element.js.map +1 -0
  8. package/lib/{es2015/match.d.ts → match.d.ts} +1 -1
  9. package/lib/match.js +18 -0
  10. package/lib/match.js.map +1 -0
  11. package/lib/{es2015/matchers → matchers}/any-of.d.ts +1 -1
  12. package/lib/matchers/any-of.js +6 -0
  13. package/lib/matchers/any-of.js.map +1 -0
  14. package/lib/{es2015/matchers → matchers}/child-nodes.d.ts +1 -1
  15. package/lib/matchers/child-nodes.js +24 -0
  16. package/lib/matchers/child-nodes.js.map +1 -0
  17. package/lib/{es2015/matchers → matchers}/children.d.ts +1 -1
  18. package/lib/matchers/children.js +24 -0
  19. package/lib/matchers/children.js.map +1 -0
  20. package/lib/{es2015/matchers → matchers}/css.d.ts +1 -1
  21. package/lib/matchers/css.js +14 -0
  22. package/lib/matchers/css.js.map +1 -0
  23. package/lib/{es2015/matchers → matchers}/element.d.ts +1 -1
  24. package/lib/matchers/element.js +30 -0
  25. package/lib/matchers/element.js.map +1 -0
  26. package/lib/{es2018/matchers → matchers}/multiple.d.ts +1 -1
  27. package/lib/matchers/multiple.js +39 -0
  28. package/lib/matchers/multiple.js.map +1 -0
  29. package/lib/{es2015/matchers → matchers}/node.d.ts +1 -1
  30. package/lib/matchers/node.js +27 -0
  31. package/lib/matchers/node.js.map +1 -0
  32. package/lib/{es2015/matchers → matchers}/optional.d.ts +1 -1
  33. package/lib/matchers/optional.js +5 -0
  34. package/lib/matchers/optional.js.map +1 -0
  35. package/lib/{es2015/matchers → matchers}/repeat.d.ts +1 -1
  36. package/lib/matchers/repeat.js +16 -0
  37. package/lib/matchers/repeat.js.map +1 -0
  38. package/lib/{es2015/matchers → matchers}/tap.d.ts +1 -1
  39. package/lib/matchers/tap.js +8 -0
  40. package/lib/matchers/tap.js.map +1 -0
  41. package/lib/{es2018/matchers → matchers}/text-content-equals.d.ts +1 -1
  42. package/lib/matchers/text-content-equals.js +16 -0
  43. package/lib/matchers/text-content-equals.js.map +1 -0
  44. package/lib/{es2018/matchers → matchers}/text-content-includes.d.ts +1 -1
  45. package/lib/matchers/text-content-includes.js +16 -0
  46. package/lib/matchers/text-content-includes.js.map +1 -0
  47. package/lib/{es2015/matchers → matchers}/text-content-matches.d.ts +1 -1
  48. package/lib/matchers/text-content-matches.js +12 -0
  49. package/lib/matchers/text-content-matches.js.map +1 -0
  50. package/lib/{es2015/matchers → matchers}/text-node.d.ts +1 -1
  51. package/lib/matchers/text-node.js +30 -0
  52. package/lib/matchers/text-node.js.map +1 -0
  53. package/lib/{es2015/matchers → matchers}/xpath.d.ts +1 -1
  54. package/lib/{es2015/matchers → matchers}/xpath.js +7 -11
  55. package/lib/matchers/xpath.js.map +1 -0
  56. package/lib/types.d.ts +18 -0
  57. package/lib/types.js +2 -0
  58. package/lib/types.js.map +1 -0
  59. package/lib/{es2015/utils → utils}/concat.js +1 -5
  60. package/lib/utils/concat.js.map +1 -0
  61. package/lib/{es2015/utils → utils}/match-multiple.d.ts +4 -1
  62. package/lib/utils/match-multiple.js +20 -0
  63. package/lib/utils/match-multiple.js.map +1 -0
  64. package/lib/{es2015/utils → utils}/match-one-by-one.d.ts +1 -1
  65. package/lib/{es2015/utils → utils}/match-one-by-one.js +9 -9
  66. package/lib/utils/match-one-by-one.js.map +1 -0
  67. package/lib/utils/merge-in-place.d.ts +1 -0
  68. package/lib/{es2015/utils → utils}/merge-in-place.js +5 -9
  69. package/lib/utils/merge-in-place.js.map +1 -0
  70. package/lib/utils/next-element-sibling.js +7 -0
  71. package/lib/utils/next-element-sibling.js.map +1 -0
  72. package/lib/utils/next-sibling.js +7 -0
  73. package/lib/utils/next-sibling.js.map +1 -0
  74. package/package.json +34 -49
  75. package/src/index.ts +18 -0
  76. package/src/match-element.ts +23 -0
  77. package/src/match.ts +23 -0
  78. package/src/matchers/any-of.ts +13 -0
  79. package/src/matchers/child-nodes.ts +33 -0
  80. package/src/matchers/children.ts +35 -0
  81. package/src/matchers/css.ts +24 -0
  82. package/src/matchers/element.ts +49 -0
  83. package/src/matchers/multiple.ts +59 -0
  84. package/src/matchers/node.ts +50 -0
  85. package/src/matchers/optional.ts +6 -0
  86. package/src/matchers/repeat.ts +25 -0
  87. package/src/matchers/tap.ts +12 -0
  88. package/src/matchers/text-content-equals.ts +28 -0
  89. package/src/matchers/text-content-includes.ts +28 -0
  90. package/src/matchers/text-content-matches.ts +20 -0
  91. package/src/matchers/text-node.ts +52 -0
  92. package/src/matchers/xpath.ts +54 -0
  93. package/src/types.ts +39 -0
  94. package/src/utils/concat.ts +9 -0
  95. package/src/utils/match-multiple.ts +27 -0
  96. package/src/utils/match-one-by-one.ts +47 -0
  97. package/src/utils/merge-in-place.ts +26 -0
  98. package/src/utils/next-element-sibling.ts +10 -0
  99. package/src/utils/next-sibling.ts +7 -0
  100. package/dist/es2015/index.min.mjs +0 -2
  101. package/dist/es2015/index.min.mjs.map +0 -1
  102. package/dist/es2015/index.mjs +0 -4445
  103. package/dist/es2015/index.mjs.map +0 -1
  104. package/dist/es2015/index.umd.js +0 -4471
  105. package/dist/es2015/index.umd.js.map +0 -1
  106. package/dist/es2015/index.umd.min.js +0 -2
  107. package/dist/es2015/index.umd.min.js.map +0 -1
  108. package/dist/es2018/index.min.mjs +0 -2
  109. package/dist/es2018/index.min.mjs.map +0 -1
  110. package/dist/es2018/index.mjs +0 -4453
  111. package/dist/es2018/index.mjs.map +0 -1
  112. package/dist/es2018/index.umd.js +0 -4479
  113. package/dist/es2018/index.umd.js.map +0 -1
  114. package/dist/es2018/index.umd.min.js +0 -2
  115. package/dist/es2018/index.umd.min.js.map +0 -1
  116. package/lib/es2015/index.d.ts +0 -17
  117. package/lib/es2015/index.js +0 -38
  118. package/lib/es2015/index.js.map +0 -1
  119. package/lib/es2015/match-element.js +0 -22
  120. package/lib/es2015/match-element.js.map +0 -1
  121. package/lib/es2015/match.js +0 -22
  122. package/lib/es2015/match.js.map +0 -1
  123. package/lib/es2015/matchers/any-of.js +0 -10
  124. package/lib/es2015/matchers/any-of.js.map +0 -1
  125. package/lib/es2015/matchers/child-nodes.js +0 -23
  126. package/lib/es2015/matchers/child-nodes.js.map +0 -1
  127. package/lib/es2015/matchers/children.js +0 -23
  128. package/lib/es2015/matchers/children.js.map +0 -1
  129. package/lib/es2015/matchers/css.js +0 -18
  130. package/lib/es2015/matchers/css.js.map +0 -1
  131. package/lib/es2015/matchers/element.js +0 -34
  132. package/lib/es2015/matchers/element.js.map +0 -1
  133. package/lib/es2015/matchers/multiple.d.ts +0 -10
  134. package/lib/es2015/matchers/multiple.js +0 -42
  135. package/lib/es2015/matchers/multiple.js.map +0 -1
  136. package/lib/es2015/matchers/node.js +0 -31
  137. package/lib/es2015/matchers/node.js.map +0 -1
  138. package/lib/es2015/matchers/optional.js +0 -9
  139. package/lib/es2015/matchers/optional.js.map +0 -1
  140. package/lib/es2015/matchers/repeat.js +0 -20
  141. package/lib/es2015/matchers/repeat.js.map +0 -1
  142. package/lib/es2015/matchers/tap.js +0 -12
  143. package/lib/es2015/matchers/tap.js.map +0 -1
  144. package/lib/es2015/matchers/text-content-equals.d.ts +0 -7
  145. package/lib/es2015/matchers/text-content-equals.js +0 -20
  146. package/lib/es2015/matchers/text-content-equals.js.map +0 -1
  147. package/lib/es2015/matchers/text-content-includes.d.ts +0 -7
  148. package/lib/es2015/matchers/text-content-includes.js +0 -20
  149. package/lib/es2015/matchers/text-content-includes.js.map +0 -1
  150. package/lib/es2015/matchers/text-content-matches.js +0 -16
  151. package/lib/es2015/matchers/text-content-matches.js.map +0 -1
  152. package/lib/es2015/matchers/text-node.js +0 -34
  153. package/lib/es2015/matchers/text-node.js.map +0 -1
  154. package/lib/es2015/matchers/xpath.js.map +0 -1
  155. package/lib/es2015/types.d.ts +0 -18
  156. package/lib/es2015/types.js +0 -3
  157. package/lib/es2015/types.js.map +0 -1
  158. package/lib/es2015/utils/concat.js.map +0 -1
  159. package/lib/es2015/utils/match-multiple.js +0 -21
  160. package/lib/es2015/utils/match-multiple.js.map +0 -1
  161. package/lib/es2015/utils/match-one-by-one.js.map +0 -1
  162. package/lib/es2015/utils/merge-in-place.d.ts +0 -5
  163. package/lib/es2015/utils/merge-in-place.js.map +0 -1
  164. package/lib/es2015/utils/next-element-sibling.js +0 -11
  165. package/lib/es2015/utils/next-element-sibling.js.map +0 -1
  166. package/lib/es2015/utils/next-sibling.js +0 -11
  167. package/lib/es2015/utils/next-sibling.js.map +0 -1
  168. package/lib/es2018/index.d.ts +0 -17
  169. package/lib/es2018/index.js +0 -38
  170. package/lib/es2018/index.js.map +0 -1
  171. package/lib/es2018/match-element.d.ts +0 -4
  172. package/lib/es2018/match-element.js +0 -22
  173. package/lib/es2018/match-element.js.map +0 -1
  174. package/lib/es2018/match.d.ts +0 -4
  175. package/lib/es2018/match.js +0 -22
  176. package/lib/es2018/match.js.map +0 -1
  177. package/lib/es2018/matchers/any-of.d.ts +0 -6
  178. package/lib/es2018/matchers/any-of.js +0 -10
  179. package/lib/es2018/matchers/any-of.js.map +0 -1
  180. package/lib/es2018/matchers/child-nodes.d.ts +0 -2
  181. package/lib/es2018/matchers/child-nodes.js +0 -27
  182. package/lib/es2018/matchers/child-nodes.js.map +0 -1
  183. package/lib/es2018/matchers/children.d.ts +0 -2
  184. package/lib/es2018/matchers/children.js +0 -27
  185. package/lib/es2018/matchers/children.js.map +0 -1
  186. package/lib/es2018/matchers/css.d.ts +0 -3
  187. package/lib/es2018/matchers/css.js +0 -18
  188. package/lib/es2018/matchers/css.js.map +0 -1
  189. package/lib/es2018/matchers/element.d.ts +0 -4
  190. package/lib/es2018/matchers/element.js +0 -34
  191. package/lib/es2018/matchers/element.js.map +0 -1
  192. package/lib/es2018/matchers/multiple.js +0 -42
  193. package/lib/es2018/matchers/multiple.js.map +0 -1
  194. package/lib/es2018/matchers/node.d.ts +0 -4
  195. package/lib/es2018/matchers/node.js +0 -31
  196. package/lib/es2018/matchers/node.js.map +0 -1
  197. package/lib/es2018/matchers/optional.d.ts +0 -2
  198. package/lib/es2018/matchers/optional.js +0 -9
  199. package/lib/es2018/matchers/optional.js.map +0 -1
  200. package/lib/es2018/matchers/repeat.d.ts +0 -2
  201. package/lib/es2018/matchers/repeat.js +0 -20
  202. package/lib/es2018/matchers/repeat.js.map +0 -1
  203. package/lib/es2018/matchers/tap.d.ts +0 -2
  204. package/lib/es2018/matchers/tap.js +0 -12
  205. package/lib/es2018/matchers/tap.js.map +0 -1
  206. package/lib/es2018/matchers/text-content-equals.js +0 -20
  207. package/lib/es2018/matchers/text-content-equals.js.map +0 -1
  208. package/lib/es2018/matchers/text-content-includes.js +0 -20
  209. package/lib/es2018/matchers/text-content-includes.js.map +0 -1
  210. package/lib/es2018/matchers/text-content-matches.d.ts +0 -6
  211. package/lib/es2018/matchers/text-content-matches.js +0 -16
  212. package/lib/es2018/matchers/text-content-matches.js.map +0 -1
  213. package/lib/es2018/matchers/text-node.d.ts +0 -4
  214. package/lib/es2018/matchers/text-node.js +0 -34
  215. package/lib/es2018/matchers/text-node.js.map +0 -1
  216. package/lib/es2018/matchers/xpath.d.ts +0 -3
  217. package/lib/es2018/matchers/xpath.js +0 -34
  218. package/lib/es2018/matchers/xpath.js.map +0 -1
  219. package/lib/es2018/types.d.ts +0 -18
  220. package/lib/es2018/types.js +0 -3
  221. package/lib/es2018/types.js.map +0 -1
  222. package/lib/es2018/utils/concat.d.ts +0 -1
  223. package/lib/es2018/utils/concat.js +0 -14
  224. package/lib/es2018/utils/concat.js.map +0 -1
  225. package/lib/es2018/utils/match-multiple.d.ts +0 -2
  226. package/lib/es2018/utils/match-multiple.js +0 -21
  227. package/lib/es2018/utils/match-multiple.js.map +0 -1
  228. package/lib/es2018/utils/match-one-by-one.d.ts +0 -2
  229. package/lib/es2018/utils/match-one-by-one.js +0 -38
  230. package/lib/es2018/utils/match-one-by-one.js.map +0 -1
  231. package/lib/es2018/utils/merge-in-place.d.ts +0 -5
  232. package/lib/es2018/utils/merge-in-place.js +0 -31
  233. package/lib/es2018/utils/merge-in-place.js.map +0 -1
  234. package/lib/es2018/utils/next-element-sibling.d.ts +0 -1
  235. package/lib/es2018/utils/next-element-sibling.js +0 -11
  236. package/lib/es2018/utils/next-element-sibling.js.map +0 -1
  237. package/lib/es2018/utils/next-sibling.d.ts +0 -1
  238. package/lib/es2018/utils/next-sibling.js +0 -11
  239. package/lib/es2018/utils/next-sibling.js.map +0 -1
  240. /package/lib/{es2015/utils → utils}/concat.d.ts +0 -0
  241. /package/lib/{es2015/utils → utils}/next-element-sibling.d.ts +0 -0
  242. /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(node
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(strings: TemplateStringsArray, ...values: string[]): ITerminalMatcher<Element>
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
- ): (...matchers: Array<INestedMatcher<Element> | ITerminalMatcher<Element>>) => INestedMatcher<Node>
140
- function element(name: string, ...matchers: Array<INestedMatcher<Element>>):
141
- INestedMatcher<Node>
142
- function element(...matchers: Array<INestedMatcher<Element>>):
143
- INestedMatcher<Node>
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
- ): (...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>) => INestedMatcher<Node>
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
- export function textContentIncludes(
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
- export function textContentMatches(
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
@@ -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"}
@@ -1,4 +1,4 @@
1
- import { IMatcher } from './types';
1
+ import { IMatcher } from './types.js';
2
2
  export declare function matchElement(this: void | Document, element: Element, ...matchers: Array<IMatcher<Element>>): {
3
3
  [name: string]: Node | Node[];
4
4
  } | null;
@@ -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"}
@@ -1,4 +1,4 @@
1
- import { IMatcher } from './types';
1
+ import { IMatcher } from './types.js';
2
2
  export declare function match(this: void | Document, node: Node, ...matchers: Array<IMatcher<Node>>): {
3
3
  [name: string]: Node | Node[];
4
4
  } | null;
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
@@ -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 '../types';
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,6 @@
1
+ export function anyOf(...matchers) {
2
+ return function (node) {
3
+ return matchers.some(match => match.call(this, node));
4
+ };
5
+ }
6
+ //# sourceMappingURL=any-of.js.map
@@ -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 '../types';
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 '../types';
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 '../types';
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 '../types';
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"}
@@ -1,4 +1,4 @@
1
- import { INestedMatcher, ITerminalMatcher, ISkipMatcher } from '../types';
1
+ import { INestedMatcher, ITerminalMatcher, ISkipMatcher } from "../types.js";
2
2
  export declare enum Range {
3
3
  Min = 0,
4
4
  Max = 1
@@ -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 '../types';
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 '../types';
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,5 @@
1
+ import { multiple } from './multiple.js';
2
+ export function optional(matcher) {
3
+ return multiple([0, 1], matcher, { greedy: true });
4
+ }
5
+ //# sourceMappingURL=optional.js.map
@@ -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 '../types';
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 '../types';
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,8 @@
1
+ export function tap(matcher, callback) {
2
+ return function (node) {
3
+ const result = matcher.call(this, node);
4
+ callback(result);
5
+ return result;
6
+ };
7
+ }
8
+ //# sourceMappingURL=tap.js.map
@@ -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"}
@@ -1,4 +1,4 @@
1
- import { ITerminalMatcher } from '../types';
1
+ import { ITerminalMatcher } from "../types.js";
2
2
  interface ITextContentEqualsOptions {
3
3
  caseSensitive?: boolean;
4
4
  trim?: boolean;
@@ -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