@xmldom/xmldom 0.9.0 → 0.9.2

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/lib/dom.js CHANGED
@@ -980,7 +980,7 @@ DOMImplementation.prototype = {
980
980
  *
981
981
  * **This behavior is slightly different from the in the specs**:
982
982
  * - undeclared properties: nodeType, baseURI, isConnected, parentElement, textContent
983
- * - missing methods: nodeType, baseURI, isConnected, parentElement, textContent
983
+ * - missing methods: contains, getRootNode, isEqualNode, isSameNode
984
984
  *
985
985
  * @class
986
986
  * @abstract
@@ -1018,12 +1018,6 @@ Node.prototype = {
1018
1018
  * @type {Node | null}
1019
1019
  */
1020
1020
  nextSibling: null,
1021
- /**
1022
- * The attributes of this node.
1023
- *
1024
- * @type {NamedNodeMap | null}
1025
- */
1026
- attributes: null,
1027
1021
  /**
1028
1022
  * The parent node of this node.
1029
1023
  *
@@ -1213,16 +1207,6 @@ Node.prototype = {
1213
1207
  isSupported: function (feature, version) {
1214
1208
  return this.ownerDocument.implementation.hasFeature(feature, version);
1215
1209
  },
1216
- /**
1217
- * Determines if the node has any attributes.
1218
- *
1219
- * @returns {boolean}
1220
- * Returns true if the node has any attributes, and false otherwise.
1221
- * @since Introduced in DOM Level 2
1222
- */
1223
- hasAttributes: function () {
1224
- return this.attributes.length > 0;
1225
- },
1226
1210
  /**
1227
1211
  * Look up the prefix associated to the given namespace URI, starting from this node.
1228
1212
  * **The default namespace declarations are ignored by this method.**
@@ -1966,7 +1950,7 @@ Document.prototype = {
1966
1950
 
1967
1951
  insertBefore: function (newChild, refChild) {
1968
1952
  //raises
1969
- if (newChild.nodeType == DOCUMENT_FRAGMENT_NODE) {
1953
+ if (newChild.nodeType === DOCUMENT_FRAGMENT_NODE) {
1970
1954
  var child = newChild.firstChild;
1971
1955
  while (child) {
1972
1956
  var next = child.nextSibling;
@@ -2019,51 +2003,6 @@ Document.prototype = {
2019
2003
  return rtv;
2020
2004
  },
2021
2005
 
2022
- /**
2023
- * The `getElementsByClassName` method of `Document` interface returns an array-like object of
2024
- * all child elements which have **all** of the given class name(s).
2025
- *
2026
- * Returns an empty list if `classeNames` is an empty string or only contains HTML white space
2027
- * characters.
2028
- *
2029
- * Warning: This is a live LiveNodeList.
2030
- * Changes in the DOM will reflect in the array as the changes occur.
2031
- * If an element selected by this array no longer qualifies for the selector,
2032
- * it will automatically be removed. Be aware of this for iteration purposes.
2033
- *
2034
- * @param {string} classNames
2035
- * Is a string representing the class name(s) to match; multiple class names are separated by
2036
- * (ASCII-)whitespace.
2037
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
2038
- * @see https://dom.spec.whatwg.org/#concept-getelementsbyclassname
2039
- */
2040
- getElementsByClassName: function (classNames) {
2041
- var classNamesSet = toOrderedSet(classNames);
2042
- return new LiveNodeList(this, function (base) {
2043
- var ls = [];
2044
- if (classNamesSet.length > 0) {
2045
- _visitNode(base.documentElement, function (node) {
2046
- if (node !== base && node.nodeType === ELEMENT_NODE) {
2047
- var nodeClassNames = node.getAttribute('class');
2048
- // can be null if the attribute does not exist
2049
- if (nodeClassNames) {
2050
- // before splitting and iterating just compare them for the most common case
2051
- var matches = classNames === nodeClassNames;
2052
- if (!matches) {
2053
- var nodeClassNamesSet = toOrderedSet(nodeClassNames);
2054
- matches = classNamesSet.every(arrayIncludes(nodeClassNamesSet));
2055
- }
2056
- if (matches) {
2057
- ls.push(node);
2058
- }
2059
- }
2060
- }
2061
- });
2062
- }
2063
- return ls;
2064
- });
2065
- },
2066
-
2067
2006
  /**
2068
2007
  * Creates a new `Element` that is owned by this `Document`.
2069
2008
  * In HTML Documents `localName` is the lower cased `tagName`,
@@ -2206,6 +2145,12 @@ function Element(symbol) {
2206
2145
  }
2207
2146
  Element.prototype = {
2208
2147
  nodeType: ELEMENT_NODE,
2148
+ /**
2149
+ * The attributes of this element.
2150
+ *
2151
+ * @type {NamedNodeMap | null}
2152
+ */
2153
+ attributes: null,
2209
2154
  getQualifiedName: function () {
2210
2155
  return this.prefix ? this.prefix + ':' + this.localName : this.localName;
2211
2156
  },
@@ -2312,6 +2257,51 @@ Element.prototype = {
2312
2257
  return this.attributes.getNamedItemNS(namespaceURI, localName);
2313
2258
  },
2314
2259
 
2260
+ /**
2261
+ * Returns a LiveNodeList of all child elements which have **all** of the given class name(s).
2262
+ *
2263
+ * Returns an empty list if `classNames` is an empty string or only contains HTML white space
2264
+ * characters.
2265
+ *
2266
+ * Warning: This returns a live LiveNodeList.
2267
+ * Changes in the DOM will reflect in the array as the changes occur.
2268
+ * If an element selected by this array no longer qualifies for the selector,
2269
+ * it will automatically be removed. Be aware of this for iteration purposes.
2270
+ *
2271
+ * @param {string} classNames
2272
+ * Is a string representing the class name(s) to match; multiple class names are separated by
2273
+ * (ASCII-)whitespace.
2274
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByClassName
2275
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
2276
+ * @see https://dom.spec.whatwg.org/#concept-getelementsbyclassname
2277
+ */
2278
+ getElementsByClassName: function (classNames) {
2279
+ var classNamesSet = toOrderedSet(classNames);
2280
+ return new LiveNodeList(this, function (base) {
2281
+ var ls = [];
2282
+ if (classNamesSet.length > 0) {
2283
+ _visitNode(base, function (node) {
2284
+ if (node !== base && node.nodeType === ELEMENT_NODE) {
2285
+ var nodeClassNames = node.getAttribute('class');
2286
+ // can be null if the attribute does not exist
2287
+ if (nodeClassNames) {
2288
+ // before splitting and iterating just compare them for the most common case
2289
+ var matches = classNames === nodeClassNames;
2290
+ if (!matches) {
2291
+ var nodeClassNamesSet = toOrderedSet(nodeClassNames);
2292
+ matches = classNamesSet.every(arrayIncludes(nodeClassNamesSet));
2293
+ }
2294
+ if (matches) {
2295
+ ls.push(node);
2296
+ }
2297
+ }
2298
+ }
2299
+ });
2300
+ }
2301
+ return ls;
2302
+ });
2303
+ },
2304
+
2315
2305
  /**
2316
2306
  * Returns a LiveNodeList of elements with the given qualifiedName.
2317
2307
  * Searching for all descendants can be done by passing `*` as `qualifiedName`.
@@ -2375,6 +2365,7 @@ Element.prototype = {
2375
2365
  });
2376
2366
  },
2377
2367
  };
2368
+ Document.prototype.getElementsByClassName = Element.prototype.getElementsByClassName;
2378
2369
  Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
2379
2370
  Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
2380
2371
 
@@ -2453,7 +2444,7 @@ CDATASection.prototype = {
2453
2444
  nodeName: '#cdata-section',
2454
2445
  nodeType: CDATA_SECTION_NODE,
2455
2446
  };
2456
- _extends(CDATASection, CharacterData);
2447
+ _extends(CDATASection, Text);
2457
2448
 
2458
2449
  function DocumentType(symbol) {
2459
2450
  checkSymbol(symbol);
@@ -2930,5 +2921,5 @@ exports.Node = Node;
2930
2921
  exports.NodeList = NodeList;
2931
2922
  exports.Notation = Notation;
2932
2923
  exports.Text = Text;
2933
- exports.XMLSerializer = XMLSerializer;
2934
2924
  exports.ProcessingInstruction = ProcessingInstruction;
2925
+ exports.XMLSerializer = XMLSerializer;
package/lib/errors.js CHANGED
@@ -100,7 +100,7 @@ function endsWithError(value) {
100
100
  * passed when null was not expected.
101
101
  *
102
102
  * This implementation supports the following usages:
103
- * 1. according to the living standard (both arguments are mandatory):
103
+ * 1. according to the living standard (both arguments are optional):
104
104
  * ```
105
105
  * new DOMException("message (can be empty)", DOMExceptionNames.HierarchyRequestError)
106
106
  * ```
@@ -179,8 +179,7 @@ var ExceptionCode = {
179
179
  var entries = Object.entries(ExceptionCode);
180
180
  for (var i = 0; i < entries.length; i++) {
181
181
  var key = entries[i][0];
182
- var value = entries[i][1];
183
- DOMException[key] = value;
182
+ DOMException[key] = entries[i][1];
184
183
  }
185
184
 
186
185
  /**
@@ -189,18 +188,15 @@ for (var i = 0; i < entries.length; i++) {
189
188
  * @class
190
189
  * @param {string} message
191
190
  * @param {any} [locator]
192
- * @param {Error} [cause]
193
- * Optional, can provide details about the location in the source.
194
191
  */
195
- function ParseError(message, locator, cause) {
192
+ function ParseError(message, locator) {
196
193
  this.message = message;
197
194
  this.locator = locator;
198
- this.cause = cause;
199
195
  if (Error.captureStackTrace) Error.captureStackTrace(this, ParseError);
200
196
  }
201
197
  extendError(ParseError);
202
198
 
203
199
  exports.DOMException = DOMException;
204
200
  exports.DOMExceptionName = DOMExceptionName;
205
- exports.ParseError = ParseError;
206
201
  exports.ExceptionCode = ExceptionCode;
202
+ exports.ParseError = ParseError;
package/lib/index.js CHANGED
@@ -8,13 +8,12 @@ exports.MIME_TYPE = conventions.MIME_TYPE;
8
8
  exports.NAMESPACE = conventions.NAMESPACE;
9
9
 
10
10
  var errors = require('./errors');
11
- exports.ParseError = errors.ParseError;
12
11
  exports.DOMException = errors.DOMException;
12
+ exports.DOMExceptionName = errors.DOMExceptionName;
13
13
  exports.ExceptionCode = errors.ExceptionCode;
14
+ exports.ParseError = errors.ParseError;
14
15
 
15
16
  var dom = require('./dom');
16
- exports.DOMImplementation = dom.DOMImplementation;
17
- exports.XMLSerializer = dom.XMLSerializer;
18
17
  exports.Attr = dom.Attr;
19
18
  exports.CDATASection = dom.CDATASection;
20
19
  exports.CharacterData = dom.CharacterData;
@@ -22,15 +21,18 @@ exports.Comment = dom.Comment;
22
21
  exports.Document = dom.Document;
23
22
  exports.DocumentFragment = dom.DocumentFragment;
24
23
  exports.DocumentType = dom.DocumentType;
24
+ exports.DOMImplementation = dom.DOMImplementation;
25
25
  exports.Element = dom.Element;
26
- exports.EntityReference = dom.EntityReference;
27
26
  exports.Entity = dom.Entity;
27
+ exports.EntityReference = dom.EntityReference;
28
+ exports.LiveNodeList = dom.LiveNodeList;
28
29
  exports.NamedNodeMap = dom.NamedNodeMap;
29
30
  exports.Node = dom.Node;
30
31
  exports.NodeList = dom.NodeList;
31
32
  exports.Notation = dom.Notation;
32
33
  exports.ProcessingInstruction = dom.ProcessingInstruction;
33
34
  exports.Text = dom.Text;
35
+ exports.XMLSerializer = dom.XMLSerializer;
34
36
 
35
37
  var domParser = require('./dom-parser');
36
38
  exports.DOMParser = domParser.DOMParser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmldom/xmldom",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
5
  "keywords": [
6
6
  "w3c",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "lint": "eslint examples lib test",
32
- "format": "prettier --write examples lib test",
32
+ "format": "prettier --write examples lib test index.d.ts",
33
33
  "changelog": "auto-changelog --unreleased-only",
34
34
  "start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test && npm --silent run lint'",
35
35
  "test": "jest",
@@ -40,7 +40,7 @@
40
40
  "release": "np --no-yarn --test-script testrelease"
41
41
  },
42
42
  "engines": {
43
- "node": ">=10.0.0"
43
+ "node": ">=14.0.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@homer0/prettier-plugin-jsdoc": "9.0.2",
@@ -59,8 +59,8 @@
59
59
  "np": "8.0.4",
60
60
  "prettier": "3.3.3",
61
61
  "rxjs": "7.8.1",
62
- "xmltest": "1.5.0",
63
- "yauzl": "2.10.0"
62
+ "xmltest": "2.0.1",
63
+ "yauzl": "3.1.3"
64
64
  },
65
65
  "bugs": {
66
66
  "url": "https://github.com/xmldom/xmldom/issues"