tiny-essentials 1.21.2 → 1.21.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.
@@ -2039,6 +2039,12 @@ declare class TinyHtml {
2039
2039
  * @returns {TinyHtml} An array of TinyHtml instances wrapping the found elements.
2040
2040
  */
2041
2041
  getElementsByTagNameNS(localName: string, namespaceURI?: string | null): TinyHtml;
2042
+ /**
2043
+ * Iterates over all elements, executing the provided callback on each.
2044
+ * @param {(element: TinyHtml, index: number, items: TinyHtml[]) => void} callback - Function invoked for each element.
2045
+ * @returns {TinyHtml} The current instance for chaining.
2046
+ */
2047
+ forEach(callback: (element: TinyHtml, index: number, items: TinyHtml[]) => void): TinyHtml;
2042
2048
  /**
2043
2049
  * Returns the current target held by this instance.
2044
2050
  *
@@ -2127,8 +2133,17 @@ declare class TinyHtml {
2127
2133
  * @returns {boolean} `true` if both elements are the same DOM node; otherwise, `false`.
2128
2134
  */
2129
2135
  isSameDom(elem: TinyNode): boolean;
2130
- /** @type {ElementDataStore} */
2131
- _data: ElementDataStore;
2136
+ /**
2137
+ * Replaces the internal data with a new object.
2138
+ * @param {ElementDataStore} value - Must be a non-null object.
2139
+ * @throws {Error} If the value is not a valid object.
2140
+ */
2141
+ set _data(value: ElementDataStore);
2142
+ /**
2143
+ * Returns a shallow copy of the internal data.
2144
+ * @type {ElementDataStore}
2145
+ */
2146
+ get _data(): ElementDataStore;
2132
2147
  /**
2133
2148
  * Retrieves data associated with a DOM element.
2134
2149
  *
@@ -550,6 +550,17 @@ class TinyHtml {
550
550
  return TinyHtml.getByTagNameNS(localName, namespaceURI, TinyHtml._preElem(this, 'getByTagNameNS'));
551
551
  }
552
552
  //////////////////////////////////////////////////////////////////
553
+ /**
554
+ * Iterates over all elements, executing the provided callback on each.
555
+ * @param {(element: TinyHtml, index: number, items: TinyHtml[]) => void} callback - Function invoked for each element.
556
+ * @returns {TinyHtml} The current instance for chaining.
557
+ */
558
+ forEach(callback) {
559
+ const elems = this.getAll().map((el, index) => this.extract(index));
560
+ for (const index in elems)
561
+ callback(elems[index], Number(index), elems);
562
+ return this;
563
+ }
553
564
  /**
554
565
  * Returns the current target held by this instance.
555
566
  *
@@ -1153,8 +1164,28 @@ class TinyHtml {
1153
1164
  return TinyHtml.isSameDom(this, elem);
1154
1165
  }
1155
1166
  //////////////////////////////////////////////////////////////////
1156
- /** @type {ElementDataStore} */
1157
- _data = {};
1167
+ /**
1168
+ * Internal data storage for element information.
1169
+ * @type {ElementDataStore}
1170
+ */
1171
+ #data = {};
1172
+ /**
1173
+ * Returns a shallow copy of the internal data.
1174
+ * @type {ElementDataStore}
1175
+ */
1176
+ get _data() {
1177
+ return { ...this.#data };
1178
+ }
1179
+ /**
1180
+ * Replaces the internal data with a new object.
1181
+ * @param {ElementDataStore} value - Must be a non-null object.
1182
+ * @throws {Error} If the value is not a valid object.
1183
+ */
1184
+ set _data(value) {
1185
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
1186
+ throw new Error('value must be a non-null object.');
1187
+ this.#data = value;
1188
+ }
1158
1189
  /**
1159
1190
  * Internal data selectors for accessing public or private data stores.
1160
1191
  *
@@ -1174,7 +1205,7 @@ class TinyHtml {
1174
1205
  private: (where, el) => {
1175
1206
  if (!(el instanceof TinyHtml))
1176
1207
  throw new Error(`Element must be a TinyHtml instance to execute ${where}().`);
1177
- return el._data;
1208
+ return el.#data;
1178
1209
  },
1179
1210
  };
1180
1211
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.21.2",
3
+ "version": "1.21.3",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",