@cntwg/html-helper 0.0.26 → 0.1.0

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.
@@ -1,4 +1,4 @@
1
- // [v0.1.041-20250509]
1
+ // [v0.1.044-20251023]
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 extra block (helper functions) ===
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 description object
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;
@@ -472,11 +498,6 @@ function createNewHTMLElement(tagName, opt) {
472
498
  return item;
473
499
  };
474
500
 
475
- /** @deprecated */
476
- function createNewHtmlElement(...args) {
477
- return createNewHTMLElement(...args);
478
- };
479
-
480
501
  /***
481
502
  * (* class definitions *)
482
503
  */
@@ -492,6 +513,7 @@ module.exports.CSS_CLASS_STRING = /*function(){ return*/ {
492
513
  }/*}*/;
493
514
 
494
515
  module.exports.isHTMLElement = isHTMLElement;
516
+ module.exports.isHTMLButton = isHTMLButton;
495
517
  module.exports.isCurrentHTMLElement = isCurrentHTMLElement;
496
518
  module.exports.isSelectedHTMLElement = isSelectedHTMLElement;
497
519
  module.exports.isActiveHTMLElement = isActiveHTMLElement;
@@ -512,15 +534,12 @@ module.exports.inactivateHTMLElements = inactivateHTMLElements;
512
534
 
513
535
  module.exports.valueToClassList = valueToClassList;
514
536
 
515
- // experimental
537
+ // * experimental *
516
538
  module.exports.createNewHTMLElement = createNewHTMLElement;
517
539
  module.exports.readAsAttrValue = readAsAttrValue;
518
540
  module.exports.readAsTagName = readAsTagName;
519
541
  module.exports.readAsAttrName = readAsAttrName;
520
542
  module.exports.valueToElementID = valueToElementID;
521
543
 
522
- // re-exported
544
+ // * re-exported *
523
545
  module.exports.valueToIDString = valueToIDString;
524
-
525
- // @deprecated
526
- module.exports.createNewHtmlElement = createNewHtmlElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/html-helper",
3
- "version": "0.0.26",
3
+ "version": "0.1.0",
4
4
  "description": "A base HTML-helper library for js",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -10,18 +10,11 @@
10
10
  },
11
11
  "keywords": [
12
12
  "electron",
13
- "html",
14
- "component"
13
+ "html"
15
14
  ],
16
15
  "main": "./index.js",
17
16
  "files": [
18
17
  "doc/*.md",
19
- "lib/html-ctrls/lists-stubs.js",
20
- "lib/html-ctrls/lists-btn.js",
21
- "lib/html-ctrls/list.js",
22
- "lib/html-ctrls/buttons.js",
23
- "lib/html-ctrls/fields.js",
24
- "lib/html-ctrls/mod-hfunc.js",
25
18
  "lib/html-helper-lib.js",
26
19
  "lib/event-hfunc.js",
27
20
  "index.js",
@@ -32,8 +25,6 @@
32
25
  "test-bs": "jest base/",
33
26
  "test-bs:g1": "jest base/fg-1",
34
27
  "test-bs:g2": "jest base/fg-2",
35
- "test-lc2:bs": "jest THtmlItemsListController/base",
36
- "test-lc2:ec": "jest THtmlItemsListController/events",
37
28
  "build-doc-md": "jsdoc2md",
38
29
  "build-doc-html": "jsdoc"
39
30
  },
@@ -42,13 +33,13 @@
42
33
  "#test-dir/*": "./__test__/*"
43
34
  },
44
35
  "dependencies": {
45
- "@ygracs/bsfoc-lib-js": "^0.2.3",
46
- "@ygracs/lists-lib-js": "^0.0.4"
36
+ "@ygracs/bsfoc-lib-js": "^0.3.0",
37
+ "@ygracs/lists-lib-js": "^0.1.0"
47
38
  },
48
39
  "devDependencies": {
49
- "jest": "^29.7.0",
50
- "jest-environment-jsdom": "^29.7.0",
51
- "jsdoc-to-markdown": "^9.1.1",
40
+ "jest": "^30.2.0",
41
+ "jest-environment-jsdom": "^30.2.0",
42
+ "jsdoc-to-markdown": "^9.1.2",
52
43
  "minimist": "^1.2.8"
53
44
  }
54
45
  }