@tb-dev/prototype-dom 6.1.10 → 6.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Andrew Ferreira
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Andrew Ferreira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { }
2
+
1
3
  declare global {
2
4
  interface Document {
3
5
  /**
@@ -157,4 +159,3 @@ declare global {
157
159
  getAsIntegerStrict: (name: string, radix?: number) => number;
158
160
  }
159
161
  }
160
- export {};
@@ -0,0 +1,183 @@
1
+ (function () {
2
+ 'use strict';
3
+
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`);
9
+ }
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`);
19
+ }
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`);
29
+ }
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 element2 = this.querySelector(selector);
63
+ if (!element2) throw new Error(`no element found for selector "${selector}"`);
64
+ return element2;
65
+ };
66
+ }
67
+ function queryAsArray() {
68
+ return function(selector, valueFn) {
69
+ valueFn ??= (element2) => element2;
70
+ const elements = this.querySelectorAll(selector);
71
+ return Array.from(elements, valueFn);
72
+ };
73
+ }
74
+ function queryAsSet() {
75
+ return function(selector, valueFn) {
76
+ valueFn ??= (element2) => element2;
77
+ const elements = this.queryAsArray(selector, valueFn);
78
+ return new Set(elements);
79
+ };
80
+ }
81
+ function queryAsMap() {
82
+ return function(selector, keyFn, valueFn) {
83
+ valueFn ??= (element2) => element2;
84
+ const elements = this.queryAsArray(selector);
85
+ const map = /* @__PURE__ */ new Map();
86
+ for (const element2 of elements) {
87
+ const key = keyFn(element2);
88
+ const value = valueFn(element2);
89
+ map.set(key, value);
90
+ }
91
+ return map;
92
+ };
93
+ }
94
+ function waitChild() {
95
+ return function(selector, timeoutMillis = 6e4) {
96
+ let element2 = this.querySelector(selector);
97
+ if (element2) return Promise.resolve(element2);
98
+ const { promise, resolve, reject } = Promise.withResolvers();
99
+ const timeout = setTimeout(onTimeout, timeoutMillis);
100
+ const interval = setInterval(onInterval.bind(this), 20);
101
+ function onInterval() {
102
+ element2 = this.querySelector(selector);
103
+ if (element2) {
104
+ clearInterval(interval);
105
+ clearTimeout(timeout);
106
+ resolve(element2);
107
+ }
108
+ }
109
+ function onTimeout() {
110
+ clearInterval(interval);
111
+ reject(new Error(`timeout waiting for element: ${selector}`));
112
+ }
113
+ return promise;
114
+ };
115
+ }
116
+ const element = {
117
+ getAttributeStrict,
118
+ getAttributeAsFloatStrict,
119
+ getAttributeAsIntStrict,
120
+ getTextStrict,
121
+ getTextAsIntStrict,
122
+ getTextAsFloatStrict,
123
+ queryStrict,
124
+ queryAsArray,
125
+ queryAsSet,
126
+ queryAsMap,
127
+ waitChild
128
+ };
129
+
130
+ function getStrict() {
131
+ return function(name) {
132
+ const item = this.get(name);
133
+ if (typeof item !== "string") {
134
+ throw new TypeError(`key "${name}" not found in URL search parameters`);
135
+ }
136
+ return item;
137
+ };
138
+ }
139
+ function getAsInteger() {
140
+ return function(name, radix = 10) {
141
+ const item = this.get(name);
142
+ if (typeof item !== "string") {
143
+ return null;
144
+ }
145
+ return Number.parseInt(item, radix);
146
+ };
147
+ }
148
+ function getAsIntegerStrict() {
149
+ return function(name, radix = 10) {
150
+ const value = Number.parseInt(this.getStrict(name), radix);
151
+ if (!Number.isInteger(value)) {
152
+ throw new TypeError(`could not parse "${name}" as an integer`);
153
+ }
154
+ return value;
155
+ };
156
+ }
157
+ const urlSearchParams = {
158
+ getStrict,
159
+ getAsInteger,
160
+ getAsIntegerStrict
161
+ };
162
+
163
+ Document.prototype.queryStrict = element.queryStrict();
164
+ Document.prototype.queryAsArray = element.queryAsArray();
165
+ Document.prototype.queryAsSet = element.queryAsSet();
166
+ Document.prototype.queryAsMap = element.queryAsMap();
167
+ Document.prototype.waitChild = element.waitChild();
168
+ Element.prototype.getAttributeStrict = element.getAttributeStrict();
169
+ Element.prototype.getAttributeAsFloatStrict = element.getAttributeAsFloatStrict();
170
+ Element.prototype.getAttributeAsIntStrict = element.getAttributeAsIntStrict();
171
+ Element.prototype.getTextStrict = element.getTextStrict();
172
+ Element.prototype.getTextAsIntStrict = element.getTextAsIntStrict();
173
+ Element.prototype.getTextAsFloatStrict = element.getTextAsFloatStrict();
174
+ Element.prototype.queryStrict = element.queryStrict();
175
+ Element.prototype.queryAsArray = element.queryAsArray();
176
+ Element.prototype.queryAsSet = element.queryAsSet();
177
+ Element.prototype.queryAsMap = element.queryAsMap();
178
+ Element.prototype.waitChild = element.waitChild();
179
+ URLSearchParams.prototype.getStrict = urlSearchParams.getStrict();
180
+ URLSearchParams.prototype.getAsInteger = urlSearchParams.getAsInteger();
181
+ URLSearchParams.prototype.getAsIntegerStrict = urlSearchParams.getAsIntegerStrict();
182
+
183
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/prototype-dom",
3
- "version": "6.1.10",
3
+ "version": "6.1.13",
4
4
  "description": "Adds prototype methods to DOM objects",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,29 +22,31 @@
22
22
  "*.{?(c|m)@(j|t)s,css,vue,md,json}": "prettier --write"
23
23
  },
24
24
  "devDependencies": {
25
- "@rollup/plugin-typescript": "^11.1.6",
26
- "@tb-dev/eslint-config": "^3.8.0",
27
- "eslint": "^8.57.0",
28
- "husky": "^9.0.11",
29
- "lint-staged": "^15.2.7",
30
- "prettier": "^3.3.2",
31
- "rollup": "^4.18.0",
25
+ "@tb-dev/eslint-config": "^5.2.1",
26
+ "eslint": "^9.9.0",
27
+ "husky": "^9.1.5",
28
+ "lint-staged": "^15.2.9",
29
+ "prettier": "^3.3.3",
32
30
  "tslib": "^2.6.3",
33
- "typedoc": "^0.25.13",
34
- "typedoc-plugin-mdn-links": "^3.1.30",
35
- "typescript": "^5.4.5"
31
+ "typedoc": "^0.26.6",
32
+ "typedoc-plugin-mdn-links": "^3.2.9",
33
+ "typescript": "^5.5.4",
34
+ "vite": "^5.4.2",
35
+ "vite-plugin-dts": "^4.0.3"
36
36
  },
37
37
  "files": [
38
38
  "dist/**/*"
39
39
  ],
40
- "main": "./dist/index.js",
40
+ "main": "./dist/index.iife.js",
41
41
  "types": "./dist/index.d.ts",
42
42
  "scripts": {
43
- "build": "rollup --config rollup.config.js && node scripts/delete-artifacts.mjs",
43
+ "build": "vite build",
44
44
  "docs": "typedoc --plugin typedoc-plugin-mdn-links",
45
45
  "format": "prettier . --write",
46
- "format-check": "prettier . --check",
46
+ "lint": "eslint . --config eslint.config.js --cache",
47
+ "lint-fix": "eslint . --config eslint.config.js --fix",
47
48
  "release": "pnpm run build && pnpm publish",
48
- "type-check": "tsc --noEmit"
49
+ "type-check": "tsc --noEmit",
50
+ "update": "miho update major -t"
49
51
  }
50
52
  }
package/dist/index.js DELETED
@@ -1,185 +0,0 @@
1
- (function () {
2
- 'use strict';
3
-
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`);
9
- }
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`);
19
- }
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`);
29
- }
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 = 60_000) {
97
- let element = this.querySelector(selector);
98
- if (element)
99
- return Promise.resolve(element);
100
- const { promise, resolve, reject } = Promise.withResolvers();
101
- const timeout = setTimeout(onTimeout, timeoutMillis);
102
- const interval = setInterval(onInterval.bind(this), 20);
103
- function onInterval() {
104
- element = this.querySelector(selector);
105
- if (element) {
106
- clearInterval(interval);
107
- clearTimeout(timeout);
108
- resolve(element);
109
- }
110
- }
111
- function onTimeout() {
112
- clearInterval(interval);
113
- reject(new Error(`timeout waiting for element: ${selector}`));
114
- }
115
- return promise;
116
- };
117
- }
118
- const element = {
119
- getAttributeStrict,
120
- getAttributeAsFloatStrict,
121
- getAttributeAsIntStrict,
122
- getTextStrict,
123
- getTextAsIntStrict,
124
- getTextAsFloatStrict,
125
- queryStrict,
126
- queryAsArray,
127
- queryAsSet,
128
- queryAsMap,
129
- waitChild
130
- };
131
-
132
- function getStrict() {
133
- return function (name) {
134
- const item = this.get(name);
135
- if (typeof item !== 'string') {
136
- throw new TypeError(`key "${name}" not found in URL search parameters`);
137
- }
138
- return item;
139
- };
140
- }
141
- function getAsInteger() {
142
- return function (name, radix = 10) {
143
- const item = this.get(name);
144
- if (typeof item !== 'string') {
145
- return null;
146
- }
147
- return Number.parseInt(item, radix);
148
- };
149
- }
150
- function getAsIntegerStrict() {
151
- return function (name, radix = 10) {
152
- const value = Number.parseInt(this.getStrict(name), radix);
153
- if (!Number.isInteger(value)) {
154
- throw new TypeError(`could not parse "${name}" as an integer`);
155
- }
156
- return value;
157
- };
158
- }
159
- const urlSearchParams = {
160
- getStrict,
161
- getAsInteger,
162
- getAsIntegerStrict
163
- };
164
-
165
- Document.prototype.queryStrict = element.queryStrict();
166
- Document.prototype.queryAsArray = element.queryAsArray();
167
- Document.prototype.queryAsSet = element.queryAsSet();
168
- Document.prototype.queryAsMap = element.queryAsMap();
169
- Document.prototype.waitChild = element.waitChild();
170
- Element.prototype.getAttributeStrict = element.getAttributeStrict();
171
- Element.prototype.getAttributeAsFloatStrict = element.getAttributeAsFloatStrict();
172
- Element.prototype.getAttributeAsIntStrict = element.getAttributeAsIntStrict();
173
- Element.prototype.getTextStrict = element.getTextStrict();
174
- Element.prototype.getTextAsIntStrict = element.getTextAsIntStrict();
175
- Element.prototype.getTextAsFloatStrict = element.getTextAsFloatStrict();
176
- Element.prototype.queryStrict = element.queryStrict();
177
- Element.prototype.queryAsArray = element.queryAsArray();
178
- Element.prototype.queryAsSet = element.queryAsSet();
179
- Element.prototype.queryAsMap = element.queryAsMap();
180
- Element.prototype.waitChild = element.waitChild();
181
- URLSearchParams.prototype.getStrict = urlSearchParams.getStrict();
182
- URLSearchParams.prototype.getAsInteger = urlSearchParams.getAsInteger();
183
- URLSearchParams.prototype.getAsIntegerStrict = urlSearchParams.getAsIntegerStrict();
184
-
185
- })();