@cntwg/html-helper 0.1.2 → 0.1.3

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 CHANGED
@@ -1,3 +1,10 @@
1
+ #### *v0.1.3*
2
+
3
+ Release version.
4
+
5
+ > - `README.md` updated;
6
+ > - some fixes.
7
+
1
8
  #### *v0.1.2*
2
9
 
3
10
  Release version.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- >|***rev.*:**|0.2.8|
1
+ >|***rev.*:**|0.2.9|
2
2
  >|:---|---:|
3
- >|date:|2025-10-23|
3
+ >|date:|2026-04-14|
4
4
 
5
5
  ## Introduction
6
6
 
@@ -36,3 +36,5 @@ This module was make for use as a library in a development of a Web-apps based o
36
36
  ### Installation
37
37
 
38
38
  `npm install @cntwg/html-helper`
39
+
40
+ > Note: It's recommended to "pin" a package versions range to its minor releases after installation. To do so use `~` range specifier (*e.g. `~0.1.0`*) in `package.json`.
package/index.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ export namespace eventHelper {
2
+ let pushEventHandler: typeof ev_helper.pushEventHandler;
3
+ let removeEventHandler: typeof ev_helper.removeEventHandler;
4
+ let triggerEventHandler: typeof ev_helper.triggerEventHandler;
5
+ }
6
+ import { valueToIDString } from "@ygracs/bsfoc-lib-js";
7
+ import ev_helper = require("./lib/event-hfunc.js");
8
+
9
+ import {
10
+ CSS_CLASS_STRING,
11
+ isHTMLElement,
12
+ isSelectedHTMLElement, isCurrentHTMLElement,
13
+ isActiveHTMLElement, isHiddenHTMLElement,
14
+ hideHTMLElement, showHTMLElement,
15
+ selectHTMLElement, unselectHTMLElement,
16
+ markHTMLElementAsCurrent, unmarkCurrentHTMLElement,
17
+ markHTMLElementAsActive, unmarkActiveHTMLElement,
18
+ lockHTMLElement, unlockHTMLElement,
19
+ activateHTMLElements, inactivateHTMLElements,
20
+ valueToClassList,
21
+ readAsTagName, readAsAttrName, readAsAttrValue,
22
+ valueToElementID,
23
+ createNewHTMLElement,
24
+ isHTMLButton,
25
+ } from "./lib/html-helper-lib.js";
26
+
27
+ export {
28
+ CSS_CLASS_STRING,
29
+ isHTMLElement,
30
+ isSelectedHTMLElement, isCurrentHTMLElement,
31
+ isActiveHTMLElement, isHiddenHTMLElement,
32
+ hideHTMLElement, showHTMLElement,
33
+ selectHTMLElement, unselectHTMLElement,
34
+ markHTMLElementAsCurrent, unmarkCurrentHTMLElement,
35
+ markHTMLElementAsActive, unmarkActiveHTMLElement,
36
+ lockHTMLElement, unlockHTMLElement,
37
+ activateHTMLElements, inactivateHTMLElements,
38
+ valueToClassList,
39
+ readAsTagName, readAsAttrName, readAsAttrValue,
40
+ valueToElementID,
41
+ createNewHTMLElement,
42
+ isHTMLButton,
43
+ valueToIDString,
44
+ };
package/index.js CHANGED
@@ -1,9 +1,9 @@
1
- // [v0.2.034-20260309]
1
+ // [v0.2.035-20260413]
2
2
 
3
3
  // === module init block ===
4
4
 
5
- const html_helper = require('./lib/html-helper-lib.js');
6
- const ev_helper = require('./lib/event-hfunc.js');
5
+ const html_helper = require('./lib/html-helper-lib');
6
+ const ev_helper = require('./lib/event-hfunc');
7
7
 
8
8
  const {
9
9
  valueToIDString,
@@ -19,6 +19,7 @@ const eventHelper = {
19
19
  removeEventHandler: ev_helper.removeEventHandler,
20
20
  triggerEventHandler: ev_helper.triggerEventHandler,
21
21
  };
22
+ module.exports.eventHelper = eventHelper;
22
23
 
23
24
  // === module exports block ===
24
25
 
@@ -50,7 +51,5 @@ module.exports.valueToElementID = html_helper.valueToElementID;
50
51
  module.exports.createNewHTMLElement = html_helper.createNewHTMLElement;
51
52
  module.exports.isHTMLButton = html_helper.isHTMLButton;
52
53
 
53
- module.exports.eventHelper = eventHelper;
54
-
55
54
  // * re-exported *
56
55
  module.exports.valueToIDString = valueToIDString;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @inner
3
+ */
4
+ export function pushEventHandler(pool: Map<string, Function>, name: string, evnt: Function): void;
5
+ /**
6
+ * @inner
7
+ */
8
+ export function removeEventHandler(pool: Map<string, Function>, name: string): void;
9
+ /**
10
+ * @inner
11
+ */
12
+ export function triggerEventHandler(pool: Map<string, Function>, name: string, ...args: any[]): void;
@@ -1,4 +1,4 @@
1
- // [v0.1.064-20260309]
1
+ // [v0.1.065-20260413]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -50,14 +50,15 @@ module.exports.removeEventHandler = removeEventHandler;
50
50
  * @function triggerEventHandler
51
51
  * @param {Map<string, Function>} pool - pool object
52
52
  * @param {string} name - event name
53
- * @param {...any} [args]
53
+ * @param {...any} args - optional params send to a target event
54
54
  * @returns {void}
55
55
  * @inner
56
56
  */
57
57
  function triggerEventHandler(pool, name, ...args) {
58
- const _name = typeof name === 'string' ? name.trim() : '';
59
- if (_name !== '') {
60
- if (pool.has(_name)) pool.get(_name)(...args);
58
+ const target = typeof name === 'string' ? name.trim() : '';
59
+ if (target !== '' && pool.has(target)) {
60
+ const e = pool.get(target);
61
+ if (typeof e === 'function') e(...args);
61
62
  };
62
63
  };
63
64
  module.exports.triggerEventHandler = triggerEventHandler;
@@ -0,0 +1,165 @@
1
+ export namespace CSS_CLASS_STRING {
2
+ export { CSS_CLASS_CURRENT };
3
+ export { CSS_CLASS_SELECTED };
4
+ export { CSS_CLASS_ACTIVE };
5
+ export { CSS_CLASS_DISABLED };
6
+ export { CSS_CLASS_HIDDEN };
7
+ }
8
+
9
+ /**
10
+ * An element descriptor.
11
+ */
12
+ export type elemDesc = {
13
+ /**
14
+ * - element ID
15
+ */
16
+ id?: string;
17
+ /**
18
+ * - some text
19
+ */
20
+ text?: string;
21
+ /**
22
+ * - an attributes list
23
+ */
24
+ attr?: {
25
+ [x: string]: any;
26
+ };
27
+ /**
28
+ * - a class names list
29
+ * @since 0.0.19
30
+ */
31
+ classNames?: string | string[];
32
+ /**
33
+ * - a 'dataset'-attributes list
34
+ */
35
+ data?: {
36
+ [x: string]: any;
37
+ };
38
+ };
39
+
40
+ declare const CSS_CLASS_CURRENT: "current";
41
+ declare const CSS_CLASS_SELECTED: "selected";
42
+ declare const CSS_CLASS_ACTIVE: "active";
43
+ declare const CSS_CLASS_DISABLED: "disabled";
44
+ declare const CSS_CLASS_HIDDEN: "hidden";
45
+
46
+ /**
47
+ * Checks if the given object is an instance of an `HTMLElement`.
48
+ */
49
+ export function isHTMLElement(obj: any): obj is HTMLElement;
50
+ /**
51
+ * Checks if the given object is an HTML-button.
52
+ */
53
+ export function isHTMLButton(obj: any): boolean;
54
+ /**
55
+ * Checks if the given object is an instance of a `HTMLElement`
56
+ * and if so it's marked as "current".
57
+ */
58
+ export function isCurrentHTMLElement(obj: HTMLElement): boolean;
59
+ /**
60
+ * Checks if the given object is an instance of a `HTMLElement`
61
+ * and if so it's marked as "selected".
62
+ */
63
+ export function isSelectedHTMLElement(obj: HTMLElement): boolean;
64
+ /**
65
+ * Checks if the given object is an instance of a `HTMLElement`
66
+ * and if so it's marked as "active".
67
+ */
68
+ export function isActiveHTMLElement(obj: HTMLElement): boolean;
69
+ /**
70
+ * Checks if the given object is an instance of a `HTMLElement`
71
+ * and if so it's marked as "hidden".
72
+ */
73
+ export function isHiddenHTMLElement(obj: HTMLElement): boolean;
74
+ /**
75
+ * Shows a given HTML-element.
76
+ * @since v0.0.23
77
+ */
78
+ export function showHTMLElement(obj: HTMLElement): boolean;
79
+ /**
80
+ * Hides a given HTML-element.
81
+ * @since v0.0.23
82
+ */
83
+ export function hideHTMLElement(obj: HTMLElement): boolean;
84
+ /**
85
+ * Makes selected a given HTML-element.
86
+ * @since v0.0.23
87
+ */
88
+ export function selectHTMLElement(obj: HTMLElement): boolean;
89
+ /**
90
+ * Makes unselected a given HTML-element.
91
+ * @since v0.0.23
92
+ */
93
+ export function unselectHTMLElement(obj: HTMLElement): boolean;
94
+ /**
95
+ * Marks a given HTML-element as "current".
96
+ * @since v0.0.23
97
+ */
98
+ export function markHTMLElementAsCurrent(obj: HTMLElement): boolean;
99
+ /**
100
+ * Unmarks a given HTML-element previous marked as "current".
101
+ * @since v0.0.23
102
+ */
103
+ export function unmarkCurrentHTMLElement(obj: HTMLElement): boolean;
104
+ /**
105
+ * Marks a given HTML-element as "active".
106
+ * @since v0.0.23
107
+ */
108
+ export function markHTMLElementAsActive(obj: HTMLElement): boolean;
109
+ /**
110
+ * Unmarks a given HTML-element previous marked as "active".
111
+ * @since v0.0.23
112
+ */
113
+ export function unmarkActiveHTMLElement(obj: HTMLElement): boolean;
114
+ /**
115
+ * Disables a given HTML-element.
116
+ * @since v0.0.23
117
+ */
118
+ export function lockHTMLElement(obj: HTMLElement): boolean;
119
+ /**
120
+ * Enables a given HTML-element.
121
+ * @since v0.0.23
122
+ */
123
+ export function unlockHTMLElement(obj: HTMLElement): boolean;
124
+ /**
125
+ * Enables an HTML-elements given by a list of a function params.
126
+ * @since v0.0.23
127
+ */
128
+ export function activateHTMLElements(...args: HTMLElement[]): void;
129
+ /**
130
+ * Disables an HTML-elements given by a list of a function params.
131
+ * @since v0.0.23
132
+ */
133
+ export function inactivateHTMLElements(...args: HTMLElement[]): void;
134
+ /**
135
+ * Tries to convert a given value to a list of a valid "class attributes".
136
+ * @since v0.0.13
137
+ */
138
+ export function valueToClassList(value: any, opt?: boolean): string[];
139
+ /**
140
+ * Creates a new HTML-element.
141
+ * @since 0.0.25
142
+ */
143
+ export function createNewHTMLElement(tagName: string, opt?: elemDesc): HTMLElement | null;
144
+ /**
145
+ * Tries to convert a given value to a valid "attribute value".
146
+ * @since v0.0.18
147
+ */
148
+ export function readAsAttrValue(value: any): string | null;
149
+ /**
150
+ * Tries to convert a given value to a valid name of an HTML-tag.
151
+ * @since v0.0.21
152
+ */
153
+ export function readAsTagName(value: any): string;
154
+ /**
155
+ * Tries to convert a given value to a valid name of an HTML-attribute.
156
+ * @since v0.0.21
157
+ */
158
+ export function readAsAttrName(value: any): string;
159
+ /**
160
+ * Tries to convert a given value to a valid identifier suitable as a value
161
+ * for an "ID-attribute" of an HTML-element.
162
+ * @since v0.0.22
163
+ */
164
+ export function valueToElementID(value: any): string;
165
+ export {};
@@ -1,4 +1,4 @@
1
- // [v0.1.046-20260309]
1
+ // [v0.1.047-20260413]
2
2
 
3
3
  // === module init block ===
4
4
 
@@ -255,7 +255,7 @@ function unlockHTMLElement(obj) {
255
255
  * Enables an HTML-elements given by a list of a function params.
256
256
  * @since v0.0.23
257
257
  * @function activateHTMLElements
258
- * @param {...HTMLElement} obj - some element
258
+ * @param {...HTMLElement} args - some element
259
259
  * @return {void}
260
260
  */
261
261
  function activateHTMLElements(...args) {
@@ -268,7 +268,7 @@ function activateHTMLElements(...args) {
268
268
  * Disables an HTML-elements given by a list of a function params.
269
269
  * @since v0.0.23
270
270
  * @function inactivateHTMLElements
271
- * @param {...HTMLElement} obj - some element
271
+ * @param {...HTMLElement} args - some element
272
272
  * @return {void}
273
273
  */
274
274
  function inactivateHTMLElements(...args) {
@@ -359,16 +359,16 @@ function readAsAttrValue(value) {
359
359
  * @return {string[]}
360
360
  */
361
361
  function valueToClassList(value, opt) {
362
+ /** @type {string[]} */
362
363
  let result = [];
363
- let list = valueToArray(value);
364
- list.forEach((elem) => {
364
+ valueToArray(value).forEach((elem) => {
365
365
  let value = '';
366
366
  if (
367
367
  typeof elem === 'string'
368
368
  && ((value = elem.trim()) !== '')
369
369
  ) {
370
- value = value.split(/\s+/);
371
- if (value.length > 0) result.push(...value);
370
+ const a = value.split(/\s+/);
371
+ if (a.length > 0) result.push(...a);
372
372
  };
373
373
  });
374
374
  if (result.length > 0 && typeof opt === 'boolean' && opt) {
@@ -446,8 +446,8 @@ function createNewHTMLElement(tagName, opt) {
446
446
  };
447
447
  // set an attributes of the element
448
448
  if (isObject(attr)) {
449
- attr = isArray(attr) ? attr : Object.entries(attr);
450
- for (let [ key, value ] of attr ) {
449
+ const data = isArray(attr) ? attr : Object.entries(attr);
450
+ for (let [ key, value ] of data ) {
451
451
  if (
452
452
  ((key = readAsAttrName(key)) !== '')
453
453
  ) {
@@ -474,8 +474,8 @@ function createNewHTMLElement(tagName, opt) {
474
474
  };
475
475
  // set a data-attributes of the element
476
476
  if (isObject(dset)) {
477
- dset = isArray(dset) ? dset : Object.entries(dset);
478
- for (let [ key, value ] of dset ) {
477
+ const data = isArray(dset) ? dset : Object.entries(dset);
478
+ for (let [ key, value ] of data ) {
479
479
  if (
480
480
  ((key = readAsAttrName(key)) !== '')
481
481
  && ((value = readAsAttrValue(value)) !== null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntwg/html-helper",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A base HTML-helper library for js",
5
5
  "author": "ygracs <cs70th-om@rambler.ru>",
6
6
  "license": "MIT",
@@ -13,11 +13,14 @@
13
13
  "html"
14
14
  ],
15
15
  "main": "./index.js",
16
+ "types": "./index.d.ts",
16
17
  "files": [
17
18
  "doc/*.md",
18
19
  "lib/html-helper-lib.js",
19
20
  "lib/event-hfunc.js",
21
+ "lib/*.d.ts",
20
22
  "index.js",
23
+ "index.d.ts",
21
24
  "CHANGELOG.md"
22
25
  ],
23
26
  "scripts": {
@@ -26,7 +29,8 @@
26
29
  "test-bs:g1": "jest base/fg-1",
27
30
  "test-bs:g2": "jest base/fg-2",
28
31
  "build-doc-md": "jsdoc2md",
29
- "build-doc-html": "jsdoc"
32
+ "build-doc-html": "jsdoc",
33
+ "gen-dts": "npx -p typescript tsc"
30
34
  },
31
35
  "imports": {
32
36
  "#lib/*": "./lib/*",
@@ -37,9 +41,10 @@
37
41
  },
38
42
  "devDependencies": {
39
43
  "@ygracs/test-helper": "~0.0.2-b",
40
- "jest": "^30.2.0",
41
- "jest-environment-jsdom": "^30.2.0",
44
+ "jest": "^30.3.0",
45
+ "jest-environment-jsdom": "^30.3.0",
42
46
  "jsdoc-to-markdown": "^9.1.3",
43
- "minimist": "^1.2.8"
47
+ "minimist": "^1.2.8",
48
+ "typescript": "~5.9.3"
44
49
  }
45
50
  }