@tb-dev/prototype-dom 6.1.0 → 6.1.2

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 (3) hide show
  1. package/dist/index.d.ts +146 -23
  2. package/dist/index.js +195 -256
  3. package/package.json +4 -4
package/dist/index.d.ts CHANGED
@@ -1,37 +1,160 @@
1
1
  declare global {
2
- interface ArrayConstructor {
3
- fromElements: <T extends Element[] | NodeList | string, V>(source: T, valueSelector: (element: Element) => V) => V[];
4
- }
5
2
  interface Document {
6
- queryStrict: <T extends Element>(selector: string) => T;
7
- queryAsArray: <T = Element>(selector: string, valueSelector?: (element: Element) => T) => T[];
8
- queryAsSet: <T = Element>(selector: string, valueSelector?: (element: Element) => T) => Set<T>;
9
- queryAsMap: <T extends Element, K, V = T>(selector: string, keySelector: (element: T) => K, valueSelector?: (element: T) => V) => Map<K, V>;
3
+ /**
4
+ * Return the first element that is a descendant of node that matches selector.
5
+ * @param selectors CSS selector to match.
6
+ *
7
+ * @throws {Error} If no element is found.
8
+ */
9
+ queryStrict: <T extends Element = Element>(selectors: string) => T;
10
+ /**
11
+ * Query all element descendants of node that match selector, then create an {@link Array} from the result.
12
+ *
13
+ * The values of the array can be customized by providing a `valueFn` function.
14
+ * Defaults to the element itself.
15
+ * @param selector CSS selector to match.
16
+ */
17
+ queryAsArray: <T = Element>(selector: string, valueFn?: (element: Element) => T) => T[];
18
+ /**
19
+ * Query all element descendants of node that match selector, then create a {@link Set} from the result.
20
+ *
21
+ * The values of the set can be customized by providing a `valueFn` function.
22
+ * Defaults to the elements themselves.
23
+ * @param selector CSS selector to match.
24
+ */
25
+ queryAsSet: <T = Element>(selector: string, valueFn?: (element: Element) => T) => Set<T>;
26
+ /**
27
+ * Query all element descendants of node that match selector, then create a {@link Map} from the result.
28
+ *
29
+ * The keys of the map are determined by the required `keyFn` function.
30
+ *
31
+ * The values can be customized by providing a `valueFn` function. Default to the elements themselves.
32
+ * @param selector CSS selector to match.
33
+ * @param keyFn Function that returns the key for each element.
34
+ * @param valueFn Function that returns the value for each element.
35
+ */
36
+ queryAsMap: <T extends Element, K, V = T>(selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
37
+ /**
38
+ * Wait for the first descendant element that matches the given selector to exist.
39
+ * @param selector CSS selector to match.
40
+ * @param timeout Maximum time to wait for the element, in milliseconds.
41
+ */
10
42
  waitChild: (selector: string, timeout?: number) => Promise<Element>;
11
43
  }
12
44
  interface Element {
13
- getAttributeStrict: <T extends string>(qualifiedName: string) => T;
14
- getAttributeAsFloatStrict: (qualifiedName: string, allowNegative?: boolean) => number;
15
- getAttributeAsIntStrict: (qualifiedName: string, radix?: number, allowNegative?: boolean) => number;
16
- getTextStrict: <T extends string>() => T;
17
- getTextAsIntStrict: (radix?: number, allowNegative?: boolean) => number;
18
- getTextAsFloatStrict: (allowNegative?: boolean) => number;
19
- queryAsArray: <T = Element>(selector: string, valueSelector?: (element: Element) => T) => T[];
20
- queryAsSet: <T = Element>(selector: string, valueSelector?: (element: Element) => T) => Set<T>;
45
+ /**
46
+ * Return the first attribute whose qualified name is `name`.
47
+ * @param name Attribute to search for.
48
+ *
49
+ * @throws {Error} If the attribute is not found.
50
+ */
51
+ getAttributeStrict: (name: string) => string;
52
+ /**
53
+ * Get the first attribute whose qualified name is `name`,
54
+ * then tries to parse the attribute as a floating point number.
55
+ * @param name Attribute to search for.
56
+ *
57
+ * @throws {Error} If the attribute is not found.
58
+ * @throws {TypeError} If the attribute cannot be parsed as a floating point number.
59
+ */
60
+ getAttributeAsFloatStrict: (name: string) => number;
61
+ /**
62
+ * Get the first attribute whose qualified name is `name`,
63
+ * then tries to parse the attribute as an integer using the specified radix.
64
+ * @param name Attribute to search for.
65
+ * @param radix A value between 2 and 36 that specifies the base of the number.
66
+ *
67
+ * @throws {Error} If the attribute is not found.
68
+ * @throws {TypeError} If the attribute cannot be parsed as an integer.
69
+ */
70
+ getAttributeAsIntStrict: (name: string, radix?: number) => number;
71
+ /**
72
+ * Return the text content of the element.
73
+ *
74
+ * @throws {Error} If the element has no text content.
75
+ */
76
+ getTextStrict: () => string;
77
+ /**
78
+ * Get the text content of the element, then tries to parse it as an integer.
79
+ * @param radix A value between 2 and 36 that specifies the base of the number.
80
+ *
81
+ * @throws {Error} If the element has no text content.
82
+ * @throws {TypeError} If the text content cannot be parsed as an integer.
83
+ */
84
+ getTextAsIntStrict: (radix?: number) => number;
85
+ /**
86
+ * Get the text content of the element, then tries to parse it as a floating point number.
87
+ *
88
+ * @throws {Error} If the element has no text content.
89
+ * @throws {TypeError} If the text content cannot be parsed as a floating point number.
90
+ */
91
+ getTextAsFloatStrict: () => number;
92
+ /**
93
+ * Query all element descendants of node that match selector, then create an {@link Array} from the result.
94
+ *
95
+ * The values of the array can be customized by providing a `valueFn` function.
96
+ * Defaults to the element itself.
97
+ * @param selector CSS selector to match.
98
+ */
99
+ queryAsArray: <T = Element>(selector: string, valueFn?: (element: Element) => T) => T[];
100
+ /**
101
+ * Query all element descendants of node that match selector, then create a {@link Set} from the result.
102
+ *
103
+ * The values of the set can be customized by providing a `valueFn` function.
104
+ * Defaults to the elements themselves.
105
+ * @param selector CSS selector to match.
106
+ */
107
+ queryAsSet: <T = Element>(selector: string, valueFn?: (element: Element) => T) => Set<T>;
108
+ /**
109
+ * Return the first element that is a descendant of node that matches selector.
110
+ * @param selectors CSS selector to match.
111
+ *
112
+ * @throws {Error} If no element is found.
113
+ */
21
114
  queryStrict: <T extends Element>(selector: string) => T;
22
- queryAsMap: <T extends Element, K, V = T>(selector: string, keySelector: (element: T) => K, valueSelector?: (element: T) => V) => Map<K, V>;
115
+ /**
116
+ * Query all element descendants of node that match selector, then create a {@link Map} from the result.
117
+ *
118
+ * The keys of the map are determined by the required `keyFn` function.
119
+ *
120
+ * The values can be customized by providing a `valueFn` function. Default to the elements themselves.
121
+ * @param selector CSS selector to match.
122
+ * @param keyFn Function that returns the key for each element.
123
+ * @param valueFn Function that returns the value for each element.
124
+ */
125
+ queryAsMap: <T extends Element, K, V = T>(selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
126
+ /**
127
+ * Wait for the first descendant element that matches the given selector to exist.
128
+ * @param selector CSS selector to match.
129
+ * @param timeout Maximum time to wait for the element, in milliseconds.
130
+ */
23
131
  waitChild: (selector: string, timeout?: number) => Promise<Element>;
24
132
  }
25
133
  interface URLSearchParams {
26
- getStrict: <T extends string>(name: string) => T;
134
+ /**
135
+ * Return the first value associated to the given search parameter.
136
+ * @param name The name of the search parameter to get.
137
+ *
138
+ * @throws {Error} If the search parameter is not found.
139
+ */
140
+ getStrict: (name: string) => string;
141
+ /**
142
+ * Get the first value associated to the given search parameter, then tries to parse it as an integer.
143
+ * The returned value may be `NaN` if it cannot be parsed as an integer.
144
+ * To throw an error if the value cannot be parsed, use {@link getAsIntegerStrict} instead.
145
+ * @param name The name of the search parameter to get.
146
+ * @param radix A value between 2 and 36 that specifies the base of the number.
147
+ */
27
148
  getAsInteger: (name: string, radix?: number) => number | null;
149
+ /**
150
+ * Get the first value associated to the given search parameter, then tries to parse it as an integer.
151
+ * @param name The name of the search parameter to get.
152
+ * @param radix A value between 2 and 36 that specifies the base of the number.
153
+ *
154
+ * @throws {Error} If the search parameter is not found.
155
+ * @throws {TypeError} If the value cannot be parsed as an integer.
156
+ */
28
157
  getAsIntegerStrict: (name: string, radix?: number) => number;
29
158
  }
30
- interface MapConstructor {
31
- fromElements: <T extends Element[] | NodeList | string, K, V>(source: T, keySelector: (element: Element) => K, valueSelector: (element: Element) => V) => Map<K, V>;
32
- }
33
- interface SetConstructor {
34
- fromElements: <T extends Element[] | NodeList | string, K>(source: T, valueSelector: (element: Element) => K) => Set<K>;
35
- }
36
159
  }
37
160
  export {};
package/dist/index.js CHANGED
@@ -1,273 +1,212 @@
1
1
  (function () {
2
2
  'use strict';
3
3
 
4
- Document.prototype.queryStrict = function (selector) {
5
- const element = this.querySelector(selector);
6
- if (!element)
7
- throw new Error(`No element found for selector "${selector}"`);
8
- return element;
9
- };
10
- Document.prototype.queryAsArray = function (selector, valueSelector) {
11
- valueSelector ??= (element) => element;
12
- const elements = this.querySelectorAll(selector);
13
- return Array.from(elements, valueSelector);
14
- };
15
- Document.prototype.queryAsSet = function (selector, valueSelector) {
16
- valueSelector ??= (element) => element;
17
- const elements = this.queryAsArray(selector, valueSelector);
18
- return new Set(elements);
19
- };
20
- Document.prototype.queryAsMap = function (selector, keySelector, valueSelector = (el) => el) {
21
- const elements = this.queryAsArray(selector);
22
- const map = new Map();
23
- for (const element of elements) {
24
- const key = keySelector(element);
25
- const value = valueSelector(element);
26
- map.set(key, value);
27
- }
28
- return map;
29
- };
30
- Document.prototype.waitChild = function (selector, timeoutMillis = 300_000) {
31
- const el = this.querySelector(selector);
32
- if (el)
33
- return Promise.resolve(el);
34
- return new Promise((resolve, reject) => {
35
- let timeout = null;
36
- let interval = null;
37
- const observer = new MutationObserver((mutations) => {
38
- const element = this.querySelector(selector);
39
- if (element) {
40
- onElementFound(element);
41
- return;
42
- }
43
- for (const mutation of mutations) {
44
- if (mutation.type !== 'childList')
45
- continue;
46
- for (const node of Array.from(mutation.addedNodes)) {
47
- if (node instanceof Element && node.matches(`:has(${selector})`)) {
48
- onElementFound(node);
49
- return;
50
- }
51
- }
52
- }
53
- });
54
- function onElementFound(element) {
55
- if (typeof timeout === 'number')
56
- clearTimeout(timeout);
57
- if (typeof interval === 'number')
58
- clearInterval(interval);
59
- observer.disconnect();
60
- resolve(element);
4
+ function getAttributeStrict() {
5
+ return function (attribute) {
6
+ const attr = this.getAttribute(attribute)?.trim();
7
+ if (typeof attr !== 'string' || attr.length === 0) {
8
+ throw new Error(`attribute "${attribute}" not found`);
61
9
  }
62
- function onInterval() {
63
- const element = this.querySelector(selector);
64
- if (element) {
65
- onElementFound(element);
66
- }
10
+ return attr;
11
+ };
12
+ }
13
+ function getAttributeAsFloatStrict() {
14
+ return function (attribute) {
15
+ const attr = this.getAttributeStrict(attribute);
16
+ const value = Number.parseFloat(attr.trim());
17
+ if (!Number.isFinite(value)) {
18
+ throw new TypeError(`could not parse attribute "${attribute}" as float`);
67
19
  }
68
- function onTimeout() {
69
- if (typeof interval === 'number')
70
- clearInterval(interval);
71
- observer.disconnect();
72
- reject(new Error(`timeout waiting for element: ${selector}`));
20
+ return value;
21
+ };
22
+ }
23
+ function getAttributeAsIntStrict() {
24
+ return function (attribute, radix = 10) {
25
+ const attr = this.getAttributeStrict(attribute);
26
+ const value = Number.parseInt(attr.trim(), radix);
27
+ if (!Number.isInteger(value)) {
28
+ throw new TypeError(`could not parse attribute "${attribute}" as integer`);
73
29
  }
74
- interval = setInterval(onInterval.bind(this), 100);
75
- timeout = setTimeout(onTimeout, timeoutMillis);
76
- observer.observe(this, { childList: true, subtree: true });
77
- });
78
- };
79
- Element.prototype.getAttributeStrict = function (attribute) {
80
- const value = this.getAttribute(attribute)?.trim();
81
- if (typeof value !== 'string' || value.length === 0) {
82
- throw new Error(`attribute "${attribute}" not found`);
83
- }
84
- return value;
85
- };
86
- Element.prototype.getAttributeAsFloatStrict = function (attribute) {
87
- const value = this.getAttributeStrict(attribute);
88
- const parsed = Number.parseFloat(value);
89
- if (!Number.isFinite(parsed))
90
- throw new Error(`could not parse attribute "${attribute}" as float`);
91
- return parsed;
92
- };
93
- Element.prototype.getAttributeAsIntStrict = function (attribute, radix = 10) {
94
- const value = this.getAttributeStrict(attribute);
95
- const parsed = Number.parseInt(value.replace(/\D/g, ''), radix);
96
- if (!Number.isInteger(parsed)) {
97
- throw new TypeError(`could not parse attribute "${attribute}" as integer`);
98
- }
99
- return parsed;
100
- };
101
- Element.prototype.getTextStrict = function () {
102
- const content = this.textContent?.trim();
103
- if (typeof content !== 'string' || content.length === 0) {
104
- throw new Error('element has no text content');
105
- }
106
- return content;
107
- };
108
- Element.prototype.getTextAsIntStrict = function (radix = 10) {
109
- const content = this.getTextStrict();
110
- const parsed = Number.parseInt(content.replace(/\D/g, ''), radix);
111
- if (!Number.isInteger(parsed)) {
112
- throw new TypeError('could not parse text content as integer');
113
- }
114
- return parsed;
115
- };
116
- Element.prototype.getTextAsFloatStrict = function () {
117
- const content = this.getTextStrict();
118
- const parsed = Number.parseFloat(content);
119
- if (!Number.isFinite(parsed)) {
120
- throw new TypeError('could not parse text content as float');
121
- }
122
- return parsed;
123
- };
124
- Element.prototype.queryStrict = function (selector) {
125
- const element = this.querySelector(selector);
126
- if (!element)
127
- throw new Error(`no element found for selector "${selector}"`);
128
- return element;
129
- };
130
- Element.prototype.queryAsArray = function (selector, valueSelector) {
131
- valueSelector ??= (element) => element;
132
- const elements = this.querySelectorAll(selector);
133
- return Array.from(elements, valueSelector);
134
- };
135
- Element.prototype.queryAsSet = function (selector, valueSelector) {
136
- valueSelector ??= (element) => element;
137
- const elements = this.queryAsArray(selector, valueSelector);
138
- return new Set(elements);
139
- };
140
- Element.prototype.queryAsMap = function (selector, keySelector, valueSelector = (el) => el) {
141
- const elements = this.queryAsArray(selector);
142
- const map = new Map();
143
- for (const element of elements) {
144
- const key = keySelector(element);
145
- const value = valueSelector(element);
146
- map.set(key, value);
147
- }
148
- return map;
149
- };
150
- Element.prototype.waitChild = function (selector, timeoutMillis = 300_000) {
151
- const el = this.querySelector(selector);
152
- if (el)
153
- return Promise.resolve(el);
154
- return new Promise((resolve, reject) => {
155
- let timeout = null;
156
- let interval = null;
157
- const observer = new MutationObserver((mutations) => {
158
- const element = this.querySelector(selector);
159
- if (element) {
160
- onElementFound(element);
161
- return;
162
- }
163
- for (const mutation of mutations) {
164
- if (mutation.type !== 'childList')
165
- continue;
166
- for (const node of Array.from(mutation.addedNodes)) {
167
- if (node instanceof Element && node.matches(`:has(${selector})`)) {
168
- onElementFound(node);
169
- return;
30
+ return value;
31
+ };
32
+ }
33
+ function getTextStrict() {
34
+ return function () {
35
+ const text = this.textContent?.trim();
36
+ if (typeof text !== 'string' || text.length === 0) {
37
+ throw new Error('element has no text content');
38
+ }
39
+ return text;
40
+ };
41
+ }
42
+ function getTextAsIntStrict() {
43
+ return function (radix = 10) {
44
+ const value = Number.parseInt(this.getTextStrict(), radix);
45
+ if (!Number.isInteger(value)) {
46
+ throw new TypeError('could not parse text content as integer');
47
+ }
48
+ return value;
49
+ };
50
+ }
51
+ function getTextAsFloatStrict() {
52
+ return function () {
53
+ const value = Number.parseFloat(this.getTextStrict());
54
+ if (!Number.isFinite(value)) {
55
+ throw new TypeError('could not parse text content as float');
56
+ }
57
+ return value;
58
+ };
59
+ }
60
+ function queryStrict() {
61
+ return function (selector) {
62
+ const element = this.querySelector(selector);
63
+ if (!element)
64
+ throw new Error(`no element found for selector "${selector}"`);
65
+ return element;
66
+ };
67
+ }
68
+ function queryAsArray() {
69
+ return function (selector, valueFn) {
70
+ valueFn ??= (element) => element;
71
+ const elements = this.querySelectorAll(selector);
72
+ return Array.from(elements, valueFn);
73
+ };
74
+ }
75
+ function queryAsSet() {
76
+ return function (selector, valueFn) {
77
+ valueFn ??= (element) => element;
78
+ const elements = this.queryAsArray(selector, valueFn);
79
+ return new Set(elements);
80
+ };
81
+ }
82
+ function queryAsMap() {
83
+ return function (selector, keyFn, valueFn) {
84
+ valueFn ??= (element) => element;
85
+ const elements = this.queryAsArray(selector);
86
+ const map = new Map();
87
+ for (const element of elements) {
88
+ const key = keyFn(element);
89
+ const value = valueFn(element);
90
+ map.set(key, value);
91
+ }
92
+ return map;
93
+ };
94
+ }
95
+ function waitChild() {
96
+ return function (selector, timeoutMillis = 300_000) {
97
+ const el = this.querySelector(selector);
98
+ if (el)
99
+ return Promise.resolve(el);
100
+ return new Promise((resolve, reject) => {
101
+ let timeout = null;
102
+ let interval = null;
103
+ const observer = new MutationObserver((mutations) => {
104
+ const element = this.querySelector(selector);
105
+ if (element) {
106
+ onElementFound(element);
107
+ return;
108
+ }
109
+ for (const mutation of mutations) {
110
+ if (mutation.type !== 'childList')
111
+ continue;
112
+ for (const node of Array.from(mutation.addedNodes)) {
113
+ if (node instanceof Element && node.matches(`:has(${selector})`)) {
114
+ onElementFound(node);
115
+ return;
116
+ }
170
117
  }
171
118
  }
119
+ });
120
+ function onElementFound(element) {
121
+ if (typeof timeout === 'number')
122
+ clearTimeout(timeout);
123
+ if (typeof interval === 'number')
124
+ clearInterval(interval);
125
+ observer.disconnect();
126
+ resolve(element);
172
127
  }
173
- });
174
- function onElementFound(element) {
175
- if (typeof timeout === 'number')
176
- clearTimeout(timeout);
177
- if (typeof interval === 'number')
178
- clearInterval(interval);
179
- observer.disconnect();
180
- resolve(element);
181
- }
182
- function onInterval() {
183
- const element = this.querySelector(selector);
184
- if (element) {
185
- onElementFound(element);
128
+ function onInterval() {
129
+ const element = this.querySelector(selector);
130
+ if (element)
131
+ onElementFound(element);
186
132
  }
187
- }
188
- function onTimeout() {
189
- if (typeof interval === 'number')
190
- clearInterval(interval);
191
- observer.disconnect();
192
- reject(new Error(`timeout waiting for element: ${selector}`));
193
- }
194
- interval = setInterval(onInterval.bind(this), 100);
195
- timeout = setTimeout(onTimeout, timeoutMillis);
196
- observer.observe(this, { childList: true, subtree: true });
197
- });
198
- };
199
- URLSearchParams.prototype.getStrict = function (name) {
200
- const item = this.get(name);
201
- if (item === null) {
202
- throw new Error(`key "${name}" not found in URL search parameters`);
203
- }
204
- return item;
205
- };
206
- URLSearchParams.prototype.getAsInteger = function (name, radix = 10) {
207
- const item = this.get(name);
208
- if (item === null)
209
- return item;
210
- return Number.parseInt(item, radix);
211
- };
212
- URLSearchParams.prototype.getAsIntegerStrict = function (name, radix = 10) {
213
- const item = this.getStrict(name);
214
- const parsed = Number.parseInt(item, radix);
215
- if (!Number.isInteger(parsed)) {
216
- throw new TypeError(`could not parse "${item}" as an integer`);
217
- }
218
- return parsed;
219
- };
220
- Array.fromElements = function (source, valueSelector) {
221
- isValidElementSource(source);
222
- const elements = parseElementSource(source);
223
- return Array.from(elements, valueSelector);
133
+ function onTimeout() {
134
+ if (typeof interval === 'number')
135
+ clearInterval(interval);
136
+ observer.disconnect();
137
+ reject(new Error(`timeout waiting for element: ${selector}`));
138
+ }
139
+ interval = setInterval(onInterval.bind(this), 100);
140
+ timeout = setTimeout(onTimeout, timeoutMillis);
141
+ observer.observe(this, { childList: true, subtree: true });
142
+ });
143
+ };
144
+ }
145
+ const element = {
146
+ getAttributeStrict,
147
+ getAttributeAsFloatStrict,
148
+ getAttributeAsIntStrict,
149
+ getTextStrict,
150
+ getTextAsIntStrict,
151
+ getTextAsFloatStrict,
152
+ queryStrict,
153
+ queryAsArray,
154
+ queryAsSet,
155
+ queryAsMap,
156
+ waitChild
224
157
  };
225
- Map.fromElements = function (source, keySelector, valueSelector) {
226
- isValidElementSource(source);
227
- const elements = parseElementSource(source);
228
- const map = new Map();
229
- for (const element of elements) {
230
- if (!(element instanceof Element)) {
231
- throw new TypeError('item in source array is not an element');
158
+
159
+ function getStrict() {
160
+ return function (name) {
161
+ const item = this.get(name);
162
+ if (typeof item !== 'string') {
163
+ throw new TypeError(`key "${name}" not found in URL search parameters`);
232
164
  }
233
- const key = keySelector(element);
234
- const value = valueSelector(element);
235
- map.set(key, value);
236
- }
237
- return map;
238
- };
239
- Set.fromElements = function (source, valueSelector) {
240
- isValidElementSource(source);
241
- const elements = parseElementSource(source);
242
- const set = new Set();
243
- for (const element of elements) {
244
- if (!(element instanceof Element)) {
245
- throw new TypeError('item in source array is not an element');
165
+ return item;
166
+ };
167
+ }
168
+ function getAsInteger() {
169
+ return function (name, radix = 10) {
170
+ const item = this.get(name);
171
+ if (typeof item !== 'string') {
172
+ return null;
246
173
  }
247
- const value = valueSelector(element);
248
- set.add(value);
249
- }
250
- return set;
251
- };
252
- function isValidElementSource(source) {
253
- if (!Array.isArray(source) &&
254
- !(source instanceof NodeList) &&
255
- (typeof source !== 'string' || source.length === 0)) {
256
- throw new TypeError('source must be an array, a NodeList or a string');
257
- }
258
- return true;
174
+ return Number.parseInt(item, radix);
175
+ };
259
176
  }
260
- function parseElementSource(source) {
261
- if (typeof source === 'string') {
262
- return document.queryAsArray(source);
263
- }
264
- else if (Array.isArray(source)) {
265
- return source;
266
- }
267
- else if (source instanceof NodeList) {
268
- return Array.from(source);
269
- }
270
- throw new TypeError('source must be an array, a NodeList or a string');
177
+ function getAsIntegerStrict() {
178
+ return function (name, radix = 10) {
179
+ const value = Number.parseInt(this.getStrict(name), radix);
180
+ if (!Number.isInteger(value)) {
181
+ throw new TypeError(`could not parse "${name}" as an integer`);
182
+ }
183
+ return value;
184
+ };
271
185
  }
186
+ const urlSearchParams = {
187
+ getStrict,
188
+ getAsInteger,
189
+ getAsIntegerStrict
190
+ };
191
+
192
+ Document.prototype.queryStrict = element.queryStrict();
193
+ Document.prototype.queryAsArray = element.queryAsArray();
194
+ Document.prototype.queryAsSet = element.queryAsSet();
195
+ Document.prototype.queryAsMap = element.queryAsMap();
196
+ Document.prototype.waitChild = element.waitChild();
197
+ Element.prototype.getAttributeStrict = element.getAttributeStrict();
198
+ Element.prototype.getAttributeAsFloatStrict = element.getAttributeAsFloatStrict();
199
+ Element.prototype.getAttributeAsIntStrict = element.getAttributeAsIntStrict();
200
+ Element.prototype.getTextStrict = element.getTextStrict();
201
+ Element.prototype.getTextAsIntStrict = element.getTextAsIntStrict();
202
+ Element.prototype.getTextAsFloatStrict = element.getTextAsFloatStrict();
203
+ Element.prototype.queryStrict = element.queryStrict();
204
+ Element.prototype.queryAsArray = element.queryAsArray();
205
+ Element.prototype.queryAsSet = element.queryAsSet();
206
+ Element.prototype.queryAsMap = element.queryAsMap();
207
+ Element.prototype.waitChild = element.waitChild();
208
+ URLSearchParams.prototype.getStrict = urlSearchParams.getStrict();
209
+ URLSearchParams.prototype.getAsInteger = urlSearchParams.getAsInteger();
210
+ URLSearchParams.prototype.getAsIntegerStrict = urlSearchParams.getAsIntegerStrict();
272
211
 
273
212
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/prototype-dom",
3
- "version": "6.1.0",
3
+ "version": "6.1.2",
4
4
  "description": "Adds prototype methods to DOM objects",
5
5
  "packageManager": "pnpm@8.15.4",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@rollup/plugin-typescript": "^11.1.6",
27
- "@tb-dev/eslint-config": "^2.0.3",
27
+ "@tb-dev/eslint-config": "^2.1.1",
28
28
  "@vitest/ui": "^1.3.1",
29
29
  "eslint": "^8.57.0",
30
30
  "husky": "^9.0.11",
@@ -32,7 +32,7 @@
32
32
  "prettier": "^3.2.5",
33
33
  "rollup": "^4.12.0",
34
34
  "tslib": "^2.6.2",
35
- "typedoc": "^0.25.8",
35
+ "typedoc": "^0.25.9",
36
36
  "typedoc-plugin-mdn-links": "^3.1.17",
37
37
  "typescript": "5.3.3",
38
38
  "vitest": "^1.3.1"
@@ -43,7 +43,7 @@
43
43
  "main": "./dist/index.js",
44
44
  "types": "./dist/index.d.ts",
45
45
  "scripts": {
46
- "build": "rollup --config rollup.config.js",
46
+ "build": "rollup --config rollup.config.js && node scripts/delete-artifacts.mjs",
47
47
  "docs": "typedoc --plugin typedoc-plugin-mdn-links",
48
48
  "format": "prettier . --write",
49
49
  "format-check": "prettier . --check",