@cntwg/html-helper 0.0.26 → 0.0.27
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/CHANGELOG.md +9 -0
- package/doc/html-ctrls-btn.md +4 -11
- package/doc/html-helper-lib.md +11 -2
- package/index.js +2 -2
- package/lib/html-ctrls/buttons.js +31 -59
- package/lib/html-ctrls/fields.js +19 -19
- package/lib/html-ctrls/list.js +65 -64
- package/lib/html-ctrls/lists-btn.js +19 -19
- package/lib/html-ctrls/lists-stubs.js +18 -18
- package/lib/html-helper-lib.js +61 -34
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.050-20250827]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -27,27 +27,27 @@ const {
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
+
* A settings to load a stub-elements.
|
|
30
31
|
* @typedef {Object} OPT_ldstubs
|
|
31
32
|
* @property {string} [defaultItem] - <*deprecated*> a default element name
|
|
32
33
|
* @property {boolean} [useClear=true] - to clear before load an elements
|
|
33
34
|
* @property {boolean} [force=false] - run in a force mode
|
|
34
|
-
* @description A settings to load a stub-elements.
|
|
35
35
|
* @todo [since v0.0.26] `defaultItem`-option deprecated
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
+
* A stub-elements description list.
|
|
39
40
|
* @typedef {Object} OBJ_stubEList
|
|
40
41
|
* @property {Array} items - array of `name`-`element` pairs
|
|
41
42
|
* @property {string} [defaultItem] - a default element name
|
|
42
|
-
* @description A stub-elements description list.
|
|
43
43
|
*/
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
+
* A an options set for a `THtmlStubItemsSet`-class constructor
|
|
46
47
|
* @typedef {Object} OPT_stubconsett
|
|
47
48
|
* @property {(any[])} items - array of `name`-`element` pairs
|
|
48
49
|
* @property {string} [defaultItem] - a default element name
|
|
49
50
|
* @property {boolean} [force=false] - run in a force mode
|
|
50
|
-
* @description A an options set for a `THtmlStubItemsSet`-class constructor
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
53
|
/**
|
|
@@ -63,9 +63,9 @@ class THtmlStubItemsSet {
|
|
|
63
63
|
#_shownItem = null;
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
+
* Creates an instance of a stub-items set
|
|
66
67
|
* @param {HTMLElement} host - host element
|
|
67
68
|
* @param {(array|OPT_stubconsett|OBJ_stubEList)} [opt] - options
|
|
68
|
-
* @description Creates an instance of a stub-items set
|
|
69
69
|
* @todo [since v0.0.26] use of an `array`-type as a value of an `opt` is deprecated
|
|
70
70
|
*/
|
|
71
71
|
constructor(host, opt) {
|
|
@@ -108,8 +108,8 @@ class THtmlStubItemsSet {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
+
* Clears an instance content.
|
|
111
112
|
* @returns {void}
|
|
112
|
-
* @description Clears an instance content.
|
|
113
113
|
*/
|
|
114
114
|
clear() {
|
|
115
115
|
// // TODO: check if any item is shown
|
|
@@ -119,9 +119,9 @@ class THtmlStubItemsSet {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
+
* Sets a default item.
|
|
122
123
|
* @param {string} name - an element name
|
|
123
124
|
* @returns {boolean}
|
|
124
|
-
* @description Sets a default item.
|
|
125
125
|
*/
|
|
126
126
|
setDefItem(name) {
|
|
127
127
|
let isACCEPTED = false;
|
|
@@ -134,8 +134,8 @@ class THtmlStubItemsSet {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
+
* Resets a default item.
|
|
137
138
|
* @returns {void}
|
|
138
|
-
* @description Resets a default item.
|
|
139
139
|
*/
|
|
140
140
|
rstDefItem() {
|
|
141
141
|
// // TODO: check if item is shown
|
|
@@ -143,9 +143,9 @@ class THtmlStubItemsSet {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
|
+
* Checks if an item exists.
|
|
146
147
|
* @param {string} name - an element name
|
|
147
148
|
* @returns {boolean}
|
|
148
|
-
* @description Checks if an item exists.
|
|
149
149
|
*/
|
|
150
150
|
hasItem(name) {
|
|
151
151
|
const _name = typeof name === 'string' ? name.trim() : '';
|
|
@@ -153,17 +153,17 @@ class THtmlStubItemsSet {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
|
+
* Checks if any items exists.
|
|
156
157
|
* @returns {boolean}
|
|
157
|
-
* @description Checks if any items exists.
|
|
158
158
|
*/
|
|
159
159
|
hasItems() {
|
|
160
160
|
return this.#_items.size > 0;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
+
* Returns an item by its name.
|
|
164
165
|
* @param {string} name - an element name
|
|
165
166
|
* @returns {?HTMLElement}
|
|
166
|
-
* @description Returns an item by its name.
|
|
167
167
|
*/
|
|
168
168
|
getItem(name) {
|
|
169
169
|
const _name = typeof name === 'string' ? name.trim() : '';
|
|
@@ -172,11 +172,11 @@ class THtmlStubItemsSet {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/**
|
|
175
|
+
* Adds an item to an instance members.
|
|
175
176
|
* @param {string} name - an element name
|
|
176
177
|
* @param {HTMLElement} item - an element
|
|
177
178
|
* @param {boolean} [opt=false] - flag indicating a force mode
|
|
178
179
|
* @returns {boolean}
|
|
179
|
-
* @description Adds an item to an instance members.
|
|
180
180
|
*/
|
|
181
181
|
addItem(name, item, opt) {
|
|
182
182
|
const _name = typeof name === 'string' ? name.trim() : '';
|
|
@@ -192,9 +192,9 @@ class THtmlStubItemsSet {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
/**
|
|
195
|
+
* Deletes an item from an instance members.
|
|
195
196
|
* @param {string} name - an element name
|
|
196
197
|
* @returns {boolean}
|
|
197
|
-
* @description Deletes an item from an instance members.
|
|
198
198
|
*/
|
|
199
199
|
delItem(name) {
|
|
200
200
|
let _name = '';
|
|
@@ -210,9 +210,9 @@ class THtmlStubItemsSet {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
/**
|
|
213
|
+
* Shows an item.
|
|
213
214
|
* @param {string} name - an element name
|
|
214
215
|
* @returns {boolean}
|
|
215
|
-
* @description Shows an item.
|
|
216
216
|
*/
|
|
217
217
|
showItem(name) {
|
|
218
218
|
const item = this.getItem(name);
|
|
@@ -222,17 +222,17 @@ class THtmlStubItemsSet {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
/**
|
|
225
|
+
* Shows a default item.
|
|
225
226
|
* @returns {boolean}
|
|
226
|
-
* @description Shows a default item.
|
|
227
227
|
*/
|
|
228
228
|
showDefItem() {
|
|
229
229
|
return this.showItem(this.#_defItem);
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
/**
|
|
233
|
+
* Hides an item.
|
|
233
234
|
* @param {string} name - an element name
|
|
234
235
|
* @returns {boolean}
|
|
235
|
-
* @description Hides an item.
|
|
236
236
|
*/
|
|
237
237
|
hideItem(name) {
|
|
238
238
|
const item = this.getItem(name);
|
|
@@ -242,18 +242,18 @@ class THtmlStubItemsSet {
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
/**
|
|
245
|
+
* Hides a default item.
|
|
245
246
|
* @returns {boolean}
|
|
246
|
-
* @description Hides a default item.
|
|
247
247
|
*/
|
|
248
248
|
hideDefItem() {
|
|
249
249
|
return this.hideItem(this.#_defItem);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
|
+
* Adds an items to an instance members.
|
|
253
254
|
* @param {(Array|OBJ_stubEList)} data - an array of entries or special object
|
|
254
255
|
* @param {(boolean|OPT_ldstubs)} [opt] - an options
|
|
255
256
|
* @returns {number}
|
|
256
|
-
* @description Adds an items to an instance members.
|
|
257
257
|
* @todo [since 0.0.25] deprecate use of `opt` as `boolean`
|
|
258
258
|
* @todo [since v0.0.26] for `OPT_ldstubs` a `defaultItem`-option deprecated
|
|
259
259
|
*/
|
package/lib/html-helper-lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// [v0.1.
|
|
1
|
+
// [v0.1.043-20250827]
|
|
2
2
|
|
|
3
3
|
// === module init block ===
|
|
4
4
|
|
|
@@ -7,7 +7,11 @@ const {
|
|
|
7
7
|
valueToIDString,
|
|
8
8
|
} = require('@ygracs/bsfoc-lib-js');
|
|
9
9
|
|
|
10
|
-
// === module
|
|
10
|
+
// === module inner block ===
|
|
11
|
+
|
|
12
|
+
const etlHTagInputForBtn = new Set([
|
|
13
|
+
'button', 'submit', 'reset', 'image',
|
|
14
|
+
]);
|
|
11
15
|
|
|
12
16
|
// === module main block ===
|
|
13
17
|
|
|
@@ -26,65 +30,89 @@ const CSS_CLASS_HIDDEN = 'hidden';
|
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
32
|
/**
|
|
33
|
+
* Checks if the given object is an instance of an `HTMLElement`.
|
|
29
34
|
* @function isHTMLElement
|
|
30
35
|
* @param {any} obj - some element
|
|
31
36
|
* @return {boolean}
|
|
32
|
-
* @description Checks if the given object is an instance of an `HTMLElement`.
|
|
33
37
|
*/
|
|
34
38
|
function isHTMLElement(obj) {
|
|
35
39
|
return obj instanceof HTMLElement;
|
|
36
40
|
};
|
|
37
41
|
|
|
38
42
|
/**
|
|
43
|
+
* Checks if the given object is an HTML-button.
|
|
44
|
+
* @function isHTMLButton
|
|
45
|
+
* @param {any} obj - element to be verified
|
|
46
|
+
* @returns {boolean}
|
|
47
|
+
*/
|
|
48
|
+
function isHTMLButton(obj) {
|
|
49
|
+
let result = false;
|
|
50
|
+
if (isHTMLElement(obj)) {
|
|
51
|
+
switch (obj.tagName.toLowerCase()) {
|
|
52
|
+
case 'button': {
|
|
53
|
+
result = true;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'input': {
|
|
57
|
+
result = etlHTagInputForBtn.has(obj.type.toLowerCase());
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
default: {}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the given object is an instance of a `HTMLElement`
|
|
68
|
+
* and if so it's marked as "selected".
|
|
39
69
|
* @function isSelectedHTMLElement
|
|
40
70
|
* @param {HTMLElement} obj - some element
|
|
41
71
|
* @return {boolean}
|
|
42
|
-
* @description Checks if the given object is an instance of a `HTMLElement`
|
|
43
|
-
* and if so it's marked as "selected".
|
|
44
72
|
*/
|
|
45
73
|
function isSelectedHTMLElement(obj) {
|
|
46
74
|
return isHTMLElement(obj) && obj.classList.contains(CSS_CLASS_SELECTED);
|
|
47
75
|
};
|
|
48
76
|
|
|
49
77
|
/**
|
|
78
|
+
* Checks if the given object is an instance of a `HTMLElement`
|
|
79
|
+
* and if so it's marked as "current".
|
|
50
80
|
* @function isCurrentHTMLElement
|
|
51
81
|
* @param {HTMLElement} obj - some element
|
|
52
82
|
* @return {boolean}
|
|
53
|
-
* @description Checks if the given object is an instance of a `HTMLElement`
|
|
54
|
-
* and if so it's marked as "current".
|
|
55
83
|
*/
|
|
56
84
|
function isCurrentHTMLElement(obj) {
|
|
57
85
|
return isHTMLElement(obj) && obj.classList.contains(CSS_CLASS_CURRENT);
|
|
58
86
|
};
|
|
59
87
|
|
|
60
88
|
/**
|
|
89
|
+
* Checks if the given object is an instance of a `HTMLElement`
|
|
90
|
+
* and if so it's marked as "active".
|
|
61
91
|
* @function isActiveHTMLElement
|
|
62
92
|
* @param {HTMLElement} obj - some element
|
|
63
93
|
* @return {boolean}
|
|
64
|
-
* @description Checks if the given object is an instance of a `HTMLElement`
|
|
65
|
-
* and if so it's marked as "active".
|
|
66
94
|
*/
|
|
67
95
|
function isActiveHTMLElement(obj) {
|
|
68
96
|
return isHTMLElement(obj) && obj.classList.contains(CSS_CLASS_ACTIVE);
|
|
69
97
|
};
|
|
70
98
|
|
|
71
99
|
/**
|
|
100
|
+
* Checks if the given object is an instance of a `HTMLElement`
|
|
101
|
+
* and if so it's marked as "hidden".
|
|
72
102
|
* @function isHiddenHTMLElement
|
|
73
103
|
* @param {HTMLElement} obj - some element
|
|
74
104
|
* @return {boolean}
|
|
75
|
-
* @description Checks if the given object is an instance of a `HTMLElement`
|
|
76
|
-
* and if so it's marked as "hidden".
|
|
77
105
|
*/
|
|
78
106
|
function isHiddenHTMLElement(obj) {
|
|
79
107
|
return isHTMLElement(obj) && obj.classList.contains(CSS_CLASS_HIDDEN);
|
|
80
108
|
};
|
|
81
109
|
|
|
82
110
|
/**
|
|
111
|
+
* Hides a given HTML-element.
|
|
83
112
|
* @since v0.0.23
|
|
84
113
|
* @function hideHTMLElement
|
|
85
114
|
* @param {HTMLElement} obj - some element
|
|
86
115
|
* @return {boolean}
|
|
87
|
-
* @description Hides a given HTML-element.
|
|
88
116
|
*/
|
|
89
117
|
function hideHTMLElement(obj) {
|
|
90
118
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -93,11 +121,11 @@ function hideHTMLElement(obj) {
|
|
|
93
121
|
};
|
|
94
122
|
|
|
95
123
|
/**
|
|
124
|
+
* Shows a given HTML-element.
|
|
96
125
|
* @since v0.0.23
|
|
97
126
|
* @function showHTMLElement
|
|
98
127
|
* @param {HTMLElement} obj - some element
|
|
99
128
|
* @return {boolean}
|
|
100
|
-
* @description Shows a given HTML-element.
|
|
101
129
|
*/
|
|
102
130
|
function showHTMLElement(obj) {
|
|
103
131
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -106,11 +134,11 @@ function showHTMLElement(obj) {
|
|
|
106
134
|
};
|
|
107
135
|
|
|
108
136
|
/**
|
|
137
|
+
* Makes selected a given HTML-element.
|
|
109
138
|
* @since v0.0.23
|
|
110
139
|
* @function selectHTMLElement
|
|
111
140
|
* @param {HTMLElement} obj - some element
|
|
112
141
|
* @return {boolean}
|
|
113
|
-
* @description Makes selected a given HTML-element.
|
|
114
142
|
*/
|
|
115
143
|
function selectHTMLElement(obj) {
|
|
116
144
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -119,11 +147,11 @@ function selectHTMLElement(obj) {
|
|
|
119
147
|
};
|
|
120
148
|
|
|
121
149
|
/**
|
|
150
|
+
* Makes unselected a given HTML-element.
|
|
122
151
|
* @since v0.0.23
|
|
123
152
|
* @function unselectHTMLElement
|
|
124
153
|
* @param {HTMLElement} obj - some element
|
|
125
154
|
* @return {boolean}
|
|
126
|
-
* @description Makes unselected a given HTML-element.
|
|
127
155
|
*/
|
|
128
156
|
function unselectHTMLElement(obj) {
|
|
129
157
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -132,11 +160,11 @@ function unselectHTMLElement(obj) {
|
|
|
132
160
|
};
|
|
133
161
|
|
|
134
162
|
/**
|
|
163
|
+
* Marks a given HTML-element as "current".
|
|
135
164
|
* @since v0.0.23
|
|
136
165
|
* @function markHTMLElementAsCurrent
|
|
137
166
|
* @param {HTMLElement} obj - some element
|
|
138
167
|
* @return {boolean} - `true` if succeed.
|
|
139
|
-
* @description Marks a given HTML-element as "current".
|
|
140
168
|
*/
|
|
141
169
|
function markHTMLElementAsCurrent(obj) {
|
|
142
170
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -145,11 +173,11 @@ function markHTMLElementAsCurrent(obj) {
|
|
|
145
173
|
};
|
|
146
174
|
|
|
147
175
|
/**
|
|
176
|
+
* Unmarks a given HTML-element previous marked as "current".
|
|
148
177
|
* @since v0.0.23
|
|
149
178
|
* @function unmarkCurrentHTMLElement
|
|
150
179
|
* @param {HTMLElement} obj - some element
|
|
151
180
|
* @return {boolean}
|
|
152
|
-
* @description Unmarks a given HTML-element previous marked as "current".
|
|
153
181
|
*/
|
|
154
182
|
function unmarkCurrentHTMLElement(obj) {
|
|
155
183
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -158,11 +186,11 @@ function unmarkCurrentHTMLElement(obj) {
|
|
|
158
186
|
};
|
|
159
187
|
|
|
160
188
|
/**
|
|
189
|
+
* Marks a given HTML-element as "active".
|
|
161
190
|
* @since v0.0.23
|
|
162
191
|
* @function markHTMLElementAsActive
|
|
163
192
|
* @param {HTMLElement} obj - some element
|
|
164
193
|
* @return {boolean}
|
|
165
|
-
* @description Marks a given HTML-element as "active".
|
|
166
194
|
*/
|
|
167
195
|
function markHTMLElementAsActive(obj) {
|
|
168
196
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -171,11 +199,11 @@ function markHTMLElementAsActive(obj) {
|
|
|
171
199
|
};
|
|
172
200
|
|
|
173
201
|
/**
|
|
202
|
+
* Unmarks a given HTML-element previous marked as "active".
|
|
174
203
|
* @since v0.0.23
|
|
175
204
|
* @function unmarkActiveHTMLElement
|
|
176
205
|
* @param {HTMLElement} obj - some element
|
|
177
206
|
* @return {boolean}
|
|
178
|
-
* @description Unmarks a given HTML-element previous marked as "active".
|
|
179
207
|
*/
|
|
180
208
|
function unmarkActiveHTMLElement(obj) {
|
|
181
209
|
const isSUCCEED = isHTMLElement(obj);
|
|
@@ -184,11 +212,11 @@ function unmarkActiveHTMLElement(obj) {
|
|
|
184
212
|
};
|
|
185
213
|
|
|
186
214
|
/**
|
|
215
|
+
* Disables a given HTML-element.
|
|
187
216
|
* @since v0.0.23
|
|
188
217
|
* @function lockHTMLElement
|
|
189
218
|
* @param {HTMLElement} obj - some element
|
|
190
219
|
* @return {boolean}
|
|
191
|
-
* @description Disables a given HTML-element.
|
|
192
220
|
*/
|
|
193
221
|
function lockHTMLElement(obj) {
|
|
194
222
|
let isSUCCEED = isHTMLElement(obj);
|
|
@@ -208,11 +236,11 @@ function lockHTMLElement(obj) {
|
|
|
208
236
|
};
|
|
209
237
|
|
|
210
238
|
/**
|
|
239
|
+
* Enables a given HTML-element.
|
|
211
240
|
* @since v0.0.23
|
|
212
241
|
* @function unlockHTMLElement
|
|
213
242
|
* @param {HTMLElement} obj - some element
|
|
214
243
|
* @return {boolean}
|
|
215
|
-
* @description Enables a given HTML-element.
|
|
216
244
|
*/
|
|
217
245
|
function unlockHTMLElement(obj) {
|
|
218
246
|
let isSUCCEED = isHTMLElement(obj);
|
|
@@ -232,11 +260,11 @@ function unlockHTMLElement(obj) {
|
|
|
232
260
|
};
|
|
233
261
|
|
|
234
262
|
/**
|
|
263
|
+
* Enables an HTML-elements given by a list of a function params.
|
|
235
264
|
* @since v0.0.23
|
|
236
265
|
* @function activateHTMLElements
|
|
237
266
|
* @param {...HTMLElement} obj - some element
|
|
238
267
|
* @return {void}
|
|
239
|
-
* @description Enables an HTML-elements given by a list of a function params.
|
|
240
268
|
*/
|
|
241
269
|
function activateHTMLElements(...args) {
|
|
242
270
|
for (let item of args) {
|
|
@@ -245,11 +273,11 @@ function activateHTMLElements(...args) {
|
|
|
245
273
|
};
|
|
246
274
|
|
|
247
275
|
/**
|
|
276
|
+
* Disables an HTML-elements given by a list of a function params.
|
|
248
277
|
* @since v0.0.23
|
|
249
278
|
* @function inactivateHTMLElements
|
|
250
279
|
* @param {...HTMLElement} obj - some element
|
|
251
280
|
* @return {void}
|
|
252
|
-
* @description Disables an HTML-elements given by a list of a function params.
|
|
253
281
|
*/
|
|
254
282
|
function inactivateHTMLElements(...args) {
|
|
255
283
|
for (let item of args) {
|
|
@@ -258,11 +286,11 @@ function inactivateHTMLElements(...args) {
|
|
|
258
286
|
};
|
|
259
287
|
|
|
260
288
|
/**
|
|
289
|
+
* Tries to convert a given value to a valid name of an HTML-tag.
|
|
261
290
|
* @since v0.0.21
|
|
262
291
|
* @function readAsTagName
|
|
263
292
|
* @param {any} value - some value
|
|
264
293
|
* @return {string}
|
|
265
|
-
* @description Tries to convert a given value to a valid name of an HTML-tag.
|
|
266
294
|
*/
|
|
267
295
|
function readAsTagName(value) {
|
|
268
296
|
let tagName = valueToIDString(value, { ignoreNumbers: true });
|
|
@@ -281,12 +309,11 @@ function readAsTagName(value) {
|
|
|
281
309
|
};
|
|
282
310
|
|
|
283
311
|
/**
|
|
312
|
+
* Tries to convert a given value to a valid name of an HTML-attribute.
|
|
284
313
|
* @since v0.0.21
|
|
285
314
|
* @function readAsAttrName
|
|
286
315
|
* @param {any} value - some value
|
|
287
316
|
* @return {string}
|
|
288
|
-
* @description Tries to convert a given value to a valid name
|
|
289
|
-
* of an HTML-attribute.
|
|
290
317
|
*/
|
|
291
318
|
function readAsAttrName(value) {
|
|
292
319
|
let attrName = valueToIDString(value, { ignoreNumbers: true });
|
|
@@ -304,11 +331,11 @@ function readAsAttrName(value) {
|
|
|
304
331
|
};
|
|
305
332
|
|
|
306
333
|
/**
|
|
334
|
+
* Tries to convert a given value to a valid "attribute value".
|
|
307
335
|
* @since v0.0.18
|
|
308
336
|
* @function readAsAttrValue
|
|
309
337
|
* @param {any} value - some value
|
|
310
338
|
* @return {?string}
|
|
311
|
-
* @description Tries to convert a given value to a valid "attribute value".
|
|
312
339
|
*/
|
|
313
340
|
function readAsAttrValue(value) {
|
|
314
341
|
let result = null;
|
|
@@ -332,13 +359,12 @@ function readAsAttrValue(value) {
|
|
|
332
359
|
};
|
|
333
360
|
|
|
334
361
|
/**
|
|
362
|
+
* Tries to convert a given value to a list of a valid "class attributes".
|
|
335
363
|
* @since v0.0.13
|
|
336
364
|
* @function valueToClassList
|
|
337
365
|
* @param {any} value - some value
|
|
338
366
|
* @param {boolean} [opt] - flag that indicates whether a dups allowed
|
|
339
367
|
* @return {string[]}
|
|
340
|
-
* @description Tries to convert a given value to a list of a valid
|
|
341
|
-
* "class attributes".
|
|
342
368
|
*/
|
|
343
369
|
function valueToClassList(value, opt) {
|
|
344
370
|
let result = [];
|
|
@@ -360,12 +386,12 @@ function valueToClassList(value, opt) {
|
|
|
360
386
|
};
|
|
361
387
|
|
|
362
388
|
/**
|
|
389
|
+
* Tries to convert a given value to a valid identifier suitable as a value
|
|
390
|
+
* for an "ID-attribute" of an HTML-element.
|
|
363
391
|
* @since v0.0.22
|
|
364
392
|
* @function valueToElementID
|
|
365
393
|
* @param {any} value - some value
|
|
366
394
|
* @return {string}
|
|
367
|
-
* @description Tries to convert a given value to a valid identifier
|
|
368
|
-
* suitable as a value for an "ID-attribute" of an HTML-element.
|
|
369
395
|
*/
|
|
370
396
|
function valueToElementID(value) {
|
|
371
397
|
let id = valueToIDString(value);
|
|
@@ -383,22 +409,22 @@ function valueToElementID(value) {
|
|
|
383
409
|
};
|
|
384
410
|
|
|
385
411
|
/**
|
|
412
|
+
* An element descriptor.
|
|
386
413
|
* @typedef {Object} elemDesc
|
|
387
414
|
* @property {string} [id] - element ID
|
|
388
415
|
* @property {string} [text] - some text
|
|
389
416
|
* @property {Object<string, any>} [attr] - an attributes list
|
|
390
417
|
* @property {string|string[]} [classNames] - a class names list (added since v0.0.19)
|
|
391
418
|
* @property {Object<string, any>} [data] - a 'dataset'-attributes list
|
|
392
|
-
* @description An element description.
|
|
393
419
|
*/
|
|
394
420
|
|
|
395
421
|
/**
|
|
422
|
+
* Creates a new HTML-element.
|
|
396
423
|
* @since 0.0.25
|
|
397
424
|
* @function createNewHTMLElement
|
|
398
425
|
* @param {string} tagName - an element tag name
|
|
399
|
-
* @param {elemDesc} [opt] - an element
|
|
426
|
+
* @param {elemDesc} [opt] - an element descriptor object
|
|
400
427
|
* @return {?HTMLElement}
|
|
401
|
-
* @description Creates a new HTML-element.
|
|
402
428
|
*/
|
|
403
429
|
function createNewHTMLElement(tagName, opt) {
|
|
404
430
|
let item = null;
|
|
@@ -492,6 +518,7 @@ module.exports.CSS_CLASS_STRING = /*function(){ return*/ {
|
|
|
492
518
|
}/*}*/;
|
|
493
519
|
|
|
494
520
|
module.exports.isHTMLElement = isHTMLElement;
|
|
521
|
+
module.exports.isHTMLButton = isHTMLButton;
|
|
495
522
|
module.exports.isCurrentHTMLElement = isCurrentHTMLElement;
|
|
496
523
|
module.exports.isSelectedHTMLElement = isSelectedHTMLElement;
|
|
497
524
|
module.exports.isActiveHTMLElement = isActiveHTMLElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cntwg/html-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "A base HTML-helper library for js",
|
|
5
5
|
"author": "ygracs <cs70th-om@rambler.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"#test-dir/*": "./__test__/*"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ygracs/bsfoc-lib-js": "^0.
|
|
46
|
-
"@ygracs/lists-lib-js": "^0.0
|
|
45
|
+
"@ygracs/bsfoc-lib-js": "^0.3.0",
|
|
46
|
+
"@ygracs/lists-lib-js": "^0.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"jest": "^
|
|
50
|
-
"jest-environment-jsdom": "^
|
|
51
|
-
"jsdoc-to-markdown": "^9.1.
|
|
49
|
+
"jest": "^30.0.5",
|
|
50
|
+
"jest-environment-jsdom": "^30.0.5",
|
|
51
|
+
"jsdoc-to-markdown": "^9.1.2",
|
|
52
52
|
"minimist": "^1.2.8"
|
|
53
53
|
}
|
|
54
54
|
}
|