@tb-dev/prototype-dom 7.0.8 → 7.0.9

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.
@@ -0,0 +1,28 @@
1
+ import { WaitScrollOptions } from './types';
2
+ declare function getAttributeStrict<E extends Element>(): (this: E, attribute: string) => string;
3
+ declare function getAttributeAsFloatStrict<E extends Element>(): (this: E, attribute: string) => number;
4
+ declare function getAttributeAsIntStrict<E extends Element>(): (this: E, attribute: string, radix?: number) => number;
5
+ declare function getTextStrict<E extends Element>(): (this: E) => string;
6
+ declare function getTextAsIntStrict<E extends Element>(): (this: E, radix?: number) => number;
7
+ declare function getTextAsFloatStrict<E extends Element>(): (this: E) => number;
8
+ declare function queryStrict<E extends Document | Element>(): <T extends Element = Element>(this: E, selector: string) => T;
9
+ declare function queryAsArray<E extends Document | Element>(): <T = Element>(this: E, selector: string, valueFn?: (element: Element) => T) => T[];
10
+ declare function queryAsSet<E extends Document | Element>(): <T = Element>(this: E, selector: string, valueFn?: (element: Element) => T) => Set<T>;
11
+ declare function queryAsMap<E extends Document | Element>(): <T extends Element, K, V = T>(this: E, selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
12
+ declare function waitChild<E extends Document | Element>(): <T extends Element = Element>(this: E, selector: string, timeoutMillis?: number) => Promise<T>;
13
+ declare function waitScroll<E extends Document | Element>(): (this: E, selector: string, options?: WaitScrollOptions) => Promise<void>;
14
+ export declare const element: {
15
+ getAttributeStrict: typeof getAttributeStrict;
16
+ getAttributeAsFloatStrict: typeof getAttributeAsFloatStrict;
17
+ getAttributeAsIntStrict: typeof getAttributeAsIntStrict;
18
+ getTextStrict: typeof getTextStrict;
19
+ getTextAsIntStrict: typeof getTextAsIntStrict;
20
+ getTextAsFloatStrict: typeof getTextAsFloatStrict;
21
+ queryStrict: typeof queryStrict;
22
+ queryAsArray: typeof queryAsArray;
23
+ queryAsSet: typeof queryAsSet;
24
+ queryAsMap: typeof queryAsMap;
25
+ waitChild: typeof waitChild;
26
+ waitScroll: typeof waitScroll;
27
+ };
28
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,58 +1,178 @@
1
- export declare const element: {
2
- getAttributeStrict: typeof getAttributeStrict;
3
- getAttributeAsFloatStrict: typeof getAttributeAsFloatStrict;
4
- getAttributeAsIntStrict: typeof getAttributeAsIntStrict;
5
- getTextStrict: typeof getTextStrict;
6
- getTextAsIntStrict: typeof getTextAsIntStrict;
7
- getTextAsFloatStrict: typeof getTextAsFloatStrict;
8
- queryStrict: typeof queryStrict;
9
- queryAsArray: typeof queryAsArray;
10
- queryAsSet: typeof queryAsSet;
11
- queryAsMap: typeof queryAsMap;
12
- waitChild: typeof waitChild;
13
- waitScroll: typeof waitScroll;
14
- };
15
-
16
- declare function getAsInteger(): (this: URLSearchParams, name: string, radix?: number) => number | null;
17
-
18
- declare function getAsIntegerStrict(): (this: URLSearchParams, name: string, radix?: number) => number;
19
-
20
- declare function getAttributeAsFloatStrict<E extends Element>(): (this: E, attribute: string) => number;
21
-
22
- declare function getAttributeAsIntStrict<E extends Element>(): (this: E, attribute: string, radix?: number) => number;
23
-
24
- declare function getAttributeStrict<E extends Element>(): (this: E, attribute: string) => string;
25
-
26
- declare function getStrict(): (this: URLSearchParams, name: string) => string;
27
-
28
- declare function getTextAsFloatStrict<E extends Element>(): (this: E) => number;
29
-
30
- declare function getTextAsIntStrict<E extends Element>(): (this: E, radix?: number) => number;
31
-
32
- declare function getTextStrict<E extends Element>(): (this: E) => string;
33
-
34
- declare function queryAsArray<E extends Document | Element>(): <T = Element>(this: E, selector: string, valueFn?: (element: Element) => T) => T[];
35
-
36
- declare function queryAsMap<E extends Document | Element>(): <T extends Element, K, V = T>(this: E, selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
37
-
38
- declare function queryAsSet<E extends Document | Element>(): <T = Element>(this: E, selector: string, valueFn?: (element: Element) => T) => Set<T>;
39
-
40
- declare function queryStrict<E extends Document | Element>(): <T extends Element = Element>(this: E, selector: string) => T;
41
-
42
- export declare const urlSearchParams: {
43
- getStrict: typeof getStrict;
44
- getAsInteger: typeof getAsInteger;
45
- getAsIntegerStrict: typeof getAsIntegerStrict;
46
- };
47
-
48
- declare function waitChild<E extends Document | Element>(): <T extends Element = Element>(this: E, selector: string, timeoutMillis?: number) => Promise<T>;
49
-
50
- declare function waitScroll<E extends Document | Element>(): (this: E, selector: string, options?: WaitScrollOptions) => Promise<void>;
51
-
52
- export declare interface WaitScrollOptions extends ScrollIntoViewOptions {
53
- /** @default true */
54
- throwOnTimeout?: boolean;
55
- timeout?: number;
56
- }
57
-
58
- export { }
1
+ import { element } from './element';
2
+ import { urlSearchParams } from './url';
3
+ import { WaitScrollOptions } from './types';
4
+ export type * from './types';
5
+ declare global {
6
+ interface Document {
7
+ /**
8
+ * Return the first element that is a descendant of node that matches selector.
9
+ * @param selectors CSS selector to match.
10
+ *
11
+ * @throws {Error} If no element is found.
12
+ */
13
+ queryStrict: <T extends Element = Element>(selectors: string) => T;
14
+ /**
15
+ * Query all element descendants of node that match selector, then create an {@link Array} from the result.
16
+ *
17
+ * The values of the array can be customized by providing a `valueFn` function.
18
+ * Defaults to the element itself.
19
+ * @param selector CSS selector to match.
20
+ */
21
+ queryAsArray: <T = Element>(selector: string, valueFn?: (element: Element) => T) => T[];
22
+ /**
23
+ * Query all element descendants of node that match selector, then create a {@link Set} from the result.
24
+ *
25
+ * The values of the set can be customized by providing a `valueFn` function.
26
+ * Defaults to the elements themselves.
27
+ * @param selector CSS selector to match.
28
+ */
29
+ queryAsSet: <T = Element>(selector: string, valueFn?: (element: Element) => T) => Set<T>;
30
+ /**
31
+ * Query all element descendants of node that match selector, then create a {@link Map} from the result.
32
+ *
33
+ * The keys of the map are determined by the required `keyFn` function.
34
+ *
35
+ * The values can be customized by providing a `valueFn` function. Default to the elements themselves.
36
+ * @param selector CSS selector to match.
37
+ * @param keyFn Function that returns the key for each element.
38
+ * @param valueFn Function that returns the value for each element.
39
+ */
40
+ queryAsMap: <T extends Element, K, V = T>(selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
41
+ /**
42
+ * Wait for the first descendant element that matches the given selector to exist.
43
+ * @param selector CSS selector to match.
44
+ * @param timeout Maximum time to wait for the element, in milliseconds.
45
+ */
46
+ waitChild: (selector: string, timeout?: number) => Promise<Element>;
47
+ /**
48
+ * Wait for the first descendant element that matches the given selector to exist.
49
+ * Once found, scroll the element into view.
50
+ * @param selector CSS selector to match.
51
+ * @param options Options to customize the scrolling behavior.
52
+ */
53
+ waitScroll: (selector: string, options?: WaitScrollOptions) => Promise<void>;
54
+ }
55
+ interface Element {
56
+ /**
57
+ * Return the first attribute whose qualified name is `name`.
58
+ * @param name Attribute to search for.
59
+ *
60
+ * @throws {Error} If the attribute is not found.
61
+ */
62
+ getAttributeStrict: (name: string) => string;
63
+ /**
64
+ * Get the first attribute whose qualified name is `name`,
65
+ * then tries to parse the attribute as a floating point number.
66
+ * @param name Attribute to search for.
67
+ *
68
+ * @throws {Error} If the attribute is not found.
69
+ * @throws {TypeError} If the attribute cannot be parsed as a floating point number.
70
+ */
71
+ getAttributeAsFloatStrict: (name: string) => number;
72
+ /**
73
+ * Get the first attribute whose qualified name is `name`,
74
+ * then tries to parse the attribute as an integer using the specified radix.
75
+ * @param name Attribute to search for.
76
+ * @param radix A value between 2 and 36 that specifies the base of the number.
77
+ *
78
+ * @throws {Error} If the attribute is not found.
79
+ * @throws {TypeError} If the attribute cannot be parsed as an integer.
80
+ */
81
+ getAttributeAsIntStrict: (name: string, radix?: number) => number;
82
+ /**
83
+ * Return the text content of the element.
84
+ *
85
+ * @throws {Error} If the element has no text content.
86
+ */
87
+ getTextStrict: () => string;
88
+ /**
89
+ * Get the text content of the element, then tries to parse it as an integer.
90
+ * @param radix A value between 2 and 36 that specifies the base of the number.
91
+ *
92
+ * @throws {Error} If the element has no text content.
93
+ * @throws {TypeError} If the text content cannot be parsed as an integer.
94
+ */
95
+ getTextAsIntStrict: (radix?: number) => number;
96
+ /**
97
+ * Get the text content of the element, then tries to parse it as a floating point number.
98
+ *
99
+ * @throws {Error} If the element has no text content.
100
+ * @throws {TypeError} If the text content cannot be parsed as a floating point number.
101
+ */
102
+ getTextAsFloatStrict: () => number;
103
+ /**
104
+ * Query all element descendants of node that match selector, then create an {@link Array} from the result.
105
+ *
106
+ * The values of the array can be customized by providing a `valueFn` function.
107
+ * Defaults to the element itself.
108
+ * @param selector CSS selector to match.
109
+ */
110
+ queryAsArray: <T = Element>(selector: string, valueFn?: (element: Element) => T) => T[];
111
+ /**
112
+ * Query all element descendants of node that match selector, then create a {@link Set} from the result.
113
+ *
114
+ * The values of the set can be customized by providing a `valueFn` function.
115
+ * Defaults to the elements themselves.
116
+ * @param selector CSS selector to match.
117
+ */
118
+ queryAsSet: <T = Element>(selector: string, valueFn?: (element: Element) => T) => Set<T>;
119
+ /**
120
+ * Return the first element that is a descendant of node that matches selector.
121
+ * @param selectors CSS selector to match.
122
+ *
123
+ * @throws {Error} If no element is found.
124
+ */
125
+ queryStrict: <T extends Element>(selector: string) => T;
126
+ /**
127
+ * Query all element descendants of node that match selector, then create a {@link Map} from the result.
128
+ *
129
+ * The keys of the map are determined by the required `keyFn` function.
130
+ *
131
+ * The values can be customized by providing a `valueFn` function. Default to the elements themselves.
132
+ * @param selector CSS selector to match.
133
+ * @param keyFn Function that returns the key for each element.
134
+ * @param valueFn Function that returns the value for each element.
135
+ */
136
+ queryAsMap: <T extends Element, K, V = T>(selector: string, keyFn: (element: T) => K, valueFn?: (element: T) => V) => Map<K, V>;
137
+ /**
138
+ * Wait for the first descendant element that matches the given selector to exist.
139
+ * @param selector CSS selector to match.
140
+ * @param timeout Maximum time to wait for the element, in milliseconds.
141
+ */
142
+ waitChild: (selector: string, timeout?: number) => Promise<Element>;
143
+ /**
144
+ * Wait for the first descendant element that matches the given selector to exist.
145
+ * Once found, scroll the element into view.
146
+ * @param selector CSS selector to match.
147
+ * @param options Options to customize the scrolling behavior.
148
+ */
149
+ waitScroll: (selector: string, options?: WaitScrollOptions) => Promise<void>;
150
+ }
151
+ interface URLSearchParams {
152
+ /**
153
+ * Return the first value associated to the given search parameter.
154
+ * @param name The name of the search parameter to get.
155
+ *
156
+ * @throws {Error} If the search parameter is not found.
157
+ */
158
+ getStrict: (name: string) => string;
159
+ /**
160
+ * Get the first value associated to the given search parameter, then tries to parse it as an integer.
161
+ * The returned value may be `NaN` if it cannot be parsed as an integer.
162
+ * To throw an error if the value cannot be parsed, use {@link getAsIntegerStrict} instead.
163
+ * @param name The name of the search parameter to get.
164
+ * @param radix A value between 2 and 36 that specifies the base of the number.
165
+ */
166
+ getAsInteger: (name: string, radix?: number) => number | null;
167
+ /**
168
+ * Get the first value associated to the given search parameter, then tries to parse it as an integer.
169
+ * @param name The name of the search parameter to get.
170
+ * @param radix A value between 2 and 36 that specifies the base of the number.
171
+ *
172
+ * @throws {Error} If the search parameter is not found.
173
+ * @throws {TypeError} If the value cannot be parsed as an integer.
174
+ */
175
+ getAsIntegerStrict: (name: string, radix?: number) => number;
176
+ }
177
+ }
178
+ export type { element, urlSearchParams };
@@ -0,0 +1,5 @@
1
+ export interface WaitScrollOptions extends ScrollIntoViewOptions {
2
+ /** @default true */
3
+ throwOnTimeout?: boolean;
4
+ timeout?: number;
5
+ }
package/dist/url.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ declare function getStrict(): (this: URLSearchParams, name: string) => string;
2
+ declare function getAsInteger(): (this: URLSearchParams, name: string, radix?: number) => number | null;
3
+ declare function getAsIntegerStrict(): (this: URLSearchParams, name: string, radix?: number) => number;
4
+ export declare const urlSearchParams: {
5
+ getStrict: typeof getStrict;
6
+ getAsInteger: typeof getAsInteger;
7
+ getAsIntegerStrict: typeof getAsIntegerStrict;
8
+ };
9
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/prototype-dom",
3
- "version": "7.0.8",
3
+ "version": "7.0.9",
4
4
  "description": "Helpful prototype methods",
5
5
  "license": "MIT",
6
6
  "type": "module",