@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.
Files changed (97) hide show
  1. package/README.md +86 -36
  2. package/lib/index.d.ts +17 -17
  3. package/lib/index.js +17 -37
  4. package/lib/index.js.map +1 -1
  5. package/lib/match-element.d.ts +3 -4
  6. package/lib/match-element.js +9 -11
  7. package/lib/match-element.js.map +1 -1
  8. package/lib/match.d.ts +3 -4
  9. package/lib/match.js +9 -11
  10. package/lib/match.js.map +1 -1
  11. package/lib/matchers/any-of.d.ts +1 -1
  12. package/lib/matchers/any-of.js +1 -5
  13. package/lib/matchers/any-of.js.map +1 -1
  14. package/lib/matchers/child-nodes.d.ts +1 -1
  15. package/lib/matchers/child-nodes.js +10 -12
  16. package/lib/matchers/child-nodes.js.map +1 -1
  17. package/lib/matchers/children.d.ts +1 -1
  18. package/lib/matchers/children.js +10 -12
  19. package/lib/matchers/children.js.map +1 -1
  20. package/lib/matchers/css.d.ts +1 -1
  21. package/lib/matchers/css.js +5 -9
  22. package/lib/matchers/css.js.map +1 -1
  23. package/lib/matchers/element.d.ts +1 -1
  24. package/lib/matchers/element.js +11 -15
  25. package/lib/matchers/element.js.map +1 -1
  26. package/lib/matchers/multiple.d.ts +1 -1
  27. package/lib/matchers/multiple.js +14 -17
  28. package/lib/matchers/multiple.js.map +1 -1
  29. package/lib/matchers/node.d.ts +1 -1
  30. package/lib/matchers/node.js +9 -13
  31. package/lib/matchers/node.js.map +1 -1
  32. package/lib/matchers/optional.d.ts +1 -1
  33. package/lib/matchers/optional.js +3 -7
  34. package/lib/matchers/optional.js.map +1 -1
  35. package/lib/matchers/repeat.d.ts +1 -1
  36. package/lib/matchers/repeat.js +6 -10
  37. package/lib/matchers/repeat.js.map +1 -1
  38. package/lib/matchers/tap.d.ts +1 -1
  39. package/lib/matchers/tap.js +1 -5
  40. package/lib/matchers/tap.js.map +1 -1
  41. package/lib/matchers/text-content-equals.d.ts +1 -1
  42. package/lib/matchers/text-content-equals.js +3 -7
  43. package/lib/matchers/text-content-equals.js.map +1 -1
  44. package/lib/matchers/text-content-includes.d.ts +1 -1
  45. package/lib/matchers/text-content-includes.js +3 -7
  46. package/lib/matchers/text-content-includes.js.map +1 -1
  47. package/lib/matchers/text-content-matches.d.ts +1 -1
  48. package/lib/matchers/text-content-matches.js +3 -7
  49. package/lib/matchers/text-content-matches.js.map +1 -1
  50. package/lib/matchers/text-node.d.ts +1 -1
  51. package/lib/matchers/text-node.js +10 -14
  52. package/lib/matchers/text-node.js.map +1 -1
  53. package/lib/matchers/xpath.d.ts +1 -1
  54. package/lib/matchers/xpath.js +8 -12
  55. package/lib/matchers/xpath.js.map +1 -1
  56. package/lib/types.d.ts +7 -6
  57. package/lib/types.js +1 -2
  58. package/lib/utils/match-multiple.d.ts +4 -1
  59. package/lib/utils/match-multiple.js +6 -7
  60. package/lib/utils/match-multiple.js.map +1 -1
  61. package/lib/utils/match-one-by-one.d.ts +1 -1
  62. package/lib/utils/match-one-by-one.js +10 -10
  63. package/lib/utils/match-one-by-one.js.map +1 -1
  64. package/lib/utils/merge-in-place.d.ts +2 -5
  65. package/lib/utils/merge-in-place.js +5 -9
  66. package/lib/utils/merge-in-place.js.map +1 -1
  67. package/lib/utils/next-element-sibling.js +2 -6
  68. package/lib/utils/next-element-sibling.js.map +1 -1
  69. package/lib/utils/next-sibling.js +2 -6
  70. package/lib/utils/next-sibling.js.map +1 -1
  71. package/package.json +30 -29
  72. package/src/index.ts +17 -17
  73. package/src/match-element.ts +9 -5
  74. package/src/match.ts +9 -5
  75. package/src/matchers/any-of.ts +1 -1
  76. package/src/matchers/child-nodes.ts +6 -5
  77. package/src/matchers/children.ts +6 -5
  78. package/src/matchers/css.ts +4 -4
  79. package/src/matchers/element.ts +42 -17
  80. package/src/matchers/multiple.ts +3 -3
  81. package/src/matchers/node.ts +35 -13
  82. package/src/matchers/optional.ts +5 -3
  83. package/src/matchers/repeat.ts +3 -3
  84. package/src/matchers/tap.ts +1 -1
  85. package/src/matchers/text-content-equals.ts +2 -2
  86. package/src/matchers/text-content-includes.ts +2 -2
  87. package/src/matchers/text-content-matches.ts +2 -2
  88. package/src/matchers/text-node.ts +13 -9
  89. package/src/matchers/xpath.ts +10 -10
  90. package/src/types.ts +7 -4
  91. package/src/utils/match-multiple.ts +1 -1
  92. package/src/utils/match-one-by-one.ts +3 -3
  93. package/src/utils/merge-in-place.ts +3 -3
  94. package/lib/utils/concat.d.ts +0 -1
  95. package/lib/utils/concat.js +0 -14
  96. package/lib/utils/concat.js.map +0 -1
  97. 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
- const result = matchElement(node
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`section`
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
- // { heading: Text, paragraph: [ Text, Text ] }
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
- ): { [name: string]: Node | Node[] } | null
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
- ): { [name: string]: Node | Node[] } | null
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(strings: TemplateStringsArray, ...values: string[]): ITerminalMatcher<Element>
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
- ): (...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>
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
- ): (...matchers: Array<INestedMatcher<Node> | ITerminalMatcher<Node>>) => INestedMatcher<Node>
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
- export function textContentIncludes(
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
- export function textContentMatches(
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 './matchers/any-of';
4
- export { childNodes } from './matchers/child-nodes';
5
- export { children } from './matchers/children';
6
- export { css } from './matchers/css';
7
- export { element } from './matchers/element';
8
- export { multiple } from './matchers/multiple';
9
- export { node } from './matchers/node';
10
- export { optional } from './matchers/optional';
11
- export { repeat } from './matchers/repeat';
12
- export { tap } from './matchers/tap';
13
- export { textContentEquals } from './matchers/text-content-equals';
14
- export { textContentIncludes } from './matchers/text-content-includes';
15
- export { textContentMatches } from './matchers/text-content-matches';
16
- export { textNode } from './matchers/text-node';
17
- export { xpath } from './matchers/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";
package/lib/index.js CHANGED
@@ -1,38 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.xpath = exports.textNode = exports.textContentMatches = exports.textContentIncludes = exports.textContentEquals = exports.tap = exports.repeat = exports.optional = exports.node = exports.multiple = exports.element = exports.css = exports.children = exports.childNodes = exports.anyOf = exports.matchElement = exports.match = void 0;
4
- var match_1 = require("./match");
5
- Object.defineProperty(exports, "match", { enumerable: true, get: function () { return match_1.match; } });
6
- var match_element_1 = require("./match-element");
7
- Object.defineProperty(exports, "matchElement", { enumerable: true, get: function () { return match_element_1.matchElement; } });
8
- var any_of_1 = require("./matchers/any-of");
9
- Object.defineProperty(exports, "anyOf", { enumerable: true, get: function () { return any_of_1.anyOf; } });
10
- var child_nodes_1 = require("./matchers/child-nodes");
11
- Object.defineProperty(exports, "childNodes", { enumerable: true, get: function () { return child_nodes_1.childNodes; } });
12
- var children_1 = require("./matchers/children");
13
- Object.defineProperty(exports, "children", { enumerable: true, get: function () { return children_1.children; } });
14
- var css_1 = require("./matchers/css");
15
- Object.defineProperty(exports, "css", { enumerable: true, get: function () { return css_1.css; } });
16
- var element_1 = require("./matchers/element");
17
- Object.defineProperty(exports, "element", { enumerable: true, get: function () { return element_1.element; } });
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":";;;AAAA,iCAA+B;AAAtB,8FAAA,KAAK,OAAA;AACd,iDAA8C;AAArC,6GAAA,YAAY,OAAA;AAErB,2CAAwC;AAA/B,+FAAA,KAAK,OAAA;AACd,qDAAkD;AAAzC,yGAAA,UAAU,OAAA;AACnB,+CAA6C;AAApC,oGAAA,QAAQ,OAAA;AACjB,qCAAmC;AAA1B,0FAAA,GAAG,OAAA;AACZ,6CAA2C;AAAlC,kGAAA,OAAO,OAAA;AAChB,+CAA6C;AAApC,oGAAA,QAAQ,OAAA;AACjB,uCAAqC;AAA5B,4FAAA,IAAI,OAAA;AACb,+CAA6C;AAApC,oGAAA,QAAQ,OAAA;AACjB,2CAAyC;AAAhC,gGAAA,MAAM,OAAA;AACf,qCAAmC;AAA1B,0FAAA,GAAG,OAAA;AACZ,qEAAiE;AAAxD,wHAAA,iBAAiB,OAAA;AAC1B,yEAAqE;AAA5D,4HAAA,mBAAmB,OAAA;AAC5B,uEAAmE;AAA1D,0HAAA,kBAAkB,OAAA;AAC3B,iDAA8C;AAArC,qGAAA,QAAQ,OAAA;AACjB,yCAAuC;AAA9B,8FAAA,KAAK,OAAA"}
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,3 @@
1
- import { IMatcher } from './types';
2
- export declare function matchElement(this: void | Document, element: Element, ...matchers: Array<IMatcher<Element>>): {
3
- [name: string]: Node | Node[];
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;
@@ -1,22 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matchElement = void 0;
4
- const extra_dom_1 = require("extra-dom");
5
- const match_one_by_one_1 = require("./utils/match-one-by-one");
6
- const next_element_sibling_1 = require("./utils/next-element-sibling");
7
- function matchElement(element, ...matchers) {
8
- const document = (0, extra_dom_1.isDocument)(this) ? this : globalThis.document;
1
+ import { isDocument } from 'extra-dom';
2
+ import { matchOneByOne } from "./utils/match-one-by-one.js";
3
+ import { nextElementSibling } from "./utils/next-element-sibling.js";
4
+ export function matchElement(element, ...matchers) {
5
+ const document = isDocument(this)
6
+ ? this
7
+ : globalThis.document;
9
8
  const context = {
10
9
  document,
11
10
  collection: {},
12
- next: next_element_sibling_1.nextElementSibling
11
+ next: nextElementSibling
13
12
  };
14
- if ((0, match_one_by_one_1.matchOneByOne)(context, element, ...matchers)) {
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
@@ -1 +1 @@
1
- {"version":3,"file":"match-element.js","sourceRoot":"","sources":["../src/match-element.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAEtC,8DAAuD;AACvD,sEAAgE;AAEhE,SAAgB,YAAY,CAE1B,OAAgB,EAChB,GAAG,QAAkC;IAErC,MAAM,QAAQ,GAAG,IAAA,sBAAU,EAAC,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,yCAAkB;KACzB,CAAA;IAED,IAAI,IAAA,gCAAa,EAAC,OAAO,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,EAAE;QAChD,OAAO,OAAO,CAAC,UAAU,CAAA;KAC1B;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AAjBD,oCAiBC"}
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
- export declare function match(this: void | Document, node: Node, ...matchers: Array<IMatcher<Node>>): {
3
- [name: string]: Node | Node[];
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.match = void 0;
4
- const extra_dom_1 = require("extra-dom");
5
- const match_one_by_one_1 = require("./utils/match-one-by-one");
6
- const next_sibling_1 = require("./utils/next-sibling");
7
- function match(node, ...matchers) {
8
- const document = (0, extra_dom_1.isDocument)(this) ? this : globalThis.document;
1
+ import { isDocument } from 'extra-dom';
2
+ import { matchOneByOne } from "./utils/match-one-by-one.js";
3
+ import { nextSibling } from "./utils/next-sibling.js";
4
+ export function match(node, ...matchers) {
5
+ const document = isDocument(this)
6
+ ? this
7
+ : globalThis.document;
9
8
  const context = {
10
9
  document,
11
10
  collection: {},
12
- next: next_sibling_1.nextSibling
11
+ next: nextSibling
13
12
  };
14
- if ((0, match_one_by_one_1.matchOneByOne)(context, node, ...matchers)) {
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":";;;AAAA,yCAAsC;AAEtC,8DAAuD;AACvD,sDAAiD;AAEjD,SAAgB,KAAK,CAEnB,IAAU,EACV,GAAG,QAA+B;IAElC,MAAM,QAAQ,GAAG,IAAA,sBAAU,EAAC,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,0BAAW;KAClB,CAAA;IAED,IAAI,IAAA,gCAAa,EAAC,OAAO,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,EAAE;QAC7C,OAAO,OAAO,CAAC,UAAU,CAAA;KAC1B;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AAjBD,sBAiBC"}
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"}
@@ -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>,
@@ -1,10 +1,6 @@
1
- "use strict";
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":";;;AAEA,SAAgB,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;AAVD,sBAUC"}
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>;
@@ -1,12 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.childNodes = void 0;
4
- const match_one_by_one_1 = require("../utils/match-one-by-one");
5
- const merge_in_place_1 = require("../utils/merge-in-place");
6
- const next_sibling_1 = require("../utils/next-sibling");
7
- function childNodes(...matchers) {
1
+ import { 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
- if (matchers.length === 0) {
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: next_sibling_1.nextSibling
16
+ next: nextSibling
18
17
  };
19
- const result = (0, match_one_by_one_1.matchOneByOne)(context, node.childNodes[0], ...matchers);
18
+ const result = matchOneByOne(context, node.childNodes[0], ...matchers);
20
19
  if (result) {
21
- (0, merge_in_place_1.mergeInPlace)(this.collection, context.collection);
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":";;;AACA,8DAAuD;AACvD,0DAAoD;AACpD,sDAAiD;AAEjD,SAAgB,UAAU,CAAC,GAAG,QAA+B;IAC3D,OAAO,UAAkC,IAAU;QAEjD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAA;SACpC;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,0BAAW;SAClB,CAAA;QAED,MAAM,MAAM,GAAG,IAAA,gCAAa,EAC1B,OAAO,EACP,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAClB,GAAG,QAAQ,CACZ,CAAA;QAED,IAAI,MAAM,EAAE;YACV,IAAA,6BAAY,EAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;SAClD;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AA3BD,gCA2BC"}
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 '../types';
1
+ import { IMatcher, INestedMatcher } from "../types.js";
2
2
  export declare function children(...matchers: Array<IMatcher<Element>>): INestedMatcher<Element>;
@@ -1,12 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.children = void 0;
4
- const match_one_by_one_1 = require("../utils/match-one-by-one");
5
- const merge_in_place_1 = require("../utils/merge-in-place");
6
- const next_element_sibling_1 = require("../utils/next-element-sibling");
7
- function children(...matchers) {
1
+ import { 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
- if (matchers.length === 0) {
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: next_element_sibling_1.nextElementSibling
16
+ next: nextElementSibling
18
17
  };
19
- const result = (0, match_one_by_one_1.matchOneByOne)(context, element.children[0], ...matchers);
18
+ const result = matchOneByOne(context, element.children[0], ...matchers);
20
19
  if (result) {
21
- (0, merge_in_place_1.mergeInPlace)(this.collection, context.collection);
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":";;;AACA,8DAAuD;AACvD,0DAAoD;AACpD,sEAAgE;AAEhE,SAAgB,QAAQ,CACtB,GAAG,QAAkC;IAErC,OAAO,UAAkC,OAAgB;QAEvD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAA;SACrC;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,yCAAkB;SACzB,CAAA;QAED,MAAM,MAAM,GAAG,IAAA,gCAAa,EAC1B,OAAO,EACP,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EACnB,GAAG,QAAQ,CACZ,CAAA;QAED,IAAI,MAAM,EAAE;YACV,IAAA,6BAAY,EAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;SAClD;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AA7BD,4BA6BC"}
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"}
@@ -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>;
@@ -1,18 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.css = void 0;
4
- const concat_1 = require("../utils/concat");
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 = (0, concat_1.concat)(strings, values).join('');
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