phane-tech-dom-utils 1.0.3 โ†’ 1.0.4

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.
Files changed (2) hide show
  1. package/README.md +322 -322
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,322 +1,322 @@
1
- # ๐Ÿ“ฆ Kotipalli Phaneendra Kumar - Array Utilities
2
-
3
- A lightweight, safe, and predictable **DOM utility module** that simplifies common DOM operations with **strict validation**, **consistent return values**, and **clean JSDoc documentation**.
4
-
5
- Designed specifically for **browser environments**, this module helps you work confidently with elements, attributes, classes, styles, events, and dynamic DOM creation without unexpected runtime errors.
6
-
7
- ---
8
-
9
- ## โœจ Highlights
10
-
11
- - ๐Ÿงฑ Safe DOM selectors with validation
12
- - ๐Ÿท๏ธ Attribute helpers (get / set / remove)
13
- - ๐Ÿงฉ Class utilities (add / remove / toggle / check)
14
- - ๐ŸŽจ Style helpers (single & multiple styles)
15
- - ๐Ÿงฉ Dynamic element creation & DOM insertion
16
- - ๐ŸŽง Event listener helpers
17
- - โญ Tab title & favicon utilities
18
- - ๐Ÿ“š Fully documented using JSDoc
19
- - โšก Predictable return values (`undefined` for invalid input)
20
-
21
- ---
22
-
23
- ## ๐Ÿ“ฆ Installation
24
-
25
- ```bash
26
- npm install phane-js-dom-helpers
27
- ```
28
- ---
29
-
30
- ## ๐Ÿš€ Import
31
-
32
- ```js
33
- import {
34
- getElementById,
35
- getElementsByClassName,
36
- getElementsByTagName,
37
- setTabTitle,
38
- getTabTitle,
39
- setFavicon,
40
- getFavicon,
41
- setTextContent,
42
- setHTMLContent,
43
- setAttribute,
44
- getAttribute,
45
- removeAttribute,
46
- hasClass,
47
- addClass,
48
- removeClass,
49
- toggleClass,
50
- setStyle,
51
- setStyles,
52
- createDynamicElement,
53
- appendDynamicTag,
54
- removeElement,
55
- addEventListenerHelper,
56
- removeEventListenerHelper,
57
- onElementLoad,
58
- setDataId
59
- } from "phane-js-dom-helpers";
60
- ```
61
-
62
- ---
63
-
64
- ## ๐Ÿ“š API Reference
65
-
66
- ### ๐Ÿ” getElementById(id)
67
-
68
- Safely returns a DOM element by its ID.
69
-
70
- ```js
71
- getElementById("header"); // HTMLElement | null
72
- getElementById("unknown"); // null
73
- getElementById(""); // undefined
74
- ```
75
-
76
- ---
77
-
78
- ### ๐Ÿ” getElementsByClassName(className)
79
-
80
- Returns a live HTMLCollection of elements.
81
-
82
- ```js
83
- getElementsByClassName("card"); // HTMLCollection
84
- ```
85
-
86
- ---
87
-
88
- ### ๐Ÿ” getElementsByTagName(tagName)
89
-
90
- Returns a live HTMLCollection of elements.
91
-
92
- ```js
93
- getElementsByTagName("div"); // HTMLCollection
94
- ```
95
-
96
- ---
97
-
98
- ### ๐Ÿท๏ธ setTabTitle(title)
99
-
100
- Sets the browser tab title.
101
-
102
- ```js
103
- setTabTitle("Home"); // "Home"
104
- ```
105
-
106
- ---
107
-
108
- ### โญ getTabTitle()
109
-
110
- Returns the current tab title.
111
-
112
- ```js
113
- getTabTitle(); // "Home"
114
- ```
115
-
116
- ---
117
-
118
- ### โญ setFavicon(url)
119
-
120
- Sets or updates the browser favicon.
121
-
122
- ```js
123
- setFavicon("/favicon.ico");
124
- ```
125
-
126
- ---
127
-
128
- ### โญ getFavicon()
129
-
130
- Returns the current favicon URL if available.
131
-
132
- ```js
133
- getFavicon(); // string | undefined
134
- ```
135
-
136
- ---
137
-
138
- ### โœ๏ธ setTextContent(element, text)
139
-
140
- Safely sets innerText on an element.
141
-
142
- ```js
143
- setTextContent(el, "Hello World");
144
- ```
145
-
146
- ---
147
-
148
- ### โœ๏ธ setHTMLContent(element, html)
149
-
150
- Safely sets innerHTML on an element.
151
- ```js
152
- setHTMLContent(el, "<b>Hello</b>");
153
- ```
154
-
155
- ---
156
-
157
- ### ๐Ÿงฑ setAttribute(element, name, value)
158
-
159
- Adds or updates an attribute.
160
-
161
- ```js
162
- setAttribute(el, "data-id", "123");
163
- ```
164
-
165
- ---
166
-
167
- ### ๐Ÿงฑ getAttribute(element, name)
168
-
169
- Gets an attribute value.
170
-
171
- ```js
172
- getAttribute(el, "data-id"); // "123"
173
- ```
174
-
175
- ---
176
-
177
- ### ๐Ÿงฑ removeAttribute(element, name)
178
-
179
- Removes an attribute.
180
-
181
- ```js
182
- removeAttribute(el, "disabled");
183
- ```
184
-
185
- ---
186
-
187
- ### ๐Ÿงฉ hasClass(element, className)
188
-
189
- Checks if a class exists on an element.
190
-
191
- ```js
192
- hasClass(el, "active"); // true | false
193
- ```
194
-
195
- ---
196
-
197
- ### ๐Ÿงฉ addClass / removeClass / toggleClass
198
-
199
- Manages element classes safely.
200
-
201
- ```js
202
- addClass(el, "active");
203
- removeClass(el, "active");
204
- toggleClass(el, "active");
205
- ```
206
-
207
- ---
208
-
209
- ### ๐ŸŽจ setStyle(element, property, value)
210
-
211
- Sets a single CSS style.
212
-
213
- ```js
214
- setStyle(el, "color", "red");
215
- ```
216
-
217
- ---
218
-
219
- ### ๐ŸŽจ setStyles(element, styles)
220
-
221
- Applies multiple CSS styles at once.
222
-
223
- ```js
224
- setStyles(el, {
225
- color: "red",
226
- backgroundColor: "yellow"
227
- });
228
- ```
229
- ---
230
-
231
- ### ๐Ÿงฉ createDynamicElement(tag, content?, props?)
232
-
233
- Creates a DOM element dynamically.
234
-
235
- ```js
236
- createDynamicElement("div", "Hello", {
237
- id: "box",
238
- className: "card"
239
- });
240
- ```
241
-
242
- ---
243
-
244
- ### โž• appendDynamicTag(child, parent?)
245
-
246
- Appends an element to the DOM.
247
-
248
- ```js
249
- appendDynamicTag(div);
250
- appendDynamicTag(div, container);
251
- ```
252
- ---
253
-
254
- ### โŒ removeElement(child, parent?)
255
-
256
- Removes an element from the DOM.
257
-
258
- ```js
259
- removeElement(div);
260
- ```
261
-
262
- ---
263
-
264
- ### ๐ŸŽง addEventListenerHelper(el, type, handler)
265
-
266
- Adds an event listener safely.
267
-
268
- ```js
269
- addEventListenerHelper(btn, "click", handleClick);
270
- ```
271
-
272
- ---
273
-
274
- ### ๐ŸŽง removeEventListenerHelper(el, type, handler)
275
-
276
- Removes an event listener safely.
277
-
278
- ```js
279
- removeEventListenerHelper(btn, "click", handleClick);
280
- ```
281
-
282
- ---
283
-
284
- ### โณ onElementLoad(element?, handler)
285
-
286
- Executes a handler when DOM or element is ready.
287
-
288
- ```js
289
- onElementLoad(null, () => console.log("DOM Ready"));
290
- ```
291
-
292
-
293
- ---
294
-
295
- ### ๐Ÿ†” setDataId(element, value)
296
-
297
- Sets data-id attribute.
298
-
299
- ```js
300
- setDataId(el, "123");
301
- ```
302
- ---
303
-
304
- ## ๐Ÿงช Design Principles
305
-
306
- - โŒ Invalid input โ†’ undefined
307
- - โœ… Safe DOM access
308
- - ๐Ÿ” No unexpected mutations
309
- - ๐Ÿ“– Predictable, documented behavior
310
-
311
-
312
- ## ๐Ÿ“„ License
313
-
314
- MIT
315
-
316
- ---
317
- ## ๐Ÿ”— Links
318
-
319
- - **GitHub Repository:** https://github.com/phane-tech/phane-tech-dom-utilities
320
- - **Demo / Documentation:** https://phane-tech.github.io/phane-tech-dom-utilities/module-DomHelpers.html
321
- - **Unit Test Cases Reports:** https://phane-tech.github.io/phane-tech-dom-utilities/unit-test-report.html
322
-
1
+ # ๐Ÿ“ฆ Kotipalli Phaneendra Kumar - Array Utilities
2
+
3
+ A lightweight, safe, and predictable **DOM utility module** that simplifies common DOM operations with **strict validation**, **consistent return values**, and **clean JSDoc documentation**.
4
+
5
+ Designed specifically for **browser environments**, this module helps you work confidently with elements, attributes, classes, styles, events, and dynamic DOM creation without unexpected runtime errors.
6
+
7
+ ---
8
+
9
+ ## โœจ Highlights
10
+
11
+ - ๐Ÿงฑ Safe DOM selectors with validation
12
+ - ๐Ÿท๏ธ Attribute helpers (get / set / remove)
13
+ - ๐Ÿงฉ Class utilities (add / remove / toggle / check)
14
+ - ๐ŸŽจ Style helpers (single & multiple styles)
15
+ - ๐Ÿงฉ Dynamic element creation & DOM insertion
16
+ - ๐ŸŽง Event listener helpers
17
+ - โญ Tab title & favicon utilities
18
+ - ๐Ÿ“š Fully documented using JSDoc
19
+ - โšก Predictable return values (`undefined` for invalid input)
20
+
21
+ ---
22
+
23
+ ## ๐Ÿ“ฆ Installation
24
+
25
+ ```bash
26
+ npm install phane-tech-dom-utils
27
+ ```
28
+ ---
29
+
30
+ ## ๐Ÿš€ Import
31
+
32
+ ```js
33
+ import {
34
+ getElementById,
35
+ getElementsByClassName,
36
+ getElementsByTagName,
37
+ setTabTitle,
38
+ getTabTitle,
39
+ setFavicon,
40
+ getFavicon,
41
+ setTextContent,
42
+ setHTMLContent,
43
+ setAttribute,
44
+ getAttribute,
45
+ removeAttribute,
46
+ hasClass,
47
+ addClass,
48
+ removeClass,
49
+ toggleClass,
50
+ setStyle,
51
+ setStyles,
52
+ createDynamicElement,
53
+ appendDynamicTag,
54
+ removeElement,
55
+ addEventListenerHelper,
56
+ removeEventListenerHelper,
57
+ onElementLoad,
58
+ setDataId
59
+ } from "phane-tech-dom-utils";
60
+ ```
61
+
62
+ ---
63
+
64
+ ## ๐Ÿ“š API Reference
65
+
66
+ ### ๐Ÿ” getElementById(id)
67
+
68
+ Safely returns a DOM element by its ID.
69
+
70
+ ```js
71
+ getElementById("header"); // HTMLElement | null
72
+ getElementById("unknown"); // null
73
+ getElementById(""); // undefined
74
+ ```
75
+
76
+ ---
77
+
78
+ ### ๐Ÿ” getElementsByClassName(className)
79
+
80
+ Returns a live HTMLCollection of elements.
81
+
82
+ ```js
83
+ getElementsByClassName("card"); // HTMLCollection
84
+ ```
85
+
86
+ ---
87
+
88
+ ### ๐Ÿ” getElementsByTagName(tagName)
89
+
90
+ Returns a live HTMLCollection of elements.
91
+
92
+ ```js
93
+ getElementsByTagName("div"); // HTMLCollection
94
+ ```
95
+
96
+ ---
97
+
98
+ ### ๐Ÿท๏ธ setTabTitle(title)
99
+
100
+ Sets the browser tab title.
101
+
102
+ ```js
103
+ setTabTitle("Home"); // "Home"
104
+ ```
105
+
106
+ ---
107
+
108
+ ### โญ getTabTitle()
109
+
110
+ Returns the current tab title.
111
+
112
+ ```js
113
+ getTabTitle(); // "Home"
114
+ ```
115
+
116
+ ---
117
+
118
+ ### โญ setFavicon(url)
119
+
120
+ Sets or updates the browser favicon.
121
+
122
+ ```js
123
+ setFavicon("/favicon.ico");
124
+ ```
125
+
126
+ ---
127
+
128
+ ### โญ getFavicon()
129
+
130
+ Returns the current favicon URL if available.
131
+
132
+ ```js
133
+ getFavicon(); // string | undefined
134
+ ```
135
+
136
+ ---
137
+
138
+ ### โœ๏ธ setTextContent(element, text)
139
+
140
+ Safely sets innerText on an element.
141
+
142
+ ```js
143
+ setTextContent(el, "Hello World");
144
+ ```
145
+
146
+ ---
147
+
148
+ ### โœ๏ธ setHTMLContent(element, html)
149
+
150
+ Safely sets innerHTML on an element.
151
+ ```js
152
+ setHTMLContent(el, "<b>Hello</b>");
153
+ ```
154
+
155
+ ---
156
+
157
+ ### ๐Ÿงฑ setAttribute(element, name, value)
158
+
159
+ Adds or updates an attribute.
160
+
161
+ ```js
162
+ setAttribute(el, "data-id", "123");
163
+ ```
164
+
165
+ ---
166
+
167
+ ### ๐Ÿงฑ getAttribute(element, name)
168
+
169
+ Gets an attribute value.
170
+
171
+ ```js
172
+ getAttribute(el, "data-id"); // "123"
173
+ ```
174
+
175
+ ---
176
+
177
+ ### ๐Ÿงฑ removeAttribute(element, name)
178
+
179
+ Removes an attribute.
180
+
181
+ ```js
182
+ removeAttribute(el, "disabled");
183
+ ```
184
+
185
+ ---
186
+
187
+ ### ๐Ÿงฉ hasClass(element, className)
188
+
189
+ Checks if a class exists on an element.
190
+
191
+ ```js
192
+ hasClass(el, "active"); // true | false
193
+ ```
194
+
195
+ ---
196
+
197
+ ### ๐Ÿงฉ addClass / removeClass / toggleClass
198
+
199
+ Manages element classes safely.
200
+
201
+ ```js
202
+ addClass(el, "active");
203
+ removeClass(el, "active");
204
+ toggleClass(el, "active");
205
+ ```
206
+
207
+ ---
208
+
209
+ ### ๐ŸŽจ setStyle(element, property, value)
210
+
211
+ Sets a single CSS style.
212
+
213
+ ```js
214
+ setStyle(el, "color", "red");
215
+ ```
216
+
217
+ ---
218
+
219
+ ### ๐ŸŽจ setStyles(element, styles)
220
+
221
+ Applies multiple CSS styles at once.
222
+
223
+ ```js
224
+ setStyles(el, {
225
+ color: "red",
226
+ backgroundColor: "yellow"
227
+ });
228
+ ```
229
+ ---
230
+
231
+ ### ๐Ÿงฉ createDynamicElement(tag, content?, props?)
232
+
233
+ Creates a DOM element dynamically.
234
+
235
+ ```js
236
+ createDynamicElement("div", "Hello", {
237
+ id: "box",
238
+ className: "card"
239
+ });
240
+ ```
241
+
242
+ ---
243
+
244
+ ### โž• appendDynamicTag(child, parent?)
245
+
246
+ Appends an element to the DOM.
247
+
248
+ ```js
249
+ appendDynamicTag(div);
250
+ appendDynamicTag(div, container);
251
+ ```
252
+ ---
253
+
254
+ ### โŒ removeElement(child, parent?)
255
+
256
+ Removes an element from the DOM.
257
+
258
+ ```js
259
+ removeElement(div);
260
+ ```
261
+
262
+ ---
263
+
264
+ ### ๐ŸŽง addEventListenerHelper(el, type, handler)
265
+
266
+ Adds an event listener safely.
267
+
268
+ ```js
269
+ addEventListenerHelper(btn, "click", handleClick);
270
+ ```
271
+
272
+ ---
273
+
274
+ ### ๐ŸŽง removeEventListenerHelper(el, type, handler)
275
+
276
+ Removes an event listener safely.
277
+
278
+ ```js
279
+ removeEventListenerHelper(btn, "click", handleClick);
280
+ ```
281
+
282
+ ---
283
+
284
+ ### โณ onElementLoad(element?, handler)
285
+
286
+ Executes a handler when DOM or element is ready.
287
+
288
+ ```js
289
+ onElementLoad(null, () => console.log("DOM Ready"));
290
+ ```
291
+
292
+
293
+ ---
294
+
295
+ ### ๐Ÿ†” setDataId(element, value)
296
+
297
+ Sets data-id attribute.
298
+
299
+ ```js
300
+ setDataId(el, "123");
301
+ ```
302
+ ---
303
+
304
+ ## ๐Ÿงช Design Principles
305
+
306
+ - โŒ Invalid input โ†’ undefined
307
+ - โœ… Safe DOM access
308
+ - ๐Ÿ” No unexpected mutations
309
+ - ๐Ÿ“– Predictable, documented behavior
310
+
311
+
312
+ ## ๐Ÿ“„ License
313
+
314
+ MIT
315
+
316
+ ---
317
+ ## ๐Ÿ”— Links
318
+
319
+ - **GitHub Repository:** https://github.com/phane-tech/phane-tech-dom-utilities
320
+ - **Demo / Documentation:** https://phane-tech.github.io/phane-tech-dom-utilities/module-DomHelpers.html
321
+ - **Unit Test Cases Reports:** https://phane-tech.github.io/phane-tech-dom-utilities/unit-test-report.html
322
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phane-tech-dom-utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Pure JavaScript DOM utility functions",
5
5
  "type": "module",
6
6
  "main": "index.cjs",