@xmldom/xmldom 0.7.7 → 0.7.8

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
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.7.8](https://github.com/xmldom/xmldom/compare/0.7.7...0.7.8)
8
+
9
+ ### Fixed
10
+
11
+ - fix: Restore ES5 compatibility [`#452`](https://github.com/xmldom/xmldom/pull/452) / [`#453`](https://github.com/xmldom/xmldom/issues/453)
12
+
13
+ Thank you, [@fengxinming](https://github.com/fengxinming), for your contributions
14
+
15
+
6
16
  ## [0.7.7](https://github.com/xmldom/xmldom/compare/0.7.6...0.7.7)
7
17
 
8
18
  ### Fixed
@@ -1,5 +1,37 @@
1
1
  'use strict'
2
2
 
3
+ /**
4
+ * Ponyfill for `Array.prototype.find` which is only available in ES6 runtimes.
5
+ *
6
+ * Works with anything that has a `length` property and index access properties, including NodeList.
7
+ *
8
+ * @template {unknown} T
9
+ * @param {Array<T> | ({length:number, [number]: T})} list
10
+ * @param {function (item: T, index: number, list:Array<T> | ({length:number, [number]: T})):boolean} predicate
11
+ * @param {Partial<Pick<ArrayConstructor['prototype'], 'find'>>?} ac `Array.prototype` by default,
12
+ * allows injecting a custom implementation in tests
13
+ * @returns {T | undefined}
14
+ *
15
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
16
+ * @see https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.find
17
+ */
18
+ function find(list, predicate, ac) {
19
+ if (ac === undefined) {
20
+ ac = Array.prototype;
21
+ }
22
+ if (list && typeof ac.find === 'function') {
23
+ return ac.find.call(list, predicate);
24
+ }
25
+ for (var i = 0; i < list.length; i++) {
26
+ if (Object.prototype.hasOwnProperty.call(list, i)) {
27
+ var item = list[i];
28
+ if (predicate.call(undefined, item, i, list)) {
29
+ return item;
30
+ }
31
+ }
32
+ }
33
+ }
34
+
3
35
  /**
4
36
  * "Shallow freezes" an object to render it immutable.
5
37
  * Uses `Object.freeze` if available,
@@ -139,6 +171,7 @@ var NAMESPACE = freeze({
139
171
  XMLNS: 'http://www.w3.org/2000/xmlns/',
140
172
  })
141
173
 
174
+ exports.find = find;
142
175
  exports.freeze = freeze;
143
176
  exports.MIME_TYPE = MIME_TYPE;
144
177
  exports.NAMESPACE = NAMESPACE;
package/lib/dom.js CHANGED
@@ -1,5 +1,6 @@
1
1
  var conventions = require("./conventions");
2
2
 
3
+ var find = conventions.find;
3
4
  var NAMESPACE = conventions.NAMESPACE;
4
5
 
5
6
  /**
@@ -176,14 +177,6 @@ NodeList.prototype = {
176
177
  }
177
178
  return buf.join('');
178
179
  },
179
- /**
180
- * @private
181
- * @param {function (Node):boolean} predicate
182
- * @returns {Node | undefined}
183
- */
184
- find: function (predicate) {
185
- return Array.prototype.find.call(this, predicate);
186
- },
187
180
  /**
188
181
  * @private
189
182
  * @param {function (Node):boolean} predicate
@@ -731,10 +724,10 @@ function isTextNode(node) {
731
724
  */
732
725
  function isElementInsertionPossible(doc, child) {
733
726
  var parentChildNodes = doc.childNodes || [];
734
- if (parentChildNodes.find(isElementNode) || isDocTypeNode(child)) {
727
+ if (find(parentChildNodes, isElementNode) || isDocTypeNode(child)) {
735
728
  return false;
736
729
  }
737
- var docTypeNode = parentChildNodes.find(isDocTypeNode);
730
+ var docTypeNode = find(parentChildNodes, isDocTypeNode);
738
731
  return !(child && docTypeNode && parentChildNodes.indexOf(docTypeNode) > parentChildNodes.indexOf(child));
739
732
  }
740
733
  /**
@@ -769,8 +762,8 @@ function _insertBefore(parent, node, child) {
769
762
  var nodeChildNodes = node.childNodes || [];
770
763
  if (parent.nodeType === Node.DOCUMENT_NODE) {
771
764
  if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
772
- let nodeChildElements = nodeChildNodes.filter(isElementNode);
773
- if (nodeChildElements.length > 1 || nodeChildNodes.find(isTextNode)) {
765
+ var nodeChildElements = nodeChildNodes.filter(isElementNode);
766
+ if (nodeChildElements.length > 1 || find(nodeChildNodes, isTextNode)) {
774
767
  throw new DOMException(HIERARCHY_REQUEST_ERR, 'More than one element or text in fragment');
775
768
  }
776
769
  if (nodeChildElements.length === 1 && !isElementInsertionPossible(parent, child)) {
@@ -778,15 +771,15 @@ function _insertBefore(parent, node, child) {
778
771
  }
779
772
  }
780
773
  if (isElementNode(node)) {
781
- if (parentChildNodes.find(isElementNode) || !isElementInsertionPossible(parent, child)) {
774
+ if (find(parentChildNodes, isElementNode) || !isElementInsertionPossible(parent, child)) {
782
775
  throw new DOMException(HIERARCHY_REQUEST_ERR, 'Only one element can be added and only after doctype');
783
776
  }
784
777
  }
785
778
  if (isDocTypeNode(node)) {
786
- if (parentChildNodes.find(isDocTypeNode)) {
779
+ if (find(parentChildNodes, isDocTypeNode)) {
787
780
  throw new DOMException(HIERARCHY_REQUEST_ERR, 'Only one doctype is allowed');
788
781
  }
789
- let parentElementChild = parentChildNodes.find(isElementNode);
782
+ var parentElementChild = find(parentChildNodes, isElementNode);
790
783
  if (child && parentChildNodes.indexOf(parentElementChild) < parentChildNodes.indexOf(child)) {
791
784
  throw new DOMException(HIERARCHY_REQUEST_ERR, 'Doctype can only be inserted before an element');
792
785
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmldom/xmldom",
3
- "version": "0.7.7",
3
+ "version": "0.7.8",
4
4
  "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
5
  "keywords": [
6
6
  "w3c",
@@ -31,7 +31,9 @@
31
31
  "start": "nodemon --watch package.json --watch lib --watch test --exec 'npm --silent run test && npm --silent run lint'",
32
32
  "stryker": "stryker run",
33
33
  "stryker:dry-run": "stryker run -m '' --reporters progress",
34
- "test": "jest"
34
+ "test": "jest",
35
+ "testrelease": "npm test && eslint lib",
36
+ "release": "np --no-yarn --test-script testrelease --branch release-0.7.x --tag lts"
35
37
  },
36
38
  "engines": {
37
39
  "node": ">=10.0.0"
@@ -46,6 +48,7 @@
46
48
  "get-stream": "^6.0.1",
47
49
  "jest": "^27.0.6",
48
50
  "nodemon": "^2.0.12",
51
+ "np": "7.6.2",
49
52
  "prettier": "^2.3.2",
50
53
  "xmltest": "^1.5.0",
51
54
  "yauzl": "^2.10.0"