Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-dom-parser

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-dom-parser - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

4

CHANGELOG.md

@@ -1,5 +0,7 @@

# Change Log
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [1.0.1](https://github.com/remarkablemark/html-dom-parser/compare/v1.0.0...v1.0.1) (2021-06-13)
# [1.0.0](https://github.com/remarkablemark/html-dom-parser/compare/v0.5.0...v1.0.0) (2020-12-25)

@@ -6,0 +8,0 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HTMLDOMParser = factory());
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HTMLDOMParser = factory());
}(this, (function () { 'use strict';
/**
* SVG elements are case-sensitive.
*
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#SVG_elements_A_to_Z}
*/
var CASE_SENSITIVE_TAG_NAMES = [
'animateMotion',
'animateTransform',
'clipPath',
'feBlend',
'feColorMatrix',
'feComponentTransfer',
'feComposite',
'feConvolveMatrix',
'feDiffuseLighting',
'feDisplacementMap',
'feDropShadow',
'feFlood',
'feFuncA',
'feFuncB',
'feFuncG',
'feFuncR',
'feGaussainBlur',
'feImage',
'feMerge',
'feMergeNode',
'feMorphology',
'feOffset',
'fePointLight',
'feSpecularLighting',
'feSpotLight',
'feTile',
'feTurbulence',
'foreignObject',
'linearGradient',
'radialGradient',
'textPath'
];
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
var constants = {
CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES
};
/**
* SVG elements are case-sensitive.
*
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#SVG_elements_A_to_Z}
*/
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
var CASE_SENSITIVE_TAG_NAMES$1 = [
'animateMotion',
'animateTransform',
'clipPath',
'feBlend',
'feColorMatrix',
'feComponentTransfer',
'feComposite',
'feConvolveMatrix',
'feDiffuseLighting',
'feDisplacementMap',
'feDropShadow',
'feFlood',
'feFuncA',
'feFuncB',
'feFuncG',
'feFuncR',
'feGaussainBlur',
'feImage',
'feMerge',
'feMergeNode',
'feMorphology',
'feOffset',
'fePointLight',
'feSpecularLighting',
'feSpotLight',
'feTile',
'feTurbulence',
'foreignObject',
'linearGradient',
'radialGradient',
'textPath'
];
function createCommonjsModule(fn) {
var module = { exports: {} };
return fn(module, module.exports), module.exports;
}
var constants$1 = {
CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES$1
};
var node = createCommonjsModule(function (module, exports) {
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloneNode = exports.Element = exports.Document = exports.NodeWithChildren = exports.ProcessingInstruction = exports.Comment = exports.Text = exports.DataNode = exports.Node = void 0;
var nodeTypes = new Map([
["tag" /* Tag */, 1],
["script" /* Script */, 1],
["style" /* Style */, 1],
["directive" /* Directive */, 1],
["text" /* Text */, 3],
["cdata" /* CDATA */, 4],
["comment" /* Comment */, 8],
["root" /* Root */, 9],
]);
/**
* This object will be used as the prototype for Nodes when creating a
* DOM-Level-1-compliant structure.
*/
var Node = /** @class */ (function () {
/**
*
* @param type The type of the node.
*/
function Node(type) {
this.type = type;
/** Parent of the node */
this.parent = null;
/** Previous sibling */
this.prev = null;
/** Next sibling */
this.next = null;
/** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
this.startIndex = null;
/** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
this.endIndex = null;
}
Object.defineProperty(Node.prototype, "nodeType", {
// Read-only aliases
get: function () {
var _a;
return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Node.prototype, "parentNode", {
// Read-write aliases for properties
get: function () {
return this.parent;
},
set: function (parent) {
this.parent = parent;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Node.prototype, "previousSibling", {
get: function () {
return this.prev;
},
set: function (prev) {
this.prev = prev;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Node.prototype, "nextSibling", {
get: function () {
return this.next;
},
set: function (next) {
this.next = next;
},
enumerable: false,
configurable: true
});
/**
* Clone this node, and optionally its children.
*
* @param recursive Clone child nodes as well.
* @returns A clone of the node.
*/
Node.prototype.cloneNode = function (recursive) {
if (recursive === void 0) { recursive = false; }
return cloneNode(this, recursive);
};
return Node;
}());
exports.Node = Node;
var DataNode = /** @class */ (function (_super) {
__extends(DataNode, _super);
/**
* @param type The type of the node
* @param data The content of the data node
*/
function DataNode(type, data) {
var _this = _super.call(this, type) || this;
_this.data = data;
return _this;
}
Object.defineProperty(DataNode.prototype, "nodeValue", {
get: function () {
return this.data;
},
set: function (data) {
this.data = data;
},
enumerable: false,
configurable: true
});
return DataNode;
}(Node));
exports.DataNode = DataNode;
var Text = /** @class */ (function (_super) {
__extends(Text, _super);
function Text(data) {
return _super.call(this, "text" /* Text */, data) || this;
}
return Text;
}(DataNode));
exports.Text = Text;
var Comment = /** @class */ (function (_super) {
__extends(Comment, _super);
function Comment(data) {
return _super.call(this, "comment" /* Comment */, data) || this;
}
return Comment;
}(DataNode));
exports.Comment = Comment;
var ProcessingInstruction = /** @class */ (function (_super) {
__extends(ProcessingInstruction, _super);
function ProcessingInstruction(name, data) {
var _this = _super.call(this, "directive" /* Directive */, data) || this;
_this.name = name;
return _this;
}
return ProcessingInstruction;
}(DataNode));
exports.ProcessingInstruction = ProcessingInstruction;
/**
* A `Node` that can have children.
*/
var NodeWithChildren = /** @class */ (function (_super) {
__extends(NodeWithChildren, _super);
/**
* @param type Type of the node.
* @param children Children of the node. Only certain node types can have children.
*/
function NodeWithChildren(type, children) {
var _this = _super.call(this, type) || this;
_this.children = children;
return _this;
}
Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
// Aliases
get: function () {
var _a;
return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
get: function () {
return this.children.length > 0
? this.children[this.children.length - 1]
: null;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
get: function () {
return this.children;
},
set: function (children) {
this.children = children;
},
enumerable: false,
configurable: true
});
return NodeWithChildren;
}(Node));
exports.NodeWithChildren = NodeWithChildren;
var Document = /** @class */ (function (_super) {
__extends(Document, _super);
function Document(children) {
return _super.call(this, "root" /* Root */, children) || this;
}
return Document;
}(NodeWithChildren));
exports.Document = Document;
var Element = /** @class */ (function (_super) {
__extends(Element, _super);
/**
* @param name Name of the tag, eg. `div`, `span`.
* @param attribs Object mapping attribute names to attribute values.
* @param children Children of the node.
*/
function Element(name, attribs, children) {
if (children === void 0) { children = []; }
var _this = _super.call(this, name === "script"
? "script" /* Script */
: name === "style"
? "style" /* Style */
: "tag" /* Tag */, children) || this;
_this.name = name;
_this.attribs = attribs;
_this.attribs = attribs;
return _this;
}
Object.defineProperty(Element.prototype, "tagName", {
// DOM Level 1 aliases
get: function () {
return this.name;
},
set: function (name) {
this.name = name;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Element.prototype, "attributes", {
get: function () {
var _this = this;
return Object.keys(this.attribs).map(function (name) {
var _a, _b;
return ({
name: name,
value: _this.attribs[name],
namespace: (_a = _this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
prefix: (_b = _this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name],
});
});
},
enumerable: false,
configurable: true
});
return Element;
}(NodeWithChildren));
exports.Element = Element;
/**
* Clone a node, and optionally its children.
*
* @param recursive Clone child nodes as well.
* @returns A clone of the node.
*/
function cloneNode(node, recursive) {
if (recursive === void 0) { recursive = false; }
var result;
switch (node.type) {
case "text" /* Text */:
result = new Text(node.data);
break;
case "directive" /* Directive */: {
var instr = node;
result = new ProcessingInstruction(instr.name, instr.data);
if (instr["x-name"] != null) {
result["x-name"] = instr["x-name"];
result["x-publicId"] = instr["x-publicId"];
result["x-systemId"] = instr["x-systemId"];
}
break;
}
case "comment" /* Comment */:
result = new Comment(node.data);
break;
case "tag" /* Tag */:
case "script" /* Script */:
case "style" /* Style */: {
var elem = node;
var children = recursive ? cloneChildren(elem.children) : [];
var clone_1 = new Element(elem.name, __assign({}, elem.attribs), children);
children.forEach(function (child) { return (child.parent = clone_1); });
if (elem["x-attribsNamespace"]) {
clone_1["x-attribsNamespace"] = __assign({}, elem["x-attribsNamespace"]);
}
if (elem["x-attribsPrefix"]) {
clone_1["x-attribsPrefix"] = __assign({}, elem["x-attribsPrefix"]);
}
result = clone_1;
break;
}
case "cdata" /* CDATA */: {
var cdata = node;
var children = recursive ? cloneChildren(cdata.children) : [];
var clone_2 = new NodeWithChildren(node.type, children);
children.forEach(function (child) { return (child.parent = clone_2); });
result = clone_2;
break;
}
case "root" /* Root */: {
var doc = node;
var children = recursive ? cloneChildren(doc.children) : [];
var clone_3 = new Document(children);
children.forEach(function (child) { return (child.parent = clone_3); });
if (doc["x-mode"]) {
clone_3["x-mode"] = doc["x-mode"];
}
result = clone_3;
break;
}
case "doctype" /* Doctype */: {
// This type isn't used yet.
throw new Error("Not implemented yet: ElementType.Doctype case");
}
}
result.startIndex = node.startIndex;
result.endIndex = node.endIndex;
return result;
}
exports.cloneNode = cloneNode;
function cloneChildren(childs) {
var children = childs.map(function (child) { return cloneNode(child, true); });
for (var i = 1; i < children.length; i++) {
children[i].prev = children[i - 1];
children[i - 1].next = children[i];
}
return children;
}
});
var node = {};
var CASE_SENSITIVE_TAG_NAMES$1 = constants.CASE_SENSITIVE_TAG_NAMES;
var lib = {};
var Comment = node.Comment;
var Element = node.Element;
var ProcessingInstruction = node.ProcessingInstruction;
var Text = node.Text;
(function (exports) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.Doctype = exports.CDATA = exports.Tag = exports.Style = exports.Script = exports.Comment = exports.Directive = exports.Text = exports.Root = exports.isTag = exports.ElementType = void 0;
/** Types of elements found in htmlparser2's DOM */
var ElementType;
(function (ElementType) {
/** Type for the root element of a document */
ElementType["Root"] = "root";
/** Type for Text */
ElementType["Text"] = "text";
/** Type for <? ... ?> */
ElementType["Directive"] = "directive";
/** Type for <!-- ... --> */
ElementType["Comment"] = "comment";
/** Type for <script> tags */
ElementType["Script"] = "script";
/** Type for <style> tags */
ElementType["Style"] = "style";
/** Type for Any tag */
ElementType["Tag"] = "tag";
/** Type for <![CDATA[ ... ]]> */
ElementType["CDATA"] = "cdata";
/** Type for <!doctype ...> */
ElementType["Doctype"] = "doctype";
})(ElementType = exports.ElementType || (exports.ElementType = {}));
/**
* Tests whether an element is a tag or not.
*
* @param elem Element to test
*/
function isTag(elem) {
return (elem.type === ElementType.Tag ||
elem.type === ElementType.Script ||
elem.type === ElementType.Style);
}
exports.isTag = isTag;
// Exports for backwards compatibility
/** Type for the root element of a document */
exports.Root = ElementType.Root;
/** Type for Text */
exports.Text = ElementType.Text;
/** Type for <? ... ?> */
exports.Directive = ElementType.Directive;
/** Type for <!-- ... --> */
exports.Comment = ElementType.Comment;
/** Type for <script> tags */
exports.Script = ElementType.Script;
/** Type for <style> tags */
exports.Style = ElementType.Style;
/** Type for Any tag */
exports.Tag = ElementType.Tag;
/** Type for <![CDATA[ ... ]]> */
exports.CDATA = ElementType.CDATA;
/** Type for <!doctype ...> */
exports.Doctype = ElementType.Doctype;
}(lib));
var caseSensitiveTagNamesMap = {};
var tagName;
var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(node, "__esModule", { value: true });
node.cloneNode = node.hasChildren = node.isDocument = node.isDirective = node.isComment = node.isText = node.isCDATA = node.isTag = node.Element = node.Document = node.NodeWithChildren = node.ProcessingInstruction = node.Comment = node.Text = node.DataNode = node.Node = void 0;
var domelementtype_1 = lib;
var nodeTypes = new Map([
[domelementtype_1.ElementType.Tag, 1],
[domelementtype_1.ElementType.Script, 1],
[domelementtype_1.ElementType.Style, 1],
[domelementtype_1.ElementType.Directive, 1],
[domelementtype_1.ElementType.Text, 3],
[domelementtype_1.ElementType.CDATA, 4],
[domelementtype_1.ElementType.Comment, 8],
[domelementtype_1.ElementType.Root, 9],
]);
/**
* This object will be used as the prototype for Nodes when creating a
* DOM-Level-1-compliant structure.
*/
var Node = /** @class */ (function () {
/**
*
* @param type The type of the node.
*/
function Node(type) {
this.type = type;
/** Parent of the node */
this.parent = null;
/** Previous sibling */
this.prev = null;
/** Next sibling */
this.next = null;
/** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
this.startIndex = null;
/** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
this.endIndex = null;
}
Object.defineProperty(Node.prototype, "nodeType", {
// Read-only aliases
get: function () {
var _a;
return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Node.prototype, "parentNode", {
// Read-write aliases for properties
get: function () {
return this.parent;
},
set: function (parent) {
this.parent = parent;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Node.prototype, "previousSibling", {
get: function () {
return this.prev;
},
set: function (prev) {
this.prev = prev;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Node.prototype, "nextSibling", {
get: function () {
return this.next;
},
set: function (next) {
this.next = next;
},
enumerable: false,
configurable: true
});
/**
* Clone this node, and optionally its children.
*
* @param recursive Clone child nodes as well.
* @returns A clone of the node.
*/
Node.prototype.cloneNode = function (recursive) {
if (recursive === void 0) { recursive = false; }
return cloneNode(this, recursive);
};
return Node;
}());
node.Node = Node;
var DataNode = /** @class */ (function (_super) {
__extends(DataNode, _super);
/**
* @param type The type of the node
* @param data The content of the data node
*/
function DataNode(type, data) {
var _this = _super.call(this, type) || this;
_this.data = data;
return _this;
}
Object.defineProperty(DataNode.prototype, "nodeValue", {
get: function () {
return this.data;
},
set: function (data) {
this.data = data;
},
enumerable: false,
configurable: true
});
return DataNode;
}(Node));
node.DataNode = DataNode;
var Text$1 = /** @class */ (function (_super) {
__extends(Text, _super);
function Text(data) {
return _super.call(this, domelementtype_1.ElementType.Text, data) || this;
}
return Text;
}(DataNode));
node.Text = Text$1;
var Comment$1 = /** @class */ (function (_super) {
__extends(Comment, _super);
function Comment(data) {
return _super.call(this, domelementtype_1.ElementType.Comment, data) || this;
}
return Comment;
}(DataNode));
node.Comment = Comment$1;
var ProcessingInstruction$1 = /** @class */ (function (_super) {
__extends(ProcessingInstruction, _super);
function ProcessingInstruction(name, data) {
var _this = _super.call(this, domelementtype_1.ElementType.Directive, data) || this;
_this.name = name;
return _this;
}
return ProcessingInstruction;
}(DataNode));
node.ProcessingInstruction = ProcessingInstruction$1;
/**
* A `Node` that can have children.
*/
var NodeWithChildren = /** @class */ (function (_super) {
__extends(NodeWithChildren, _super);
/**
* @param type Type of the node.
* @param children Children of the node. Only certain node types can have children.
*/
function NodeWithChildren(type, children) {
var _this = _super.call(this, type) || this;
_this.children = children;
return _this;
}
Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
// Aliases
get: function () {
var _a;
return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
get: function () {
return this.children.length > 0
? this.children[this.children.length - 1]
: null;
},
enumerable: false,
configurable: true
});
Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
get: function () {
return this.children;
},
set: function (children) {
this.children = children;
},
enumerable: false,
configurable: true
});
return NodeWithChildren;
}(Node));
node.NodeWithChildren = NodeWithChildren;
var Document = /** @class */ (function (_super) {
__extends(Document, _super);
function Document(children) {
return _super.call(this, domelementtype_1.ElementType.Root, children) || this;
}
return Document;
}(NodeWithChildren));
node.Document = Document;
var Element$1 = /** @class */ (function (_super) {
__extends(Element, _super);
/**
* @param name Name of the tag, eg. `div`, `span`.
* @param attribs Object mapping attribute names to attribute values.
* @param children Children of the node.
*/
function Element(name, attribs, children, type) {
if (children === void 0) { children = []; }
if (type === void 0) { type = name === "script"
? domelementtype_1.ElementType.Script
: name === "style"
? domelementtype_1.ElementType.Style
: domelementtype_1.ElementType.Tag; }
var _this = _super.call(this, type, children) || this;
_this.name = name;
_this.attribs = attribs;
return _this;
}
Object.defineProperty(Element.prototype, "tagName", {
// DOM Level 1 aliases
get: function () {
return this.name;
},
set: function (name) {
this.name = name;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Element.prototype, "attributes", {
get: function () {
var _this = this;
return Object.keys(this.attribs).map(function (name) {
var _a, _b;
return ({
name: name,
value: _this.attribs[name],
namespace: (_a = _this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
prefix: (_b = _this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name],
});
});
},
enumerable: false,
configurable: true
});
return Element;
}(NodeWithChildren));
node.Element = Element$1;
/**
* @param node Node to check.
* @returns `true` if the node is a `Element`, `false` otherwise.
*/
function isTag(node) {
return domelementtype_1.isTag(node);
}
node.isTag = isTag;
/**
* @param node Node to check.
* @returns `true` if the node has the type `CDATA`, `false` otherwise.
*/
function isCDATA(node) {
return node.type === domelementtype_1.ElementType.CDATA;
}
node.isCDATA = isCDATA;
/**
* @param node Node to check.
* @returns `true` if the node has the type `Text`, `false` otherwise.
*/
function isText(node) {
return node.type === domelementtype_1.ElementType.Text;
}
node.isText = isText;
/**
* @param node Node to check.
* @returns `true` if the node has the type `Comment`, `false` otherwise.
*/
function isComment(node) {
return node.type === domelementtype_1.ElementType.Comment;
}
node.isComment = isComment;
/**
* @param node Node to check.
* @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
*/
function isDirective(node) {
return node.type === domelementtype_1.ElementType.Directive;
}
node.isDirective = isDirective;
/**
* @param node Node to check.
* @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
*/
function isDocument(node) {
return node.type === domelementtype_1.ElementType.Root;
}
node.isDocument = isDocument;
/**
* @param node Node to check.
* @returns `true` if the node is a `NodeWithChildren` (has children), `false` otherwise.
*/
function hasChildren(node) {
return Object.prototype.hasOwnProperty.call(node, "children");
}
node.hasChildren = hasChildren;
/**
* Clone a node, and optionally its children.
*
* @param recursive Clone child nodes as well.
* @returns A clone of the node.
*/
function cloneNode(node, recursive) {
if (recursive === void 0) { recursive = false; }
var result;
if (isText(node)) {
result = new Text$1(node.data);
}
else if (isComment(node)) {
result = new Comment$1(node.data);
}
else if (isTag(node)) {
var children = recursive ? cloneChildren(node.children) : [];
var clone_1 = new Element$1(node.name, __assign({}, node.attribs), children);
children.forEach(function (child) { return (child.parent = clone_1); });
if (node["x-attribsNamespace"]) {
clone_1["x-attribsNamespace"] = __assign({}, node["x-attribsNamespace"]);
}
if (node["x-attribsPrefix"]) {
clone_1["x-attribsPrefix"] = __assign({}, node["x-attribsPrefix"]);
}
result = clone_1;
}
else if (isCDATA(node)) {
var children = recursive ? cloneChildren(node.children) : [];
var clone_2 = new NodeWithChildren(domelementtype_1.ElementType.CDATA, children);
children.forEach(function (child) { return (child.parent = clone_2); });
result = clone_2;
}
else if (isDocument(node)) {
var children = recursive ? cloneChildren(node.children) : [];
var clone_3 = new Document(children);
children.forEach(function (child) { return (child.parent = clone_3); });
if (node["x-mode"]) {
clone_3["x-mode"] = node["x-mode"];
}
result = clone_3;
}
else if (isDirective(node)) {
var instruction = new ProcessingInstruction$1(node.name, node.data);
if (node["x-name"] != null) {
instruction["x-name"] = node["x-name"];
instruction["x-publicId"] = node["x-publicId"];
instruction["x-systemId"] = node["x-systemId"];
}
result = instruction;
}
else {
throw new Error("Not implemented yet: " + node.type);
}
result.startIndex = node.startIndex;
result.endIndex = node.endIndex;
return result;
}
node.cloneNode = cloneNode;
function cloneChildren(childs) {
var children = childs.map(function (child) { return cloneNode(child, true); });
for (var i = 1; i < children.length; i++) {
children[i].prev = children[i - 1];
children[i - 1].next = children[i];
}
return children;
}
for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES$1.length; i < len; i++) {
tagName = CASE_SENSITIVE_TAG_NAMES$1[i];
caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
}
var constants = constants$1;
var domhandler = node;
/**
* Gets case-sensitive tag name.
*
* @param {string} tagName - Tag name in lowercase.
* @return {string|undefined} - Case-sensitive tag name.
*/
function getCaseSensitiveTagName(tagName) {
return caseSensitiveTagNamesMap[tagName];
}
var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;
/**
* Formats DOM attributes to a hash map.
*
* @param {NamedNodeMap} attributes - List of attributes.
* @return {object} - Map of attribute name to value.
*/
function formatAttributes(attributes) {
var result = {};
var attribute;
// `NamedNodeMap` is array-like
for (var i = 0, len = attributes.length; i < len; i++) {
attribute = attributes[i];
result[attribute.name] = attribute.value;
}
return result;
}
var Comment = domhandler.Comment;
var Element = domhandler.Element;
var ProcessingInstruction = domhandler.ProcessingInstruction;
var Text = domhandler.Text;
/**
* Corrects the tag name if it is case-sensitive (SVG).
* Otherwise, returns the lowercase tag name (HTML).
*
* @param {string} tagName - Lowercase tag name.
* @return {string} - Formatted tag name.
*/
function formatTagName(tagName) {
tagName = tagName.toLowerCase();
var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
if (caseSensitiveTagName) {
return caseSensitiveTagName;
}
return tagName;
}
var caseSensitiveTagNamesMap = {};
var tagName;
/**
* Transforms DOM nodes to `domhandler` nodes.
*
* @param {NodeList} nodes - DOM nodes.
* @param {Element|null} [parent=null] - Parent node.
* @param {string} [directive] - Directive.
* @return {Array<Comment|Element|ProcessingInstruction|Text>}
*/
function formatDOM(nodes, parent, directive) {
parent = parent || null;
var result = [];
for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES.length; i < len; i++) {
tagName = CASE_SENSITIVE_TAG_NAMES[i];
caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
}
for (var index = 0, len = nodes.length; index < len; index++) {
var node = nodes[index];
var current;
/**
* Gets case-sensitive tag name.
*
* @param {string} tagName - Tag name in lowercase.
* @return {string|undefined} - Case-sensitive tag name.
*/
function getCaseSensitiveTagName(tagName) {
return caseSensitiveTagNamesMap[tagName];
}
// set the node data given the type
switch (node.nodeType) {
case 1:
// script, style, or tag
current = new Element(
formatTagName(node.nodeName),
formatAttributes(node.attributes)
);
current.children = formatDOM(node.childNodes, current);
break;
/**
* Formats DOM attributes to a hash map.
*
* @param {NamedNodeMap} attributes - List of attributes.
* @return {object} - Map of attribute name to value.
*/
function formatAttributes(attributes) {
var result = {};
var attribute;
// `NamedNodeMap` is array-like
for (var i = 0, len = attributes.length; i < len; i++) {
attribute = attributes[i];
result[attribute.name] = attribute.value;
}
return result;
}
case 3:
current = new Text(node.nodeValue);
break;
/**
* Corrects the tag name if it is case-sensitive (SVG).
* Otherwise, returns the lowercase tag name (HTML).
*
* @param {string} tagName - Lowercase tag name.
* @return {string} - Formatted tag name.
*/
function formatTagName(tagName) {
tagName = tagName.toLowerCase();
var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
if (caseSensitiveTagName) {
return caseSensitiveTagName;
}
return tagName;
}
case 8:
current = new Comment(node.nodeValue);
break;
/**
* Transforms DOM nodes to `domhandler` nodes.
*
* @param {NodeList} nodes - DOM nodes.
* @param {Element|null} [parent=null] - Parent node.
* @param {string} [directive] - Directive.
* @return {Array<Comment|Element|ProcessingInstruction|Text>}
*/
function formatDOM$1(nodes, parent, directive) {
parent = parent || null;
var result = [];
default:
continue;
}
for (var index = 0, len = nodes.length; index < len; index++) {
var node = nodes[index];
var current;
// set previous node next
var prev = result[index - 1] || null;
if (prev) {
prev.next = current;
}
// set the node data given the type
switch (node.nodeType) {
case 1:
// script, style, or tag
current = new Element(
formatTagName(node.nodeName),
formatAttributes(node.attributes)
);
current.children = formatDOM$1(node.childNodes, current);
break;
// set properties for current node
current.parent = parent;
current.prev = prev;
current.next = null;
case 3:
current = new Text(node.nodeValue);
break;
result.push(current);
}
case 8:
current = new Comment(node.nodeValue);
break;
if (directive) {
current = new ProcessingInstruction(
directive.substring(0, directive.indexOf(' ')).toLowerCase(),
directive
);
current.next = result[0] || null;
current.parent = parent;
result.unshift(current);
default:
continue;
}
if (result[1]) {
result[1].prev = result[0];
}
}
// set previous node next
var prev = result[index - 1] || null;
if (prev) {
prev.next = current;
}
return result;
}
// set properties for current node
current.parent = parent;
current.prev = prev;
current.next = null;
/**
* Detects if browser is Internet Explorer.
*
* @return {boolean} - Whether IE is detected.
*/
function isIE() {
return /(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent);
}
result.push(current);
}
var utilities = {
formatAttributes: formatAttributes,
formatDOM: formatDOM,
isIE: isIE
};
if (directive) {
current = new ProcessingInstruction(
directive.substring(0, directive.indexOf(' ')).toLowerCase(),
directive
);
current.next = result[0] || null;
current.parent = parent;
result.unshift(current);
// constants
var HTML = 'html';
var HEAD = 'head';
var BODY = 'body';
var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
var HEAD_TAG_REGEX = /<head.*>/i;
var BODY_TAG_REGEX = /<body.*>/i;
if (result[1]) {
result[1].prev = result[0];
}
}
// falls back to `parseFromString` if `createHTMLDocument` cannot be used
var parseFromDocument = function () {
throw new Error(
'This browser does not support `document.implementation.createHTMLDocument`'
);
};
return result;
}
var parseFromString = function () {
throw new Error(
'This browser does not support `DOMParser.prototype.parseFromString`'
);
};
/**
* Detects if browser is Internet Explorer.
*
* @return {boolean} - Whether IE is detected.
*/
function isIE$1() {
return /(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent);
}
/**
* DOMParser (performance: slow).
*
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
*/
if (typeof window.DOMParser === 'function') {
var domParser = new window.DOMParser();
var mimeType = 'text/html';
var utilities = {
formatAttributes: formatAttributes,
formatDOM: formatDOM$1,
isIE: isIE$1
};
/**
* Creates an HTML document using `DOMParser.parseFromString`.
*
* @param {string} html - The HTML string.
* @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
* @return {HTMLDocument}
*/
parseFromString = function (html, tagName) {
if (tagName) {
html = '<' + tagName + '>' + html + '</' + tagName + '>';
}
// constants
var HTML = 'html';
var HEAD = 'head';
var BODY = 'body';
var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
var HEAD_TAG_REGEX = /<head.*>/i;
var BODY_TAG_REGEX = /<body.*>/i;
return domParser.parseFromString(html, mimeType);
};
// falls back to `parseFromString` if `createHTMLDocument` cannot be used
var parseFromDocument = function () {
throw new Error(
'This browser does not support `document.implementation.createHTMLDocument`'
);
};
parseFromDocument = parseFromString;
}
var parseFromString = function () {
throw new Error(
'This browser does not support `DOMParser.prototype.parseFromString`'
);
};
/**
* DOMImplementation (performance: fair).
*
* @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
*/
if (document.implementation) {
var isIE$1 = utilities.isIE;
/**
* DOMParser (performance: slow).
*
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
*/
if (typeof window.DOMParser === 'function') {
var domParser = new window.DOMParser();
var mimeType = 'text/html';
// title parameter is required in IE
// https://msdn.microsoft.com/en-us/library/ff975457(v=vs.85).aspx
var doc = document.implementation.createHTMLDocument(
isIE$1() ? 'html-dom-parser' : undefined
);
/**
* Creates an HTML document using `DOMParser.parseFromString`.
*
* @param {string} html - The HTML string.
* @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
* @return {HTMLDocument}
*/
parseFromString = function (html, tagName) {
if (tagName) {
html = '<' + tagName + '>' + html + '</' + tagName + '>';
}
/**
* Use HTML document created by `document.implementation.createHTMLDocument`.
*
* @param {string} html - The HTML string.
* @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
* @return {HTMLDocument}
*/
parseFromDocument = function (html, tagName) {
if (tagName) {
doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;
return doc;
}
return domParser.parseFromString(html, mimeType);
};
doc.documentElement.innerHTML = html;
return doc;
};
}
parseFromDocument = parseFromString;
}
/**
* Template (performance: fast).
*
* @see https://developer.mozilla.org/docs/Web/HTML/Element/template
*/
var template = document.createElement('template');
var parseFromTemplate;
/**
* DOMImplementation (performance: fair).
*
* @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
*/
if (document.implementation) {
var isIE = utilities.isIE;
if (template.content) {
/**
* Uses a template element (content fragment) to parse HTML.
*
* @param {string} html - The HTML string.
* @return {NodeList}
*/
parseFromTemplate = function (html) {
template.innerHTML = html;
return template.content.childNodes;
};
}
// title parameter is required in IE
// https://msdn.microsoft.com/en-us/library/ff975457(v=vs.85).aspx
var doc = document.implementation.createHTMLDocument(
isIE() ? 'html-dom-parser' : undefined
);
/**
* Parses HTML string to DOM nodes.
*
* @param {string} html - HTML markup.
* @return {NodeList}
*/
function domparser(html) {
var firstTagName;
var match = html.match(FIRST_TAG_REGEX);
/**
* Use HTML document created by `document.implementation.createHTMLDocument`.
*
* @param {string} html - The HTML string.
* @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
* @return {HTMLDocument}
*/
parseFromDocument = function (html, tagName) {
if (tagName) {
doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;
return doc;
}
if (match && match[1]) {
firstTagName = match[1].toLowerCase();
}
doc.documentElement.innerHTML = html;
return doc;
};
}
var doc;
var element;
var elements;
/**
* Template (performance: fast).
*
* @see https://developer.mozilla.org/docs/Web/HTML/Element/template
*/
var template = document.createElement('template');
var parseFromTemplate;
switch (firstTagName) {
case HTML:
doc = parseFromString(html);
if (template.content) {
/**
* Uses a template element (content fragment) to parse HTML.
*
* @param {string} html - The HTML string.
* @return {NodeList}
*/
parseFromTemplate = function (html) {
template.innerHTML = html;
return template.content.childNodes;
};
}
// the created document may come with filler head/body elements,
// so make sure to remove them if they don't actually exist
if (!HEAD_TAG_REGEX.test(html)) {
element = doc.getElementsByTagName(HEAD)[0];
if (element) {
element.parentNode.removeChild(element);
}
}
/**
* Parses HTML string to DOM nodes.
*
* @param {string} html - HTML markup.
* @return {NodeList}
*/
function domparser$1(html) {
var firstTagName;
var match = html.match(FIRST_TAG_REGEX);
if (!BODY_TAG_REGEX.test(html)) {
element = doc.getElementsByTagName(BODY)[0];
if (element) {
element.parentNode.removeChild(element);
}
}
if (match && match[1]) {
firstTagName = match[1].toLowerCase();
}
return doc.getElementsByTagName(HTML);
var doc;
var element;
var elements;
case HEAD:
case BODY:
elements = parseFromDocument(html).getElementsByTagName(firstTagName);
switch (firstTagName) {
case HTML:
doc = parseFromString(html);
// if there's a sibling element, then return both elements
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
return elements[0].parentNode.childNodes;
}
return elements;
// the created document may come with filler head/body elements,
// so make sure to remove them if they don't actually exist
if (!HEAD_TAG_REGEX.test(html)) {
element = doc.getElementsByTagName(HEAD)[0];
if (element) {
element.parentNode.removeChild(element);
}
}
// low-level tag or text
default:
if (parseFromTemplate) {
return parseFromTemplate(html);
}
if (!BODY_TAG_REGEX.test(html)) {
element = doc.getElementsByTagName(BODY)[0];
if (element) {
element.parentNode.removeChild(element);
}
}
return parseFromDocument(html, BODY).getElementsByTagName(BODY)[0]
.childNodes;
}
}
return doc.getElementsByTagName(HTML);
var domparser_1 = domparser;
case HEAD:
case BODY:
elements = parseFromDocument(html).getElementsByTagName(firstTagName);
var formatDOM$1 = utilities.formatDOM;
// if there's a sibling element, then return both elements
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
return elements[0].parentNode.childNodes;
}
return elements;
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
// low-level tag or text
default:
if (parseFromTemplate) {
return parseFromTemplate(html);
}
/**
* Parses HTML string to DOM nodes in browser.
*
* @param {string} html - HTML markup.
* @return {DomElement[]} - DOM elements.
*/
function HTMLDOMParser(html) {
if (typeof html !== 'string') {
throw new TypeError('First argument must be a string');
}
return parseFromDocument(html, BODY).getElementsByTagName(BODY)[0]
.childNodes;
}
}
if (html === '') {
return [];
}
var domparser_1 = domparser$1;
// match directive
var match = html.match(DIRECTIVE_REGEX);
var directive;
var domparser = domparser_1;
var formatDOM = utilities.formatDOM;
if (match && match[1]) {
directive = match[1];
}
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
return formatDOM$1(domparser_1(html), null, directive);
}
/**
* Parses HTML string to DOM nodes in browser.
*
* @param {string} html - HTML markup.
* @return {DomElement[]} - DOM elements.
*/
function HTMLDOMParser(html) {
if (typeof html !== 'string') {
throw new TypeError('First argument must be a string');
}
var htmlToDom = HTMLDOMParser;
if (html === '') {
return [];
}
return htmlToDom;
// match directive
var match = html.match(DIRECTIVE_REGEX);
var directive;
if (match && match[1]) {
directive = match[1];
}
return formatDOM(domparser(html), null, directive);
}
var htmlToDom = HTMLDOMParser;
return htmlToDom;
})));
//# sourceMappingURL=html-dom-parser.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).HTMLDOMParser=t()}(this,(function(){"use strict";var e=["animateMotion","animateTransform","clipPath","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussainBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","foreignObject","linearGradient","radialGradient","textPath"],t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};for(var n,r=function(e){var t={exports:{}};return e(t,t.exports),t.exports}((function(e,n){var r,o=t&&t.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=t&&t.__assign||function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};Object.defineProperty(n,"__esModule",{value:!0}),n.cloneNode=n.Element=n.Document=n.NodeWithChildren=n.ProcessingInstruction=n.Comment=n.Text=n.DataNode=n.Node=void 0;var a=new Map([["tag",1],["script",1],["style",1],["directive",1],["text",3],["cdata",4],["comment",8],["root",9]]),u=function(){function e(e){this.type=e,this.parent=null,this.prev=null,this.next=null,this.startIndex=null,this.endIndex=null}return Object.defineProperty(e.prototype,"nodeType",{get:function(){var e;return null!==(e=a.get(this.type))&&void 0!==e?e:1},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parentNode",{get:function(){return this.parent},set:function(e){this.parent=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"previousSibling",{get:function(){return this.prev},set:function(e){this.prev=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"nextSibling",{get:function(){return this.next},set:function(e){this.next=e},enumerable:!1,configurable:!0}),e.prototype.cloneNode=function(e){return void 0===e&&(e=!1),m(this,e)},e}();n.Node=u;var c=function(e){function t(t,n){var r=e.call(this,t)||this;return r.data=n,r}return o(t,e),Object.defineProperty(t.prototype,"nodeValue",{get:function(){return this.data},set:function(e){this.data=e},enumerable:!1,configurable:!0}),t}(u);n.DataNode=c;var s=function(e){function t(t){return e.call(this,"text",t)||this}return o(t,e),t}(c);n.Text=s;var l=function(e){function t(t){return e.call(this,"comment",t)||this}return o(t,e),t}(c);n.Comment=l;var f=function(e){function t(t,n){var r=e.call(this,"directive",n)||this;return r.name=t,r}return o(t,e),t}(c);n.ProcessingInstruction=f;var d=function(e){function t(t,n){var r=e.call(this,t)||this;return r.children=n,r}return o(t,e),Object.defineProperty(t.prototype,"firstChild",{get:function(){var e;return null!==(e=this.children[0])&&void 0!==e?e:null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"lastChild",{get:function(){return this.children.length>0?this.children[this.children.length-1]:null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"childNodes",{get:function(){return this.children},set:function(e){this.children=e},enumerable:!1,configurable:!0}),t}(u);n.NodeWithChildren=d;var p=function(e){function t(t){return e.call(this,"root",t)||this}return o(t,e),t}(d);n.Document=p;var h=function(e){function t(t,n,r){void 0===r&&(r=[]);var o=e.call(this,"script"===t?"script":"style"===t?"style":"tag",r)||this;return o.name=t,o.attribs=n,o.attribs=n,o}return o(t,e),Object.defineProperty(t.prototype,"tagName",{get:function(){return this.name},set:function(e){this.name=e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"attributes",{get:function(){var e=this;return Object.keys(this.attribs).map((function(t){var n,r;return{name:t,value:e.attribs[t],namespace:null===(n=e["x-attribsNamespace"])||void 0===n?void 0:n[t],prefix:null===(r=e["x-attribsPrefix"])||void 0===r?void 0:r[t]}}))},enumerable:!1,configurable:!0}),t}(d);function m(e,t){var n;switch(void 0===t&&(t=!1),e.type){case"text":n=new s(e.data);break;case"directive":var r=e;n=new f(r.name,r.data),null!=r["x-name"]&&(n["x-name"]=r["x-name"],n["x-publicId"]=r["x-publicId"],n["x-systemId"]=r["x-systemId"]);break;case"comment":n=new l(e.data);break;case"tag":case"script":case"style":var o=e,a=t?b(o.children):[],u=new h(o.name,i({},o.attribs),a);a.forEach((function(e){return e.parent=u})),o["x-attribsNamespace"]&&(u["x-attribsNamespace"]=i({},o["x-attribsNamespace"])),o["x-attribsPrefix"]&&(u["x-attribsPrefix"]=i({},o["x-attribsPrefix"])),n=u;break;case"cdata":a=t?b(e.children):[];var c=new d(e.type,a);a.forEach((function(e){return e.parent=c})),n=c;break;case"root":var m=e,g=(a=t?b(m.children):[],new p(a));a.forEach((function(e){return e.parent=g})),m["x-mode"]&&(g["x-mode"]=m["x-mode"]),n=g;break;case"doctype":throw new Error("Not implemented yet: ElementType.Doctype case")}return n.startIndex=e.startIndex,n.endIndex=e.endIndex,n}function b(e){for(var t=e.map((function(e){return m(e,!0)})),n=1;n<t.length;n++)t[n].prev=t[n-1],t[n-1].next=t[n];return t}n.Element=h,n.cloneNode=m})),o=e,i=r.Comment,a=r.Element,u=r.ProcessingInstruction,c=r.Text,s={},l=0,f=o.length;l<f;l++)n=o[l],s[n.toLowerCase()]=n;function d(e){for(var t,n={},r=0,o=e.length;r<o;r++)n[(t=e[r]).name]=t.value;return n}function p(e){var t=function(e){return s[e]}(e=e.toLowerCase());return t||e}var h=function e(t,n,r){n=n||null;for(var o=[],s=0,l=t.length;s<l;s++){var f,h=t[s];switch(h.nodeType){case 1:(f=new a(p(h.nodeName),d(h.attributes))).children=e(h.childNodes,f);break;case 3:f=new c(h.nodeValue);break;case 8:f=new i(h.nodeValue);break;default:continue}var m=o[s-1]||null;m&&(m.next=f),f.parent=n,f.prev=m,f.next=null,o.push(f)}return r&&((f=new u(r.substring(0,r.indexOf(" ")).toLowerCase(),r)).next=o[0]||null,f.parent=n,o.unshift(f),o[1]&&(o[1].prev=o[0])),o},m=function(){return/(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent)},b="html",g="head",v="body",y=/<([a-zA-Z]+[0-9]?)/,x=/<head.*>/i,w=/<body.*>/i,N=function(){throw new Error("This browser does not support `document.implementation.createHTMLDocument`")},T=function(){throw new Error("This browser does not support `DOMParser.prototype.parseFromString`")};if("function"==typeof window.DOMParser){var P=new window.DOMParser;N=T=function(e,t){return t&&(e="<"+t+">"+e+"</"+t+">"),P.parseFromString(e,"text/html")}}if(document.implementation){var O=m,E=document.implementation.createHTMLDocument(O()?"html-dom-parser":void 0);N=function(e,t){return t?(E.documentElement.getElementsByTagName(t)[0].innerHTML=e,E):(E.documentElement.innerHTML=e,E)}}var M,j=document.createElement("template");j.content&&(M=function(e){return j.innerHTML=e,j.content.childNodes});var C=function(e){var t,n,r,o,i=e.match(y);switch(i&&i[1]&&(t=i[1].toLowerCase()),t){case b:return n=T(e),x.test(e)||(r=n.getElementsByTagName(g)[0])&&r.parentNode.removeChild(r),w.test(e)||(r=n.getElementsByTagName(v)[0])&&r.parentNode.removeChild(r),n.getElementsByTagName(b);case g:case v:return o=N(e).getElementsByTagName(t),w.test(e)&&x.test(e)?o[0].parentNode.childNodes:o;default:return M?M(e):N(e,v).getElementsByTagName(v)[0].childNodes}},I=h,D=/<(![a-zA-Z\s]+)>/;return function(e){if("string"!=typeof e)throw new TypeError("First argument must be a string");if(""===e)return[];var t,n=e.match(D);return n&&n[1]&&(t=n[1]),I(C(e),null,t)}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).HTMLDOMParser=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t={CASE_SENSITIVE_TAG_NAMES:["animateMotion","animateTransform","clipPath","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussainBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","foreignObject","linearGradient","radialGradient","textPath"]},n={},r={};!function(e){var t;Object.defineProperty(e,"__esModule",{value:!0}),e.Doctype=e.CDATA=e.Tag=e.Style=e.Script=e.Comment=e.Directive=e.Text=e.Root=e.isTag=e.ElementType=void 0,function(e){e.Root="root",e.Text="text",e.Directive="directive",e.Comment="comment",e.Script="script",e.Style="style",e.Tag="tag",e.CDATA="cdata",e.Doctype="doctype"}(t=e.ElementType||(e.ElementType={})),e.isTag=function(e){return e.type===t.Tag||e.type===t.Script||e.type===t.Style},e.Root=t.Root,e.Text=t.Text,e.Directive=t.Directive,e.Comment=t.Comment,e.Script=t.Script,e.Style=t.Style,e.Tag=t.Tag,e.CDATA=t.CDATA,e.Doctype=t.Doctype}(r);var o,i=e&&e.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),a=e&&e.__assign||function(){return(a=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};Object.defineProperty(n,"__esModule",{value:!0}),n.cloneNode=n.hasChildren=n.isDocument=n.isDirective=n.isComment=n.isText=n.isCDATA=n.isTag=n.Element=n.Document=n.NodeWithChildren=n.ProcessingInstruction=n.Comment=n.Text=n.DataNode=n.Node=void 0;var u=r,l=new Map([[u.ElementType.Tag,1],[u.ElementType.Script,1],[u.ElementType.Style,1],[u.ElementType.Directive,1],[u.ElementType.Text,3],[u.ElementType.CDATA,4],[u.ElementType.Comment,8],[u.ElementType.Root,9]]),c=function(){function e(e){this.type=e,this.parent=null,this.prev=null,this.next=null,this.startIndex=null,this.endIndex=null}return Object.defineProperty(e.prototype,"nodeType",{get:function(){var e;return null!==(e=l.get(this.type))&&void 0!==e?e:1},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"parentNode",{get:function(){return this.parent},set:function(e){this.parent=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"previousSibling",{get:function(){return this.prev},set:function(e){this.prev=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"nextSibling",{get:function(){return this.next},set:function(e){this.next=e},enumerable:!1,configurable:!0}),e.prototype.cloneNode=function(e){return void 0===e&&(e=!1),w(this,e)},e}();n.Node=c;var s=function(e){function t(t,n){var r=e.call(this,t)||this;return r.data=n,r}return i(t,e),Object.defineProperty(t.prototype,"nodeValue",{get:function(){return this.data},set:function(e){this.data=e},enumerable:!1,configurable:!0}),t}(c);n.DataNode=s;var f=function(e){function t(t){return e.call(this,u.ElementType.Text,t)||this}return i(t,e),t}(s);n.Text=f;var p=function(e){function t(t){return e.call(this,u.ElementType.Comment,t)||this}return i(t,e),t}(s);n.Comment=p;var d=function(e){function t(t,n){var r=e.call(this,u.ElementType.Directive,n)||this;return r.name=t,r}return i(t,e),t}(s);n.ProcessingInstruction=d;var m=function(e){function t(t,n){var r=e.call(this,t)||this;return r.children=n,r}return i(t,e),Object.defineProperty(t.prototype,"firstChild",{get:function(){var e;return null!==(e=this.children[0])&&void 0!==e?e:null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"lastChild",{get:function(){return this.children.length>0?this.children[this.children.length-1]:null},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"childNodes",{get:function(){return this.children},set:function(e){this.children=e},enumerable:!1,configurable:!0}),t}(c);n.NodeWithChildren=m;var h=function(e){function t(t){return e.call(this,u.ElementType.Root,t)||this}return i(t,e),t}(m);n.Document=h;var y=function(e){function t(t,n,r,o){void 0===r&&(r=[]),void 0===o&&(o="script"===t?u.ElementType.Script:"style"===t?u.ElementType.Style:u.ElementType.Tag);var i=e.call(this,o,r)||this;return i.name=t,i.attribs=n,i}return i(t,e),Object.defineProperty(t.prototype,"tagName",{get:function(){return this.name},set:function(e){this.name=e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"attributes",{get:function(){var e=this;return Object.keys(this.attribs).map((function(t){var n,r;return{name:t,value:e.attribs[t],namespace:null===(n=e["x-attribsNamespace"])||void 0===n?void 0:n[t],prefix:null===(r=e["x-attribsPrefix"])||void 0===r?void 0:r[t]}}))},enumerable:!1,configurable:!0}),t}(m);function g(e){return u.isTag(e)}function T(e){return e.type===u.ElementType.CDATA}function v(e){return e.type===u.ElementType.Text}function b(e){return e.type===u.ElementType.Comment}function x(e){return e.type===u.ElementType.Directive}function E(e){return e.type===u.ElementType.Root}function w(e,t){var n;if(void 0===t&&(t=!1),v(e))n=new f(e.data);else if(b(e))n=new p(e.data);else if(g(e)){var r=t?C(e.children):[],o=new y(e.name,a({},e.attribs),r);r.forEach((function(e){return e.parent=o})),e["x-attribsNamespace"]&&(o["x-attribsNamespace"]=a({},e["x-attribsNamespace"])),e["x-attribsPrefix"]&&(o["x-attribsPrefix"]=a({},e["x-attribsPrefix"])),n=o}else if(T(e)){r=t?C(e.children):[];var i=new m(u.ElementType.CDATA,r);r.forEach((function(e){return e.parent=i})),n=i}else if(E(e)){r=t?C(e.children):[];var l=new h(r);r.forEach((function(e){return e.parent=l})),e["x-mode"]&&(l["x-mode"]=e["x-mode"]),n=l}else{if(!x(e))throw new Error("Not implemented yet: "+e.type);var c=new d(e.name,e.data);null!=e["x-name"]&&(c["x-name"]=e["x-name"],c["x-publicId"]=e["x-publicId"],c["x-systemId"]=e["x-systemId"]),n=c}return n.startIndex=e.startIndex,n.endIndex=e.endIndex,n}function C(e){for(var t=e.map((function(e){return w(e,!0)})),n=1;n<t.length;n++)t[n].prev=t[n-1],t[n-1].next=t[n];return t}n.Element=y,n.isTag=g,n.isCDATA=T,n.isText=v,n.isComment=b,n.isDirective=x,n.isDocument=E,n.hasChildren=function(e){return Object.prototype.hasOwnProperty.call(e,"children")},n.cloneNode=w;for(var D,N=n,S=t.CASE_SENSITIVE_TAG_NAMES,O=N.Comment,P=N.Element,A=N.ProcessingInstruction,M=N.Text,_={},j=0,I=S.length;j<I;j++)D=S[j],_[D.toLowerCase()]=D;function L(e){for(var t,n={},r=0,o=e.length;r<o;r++)n[(t=e[r]).name]=t.value;return n}function B(e){var t=function(e){return _[e]}(e=e.toLowerCase());return t||e}var F=function e(t,n,r){n=n||null;for(var o=[],i=0,a=t.length;i<a;i++){var u,l=t[i];switch(l.nodeType){case 1:(u=new P(B(l.nodeName),L(l.attributes))).children=e(l.childNodes,u);break;case 3:u=new M(l.nodeValue);break;case 8:u=new O(l.nodeValue);break;default:continue}var c=o[i-1]||null;c&&(c.next=u),u.parent=n,u.prev=c,u.next=null,o.push(u)}return r&&((u=new A(r.substring(0,r.indexOf(" ")).toLowerCase(),r)).next=o[0]||null,u.parent=n,o.unshift(u),o[1]&&(o[1].prev=o[0])),o},R=function(){return/(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent)},G="html",H="head",V="body",k=/<([a-zA-Z]+[0-9]?)/,z=/<head.*>/i,W=/<body.*>/i,Z=function(){throw new Error("This browser does not support `document.implementation.createHTMLDocument`")},q=function(){throw new Error("This browser does not support `DOMParser.prototype.parseFromString`")};if("function"==typeof window.DOMParser){var J=new window.DOMParser;Z=q=function(e,t){return t&&(e="<"+t+">"+e+"</"+t+">"),J.parseFromString(e,"text/html")}}if(document.implementation){var K=R,Q=document.implementation.createHTMLDocument(K()?"html-dom-parser":void 0);Z=function(e,t){return t?(Q.documentElement.getElementsByTagName(t)[0].innerHTML=e,Q):(Q.documentElement.innerHTML=e,Q)}}var U,X=document.createElement("template");X.content&&(U=function(e){return X.innerHTML=e,X.content.childNodes});var Y=function(e){var t,n,r,o,i=e.match(k);switch(i&&i[1]&&(t=i[1].toLowerCase()),t){case G:return n=q(e),z.test(e)||(r=n.getElementsByTagName(H)[0])&&r.parentNode.removeChild(r),W.test(e)||(r=n.getElementsByTagName(V)[0])&&r.parentNode.removeChild(r),n.getElementsByTagName(G);case H:case V:return o=Z(e).getElementsByTagName(t),W.test(e)&&z.test(e)?o[0].parentNode.childNodes:o;default:return U?U(e):Z(e,V).getElementsByTagName(V)[0].childNodes}},$=F,ee=/<(![a-zA-Z\s]+)>/;return function(e){if("string"!=typeof e)throw new TypeError("First argument must be a string");if(""===e)return[];var t,n=e.match(ee);return n&&n[1]&&(t=n[1]),$(Y(e),null,t)}}));
//# sourceMappingURL=html-dom-parser.min.js.map

@@ -1,3 +0,3 @@

// TypeScript Version: 4.1
// TypeScript Version: 4.3
export { default } from './lib/server/html-to-dom';

@@ -1,2 +0,2 @@

// TypeScript Version: 4.1
// TypeScript Version: 4.3

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

// TypeScript Version: 4.1
// TypeScript Version: 4.3

@@ -3,0 +3,0 @@ /**

@@ -1,2 +0,2 @@

// TypeScript Version: 4.1
// TypeScript Version: 4.3

@@ -3,0 +3,0 @@ import { DataNode, Element } from 'domhandler';

@@ -1,2 +0,2 @@

// TypeScript Version: 4.1
// TypeScript Version: 4.3

@@ -3,0 +3,0 @@ import { Comment, Element, ProcessingInstruction, Text } from 'domhandler';

@@ -1,2 +0,2 @@

// TypeScript Version: 4.1
// TypeScript Version: 4.3

@@ -3,0 +3,0 @@ import {

@@ -1,2 +0,2 @@

// TypeScript Version: 4.1
// TypeScript Version: 4.3

@@ -3,0 +3,0 @@ type Nodes = Array<Comment | Element | ProcessingInstruction | Text>;

{
"name": "html-dom-parser",
"version": "1.0.0",
"version": "1.0.1",
"description": "HTML to DOM parser.",

@@ -13,3 +13,5 @@ "author": "Mark <mark@remarkablemark.org>",

"lint:fix": "npm run lint -- --fix",
"prepublishOnly": "run-s lint lint:dts test clean build",
"_postinstall": "husky install",
"postpublish": "pinst --enable",
"prepublishOnly": "pinst --disable && run-s lint lint:dts test clean build",
"release": "standard-version --no-verify",

@@ -38,19 +40,19 @@ "test": "run-s test:server test:client",

"dependencies": {
"domhandler": "4.0.0",
"htmlparser2": "6.0.0"
"domhandler": "4.2.0",
"htmlparser2": "6.1.0"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@size-limit/preset-big-lib": "^4.9.1",
"chai": "^4.2.0",
"dtslint": "^4.0.6",
"eslint": "^7.16.0",
"eslint-plugin-prettier": "^3.3.0",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@size-limit/preset-big-lib": "^4.12.0",
"chai": "^4.3.4",
"dtslint": "^4.1.0",
"eslint": "^7.28.0",
"eslint-plugin-prettier": "^3.4.0",
"html-minifier": "^4.0.0",
"husky": "^4.3.6",
"husky": "^6.0.0",
"jsdomify": "^3.1.1",
"karma": "^5.2.3",
"karma": "^6.3.3",
"karma-chai": "^0.1.0",

@@ -61,16 +63,17 @@ "karma-chrome-launcher": "^3.1.0",

"karma-mocha-reporter": "^2.2.5",
"lint-staged": "^10.5.3",
"mocha": "^8.2.1",
"lint-staged": "^11.0.0",
"mocha": "^9.0.0",
"mock-require": "^3.0.3",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"rollup": "^2.35.1",
"pinst": "^2.1.6",
"prettier": "2.3.1",
"rollup": "^2.51.2",
"rollup-plugin-terser": "^7.0.2",
"sinon": "^9.2.2",
"size-limit": "^4.9.1",
"standard-version": "^5",
"typescript": "^4.1.3",
"sinon": "^11.1.1",
"size-limit": "^4.12.0",
"standard-version": "^9.3.0",
"typescript": "^4.3.2",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
"webpack-cli": "^4.7.2"
},

@@ -77,0 +80,0 @@ "files": [

@@ -61,3 +61,3 @@ # html-dom-parser

```sh
$ npm install html-dom-parser --save
npm install html-dom-parser --save
```

@@ -68,3 +68,3 @@

```sh
$ yarn add html-dom-parser
yarn add html-dom-parser
```

@@ -158,3 +158,3 @@

```sh
$ npm test
npm test
```

@@ -165,3 +165,3 @@

```sh
$ npx nyc report --reporter=html
npx nyc report --reporter=html
```

@@ -172,4 +172,4 @@

```sh
$ npm run lint
# npm run lint:fix
npm run lint
npm run lint:fix
```

@@ -180,3 +180,3 @@

```sh
$ npm run lint:dts
npm run lint:dts
```

@@ -189,4 +189,4 @@

```sh
$ npm run release
$ git push --follow-tags && npm publish
npm run release
git push --follow-tags && npm publish
```

@@ -193,0 +193,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc