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

html-dom-parser

Package Overview
Dependencies
Maintainers
0
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 5.0.11 to 5.0.12

8

dist/html-dom-parser.js

@@ -432,2 +432,6 @@ (function (global, factory) {

}, {});
var CARRIAGE_RETURN = '\r';
var CARRIAGE_RETURN_REGEX = new RegExp(CARRIAGE_RETURN, 'g');
var CARRIAGE_RETURN_PLACEHOLDER = "__HTML_DOM_PARSER_CARRIAGE_RETURN_PLACEHOLDER_".concat(Date.now(), "__");
var CARRIAGE_RETURN_PLACEHOLDER_REGEX = new RegExp(CARRIAGE_RETURN_PLACEHOLDER, 'g');

@@ -482,3 +486,3 @@ /**

function escapeSpecialCharacters(html) {
return html.replace(/\r/g, '\\r');
return html.replace(CARRIAGE_RETURN_REGEX, CARRIAGE_RETURN_PLACEHOLDER);
}

@@ -492,3 +496,3 @@ /**

function revertEscapedCharacters(text) {
return text.replace(/\\r/g, '\r');
return text.replace(CARRIAGE_RETURN_PLACEHOLDER_REGEX, CARRIAGE_RETURN);
}

@@ -495,0 +499,0 @@ /**

@@ -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;!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"}(e||(e={})),e.Root,e.Text,e.Directive,e.Comment,e.Script,e.Style,e.Tag,e.CDATA,e.Doctype;class t{constructor(){this.parent=null,this.prev=null,this.next=null,this.startIndex=null,this.endIndex=null}get parentNode(){return this.parent}set parentNode(e){this.parent=e}get previousSibling(){return this.prev}set previousSibling(e){this.prev=e}get nextSibling(){return this.next}set nextSibling(e){this.next=e}cloneNode(e=!1){return d(this,e)}}class n extends t{constructor(e){super(),this.data=e}get nodeValue(){return this.data}set nodeValue(e){this.data=e}}class r extends n{constructor(){super(...arguments),this.type=e.Text}get nodeType(){return 3}}class o extends n{constructor(){super(...arguments),this.type=e.Comment}get nodeType(){return 8}}class i extends n{constructor(t,n){super(n),this.name=t,this.type=e.Directive}get nodeType(){return 1}}class s extends t{constructor(e){super(),this.children=e}get firstChild(){var e;return null!==(e=this.children[0])&&void 0!==e?e:null}get lastChild(){return this.children.length>0?this.children[this.children.length-1]:null}get childNodes(){return this.children}set childNodes(e){this.children=e}}class a extends s{constructor(){super(...arguments),this.type=e.CDATA}get nodeType(){return 4}}class c extends s{constructor(){super(...arguments),this.type=e.Root}get nodeType(){return 9}}class u extends s{constructor(t,n,r=[],o=("script"===t?e.Script:"style"===t?e.Style:e.Tag)){super(r),this.name=t,this.attribs=n,this.type=o}get nodeType(){return 1}get tagName(){return this.name}set tagName(e){this.name=e}get attributes(){return Object.keys(this.attribs).map((e=>{var t,n;return{name:e,value:this.attribs[e],namespace:null===(t=this["x-attribsNamespace"])||void 0===t?void 0:t[e],prefix:null===(n=this["x-attribsPrefix"])||void 0===n?void 0:n[e]}}))}}function l(t){return(n=t).type===e.Tag||n.type===e.Script||n.type===e.Style;var n}function d(t,n=!1){let s;if(function(t){return t.type===e.Text}(t))s=new r(t.data);else if(function(t){return t.type===e.Comment}(t))s=new o(t.data);else if(l(t)){const e=n?p(t.children):[],r=new u(t.name,{...t.attribs},e);e.forEach((e=>e.parent=r)),null!=t.namespace&&(r.namespace=t.namespace),t["x-attribsNamespace"]&&(r["x-attribsNamespace"]={...t["x-attribsNamespace"]}),t["x-attribsPrefix"]&&(r["x-attribsPrefix"]={...t["x-attribsPrefix"]}),s=r}else if(function(t){return t.type===e.CDATA}(t)){const e=n?p(t.children):[],r=new a(e);e.forEach((e=>e.parent=r)),s=r}else if(function(t){return t.type===e.Root}(t)){const e=n?p(t.children):[],r=new c(e);e.forEach((e=>e.parent=r)),t["x-mode"]&&(r["x-mode"]=t["x-mode"]),s=r}else{if(!function(t){return t.type===e.Directive}(t))throw new Error(`Not implemented yet: ${t.type}`);{const e=new i(t.name,t.data);null!=t["x-name"]&&(e["x-name"]=t["x-name"],e["x-publicId"]=t["x-publicId"],e["x-systemId"]=t["x-systemId"]),s=e}}return s.startIndex=t.startIndex,s.endIndex=t.endIndex,null!=t.sourceCodeLocation&&(s.sourceCodeLocation=t.sourceCodeLocation),s}function p(e){const t=e.map((e=>d(e,!0)));for(let e=1;e<t.length;e++)t[e].prev=t[e-1],t[e-1].next=t[e];return t}var f=["animateMotion","animateTransform","clipPath","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","foreignObject","linearGradient","radialGradient","textPath"].reduce((function(e,t){return e[t.toLowerCase()]=t,e}),{});function h(e){for(var t={},n=0,r=e.length;n<r;n++){var o=e[n];t[o.name]=o.value}return t}function m(e){var t=function(e){return f[e]}(e=e.toLowerCase());return t||e}function x(e,t,n){void 0===t&&(t=null);for(var s,a=[],c=0,l=e.length;c<l;c++){var d=e[c];switch(d.nodeType){case 1:var p=m(d.nodeName);(s=new u(p,h(d.attributes))).children=x("template"===p?d.content.childNodes:d.childNodes,s);break;case 3:s=new r(d.nodeValue.replace(/\\r/g,"\r"));break;case 8:s=new o(d.nodeValue);break;default:continue}var f=a[c-1]||null;f&&(f.next=s),s.parent=t,s.prev=f,s.next=null,a.push(s)}return n&&((s=new i(n.substring(0,n.indexOf(" ")).toLowerCase(),n)).next=a[0]||null,s.parent=t,a.unshift(s),a[1]&&(a[1].prev=a[0])),a}var y="html",v="head",g="body",b=/<([a-zA-Z]+[0-9]?)/,T=/<head[^]*>/i,w=/<body[^]*>/i,C=function(e,t){throw new Error("This browser does not support `document.implementation.createHTMLDocument`")},S=function(e,t){throw new Error("This browser does not support `DOMParser.prototype.parseFromString`")},N="object"==typeof window&&window.DOMParser;if("function"==typeof N){var D=new N;C=S=function(e,t){return t&&(e="<".concat(t,">").concat(e,"</").concat(t,">")),D.parseFromString(e,"text/html")}}if("object"==typeof document&&document.implementation){var L=document.implementation.createHTMLDocument();C=function(e,t){if(t){var n=L.documentElement.querySelector(t);return n&&(n.innerHTML=e),L}return L.documentElement.innerHTML=e,L}}var M,A="object"==typeof document&&document.createElement("template");A&&A.content&&(M=function(e){return A.innerHTML=e,A.content.childNodes});var I=/<(![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=e.match(I),n=t?t[1]:void 0;return x(function(e){var t,n,r=(e=function(e){return e.replace(/\r/g,"\\r")}(e)).match(b),o=r&&r[1]?r[1].toLowerCase():"";switch(o){case y:var i=S(e);return T.test(e)||null===(t=null==(a=i.querySelector(v))?void 0:a.parentNode)||void 0===t||t.removeChild(a),w.test(e)||null===(n=null==(a=i.querySelector(g))?void 0:a.parentNode)||void 0===n||n.removeChild(a),i.querySelectorAll(y);case v:case g:var s=C(e).querySelectorAll(o);return w.test(e)&&T.test(e)?s[0].parentNode.childNodes:s;default:return M?M(e):(a=C(e,g).querySelector(g)).childNodes;var a}}(e),null,n)}}));
!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;!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"}(e||(e={})),e.Root,e.Text,e.Directive,e.Comment,e.Script,e.Style,e.Tag,e.CDATA,e.Doctype;class t{constructor(){this.parent=null,this.prev=null,this.next=null,this.startIndex=null,this.endIndex=null}get parentNode(){return this.parent}set parentNode(e){this.parent=e}get previousSibling(){return this.prev}set previousSibling(e){this.prev=e}get nextSibling(){return this.next}set nextSibling(e){this.next=e}cloneNode(e=!1){return d(this,e)}}class n extends t{constructor(e){super(),this.data=e}get nodeValue(){return this.data}set nodeValue(e){this.data=e}}class r extends n{constructor(){super(...arguments),this.type=e.Text}get nodeType(){return 3}}class o extends n{constructor(){super(...arguments),this.type=e.Comment}get nodeType(){return 8}}class i extends n{constructor(t,n){super(n),this.name=t,this.type=e.Directive}get nodeType(){return 1}}class s extends t{constructor(e){super(),this.children=e}get firstChild(){var e;return null!==(e=this.children[0])&&void 0!==e?e:null}get lastChild(){return this.children.length>0?this.children[this.children.length-1]:null}get childNodes(){return this.children}set childNodes(e){this.children=e}}class a extends s{constructor(){super(...arguments),this.type=e.CDATA}get nodeType(){return 4}}class c extends s{constructor(){super(...arguments),this.type=e.Root}get nodeType(){return 9}}class u extends s{constructor(t,n,r=[],o=("script"===t?e.Script:"style"===t?e.Style:e.Tag)){super(r),this.name=t,this.attribs=n,this.type=o}get nodeType(){return 1}get tagName(){return this.name}set tagName(e){this.name=e}get attributes(){return Object.keys(this.attribs).map((e=>{var t,n;return{name:e,value:this.attribs[e],namespace:null===(t=this["x-attribsNamespace"])||void 0===t?void 0:t[e],prefix:null===(n=this["x-attribsPrefix"])||void 0===n?void 0:n[e]}}))}}function l(t){return(n=t).type===e.Tag||n.type===e.Script||n.type===e.Style;var n}function d(t,n=!1){let s;if(function(t){return t.type===e.Text}(t))s=new r(t.data);else if(function(t){return t.type===e.Comment}(t))s=new o(t.data);else if(l(t)){const e=n?p(t.children):[],r=new u(t.name,{...t.attribs},e);e.forEach((e=>e.parent=r)),null!=t.namespace&&(r.namespace=t.namespace),t["x-attribsNamespace"]&&(r["x-attribsNamespace"]={...t["x-attribsNamespace"]}),t["x-attribsPrefix"]&&(r["x-attribsPrefix"]={...t["x-attribsPrefix"]}),s=r}else if(function(t){return t.type===e.CDATA}(t)){const e=n?p(t.children):[],r=new a(e);e.forEach((e=>e.parent=r)),s=r}else if(function(t){return t.type===e.Root}(t)){const e=n?p(t.children):[],r=new c(e);e.forEach((e=>e.parent=r)),t["x-mode"]&&(r["x-mode"]=t["x-mode"]),s=r}else{if(!function(t){return t.type===e.Directive}(t))throw new Error(`Not implemented yet: ${t.type}`);{const e=new i(t.name,t.data);null!=t["x-name"]&&(e["x-name"]=t["x-name"],e["x-publicId"]=t["x-publicId"],e["x-systemId"]=t["x-systemId"]),s=e}}return s.startIndex=t.startIndex,s.endIndex=t.endIndex,null!=t.sourceCodeLocation&&(s.sourceCodeLocation=t.sourceCodeLocation),s}function p(e){const t=e.map((e=>d(e,!0)));for(let e=1;e<t.length;e++)t[e].prev=t[e-1],t[e-1].next=t[e];return t}var f=["animateMotion","animateTransform","clipPath","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","foreignObject","linearGradient","radialGradient","textPath"].reduce((function(e,t){return e[t.toLowerCase()]=t,e}),{}),h=new RegExp("\r","g"),m="__HTML_DOM_PARSER_CARRIAGE_RETURN_PLACEHOLDER_".concat(Date.now(),"__"),x=new RegExp(m,"g");function y(e){for(var t={},n=0,r=e.length;n<r;n++){var o=e[n];t[o.name]=o.value}return t}function g(e){var t=function(e){return f[e]}(e=e.toLowerCase());return t||e}function v(e,t,n){void 0===t&&(t=null);for(var s,a=[],c=0,l=e.length;c<l;c++){var d=e[c];switch(d.nodeType){case 1:var p=g(d.nodeName);(s=new u(p,y(d.attributes))).children=v("template"===p?d.content.childNodes:d.childNodes,s);break;case 3:s=new r(d.nodeValue.replace(x,"\r"));break;case 8:s=new o(d.nodeValue);break;default:continue}var f=a[c-1]||null;f&&(f.next=s),s.parent=t,s.prev=f,s.next=null,a.push(s)}return n&&((s=new i(n.substring(0,n.indexOf(" ")).toLowerCase(),n)).next=a[0]||null,s.parent=t,a.unshift(s),a[1]&&(a[1].prev=a[0])),a}var b="html",T="head",w="body",C=/<([a-zA-Z]+[0-9]?)/,S=/<head[^]*>/i,N=/<body[^]*>/i,D=function(e,t){throw new Error("This browser does not support `document.implementation.createHTMLDocument`")},L=function(e,t){throw new Error("This browser does not support `DOMParser.prototype.parseFromString`")},M="object"==typeof window&&window.DOMParser;if("function"==typeof M){var A=new M;D=L=function(e,t){return t&&(e="<".concat(t,">").concat(e,"</").concat(t,">")),A.parseFromString(e,"text/html")}}if("object"==typeof document&&document.implementation){var E=document.implementation.createHTMLDocument();D=function(e,t){if(t){var n=E.documentElement.querySelector(t);return n&&(n.innerHTML=e),E}return E.documentElement.innerHTML=e,E}}var R,I="object"==typeof document&&document.createElement("template");function P(e){var t,n,r=(e=function(e){return e.replace(h,m)}(e)).match(C),o=r&&r[1]?r[1].toLowerCase():"";switch(o){case b:var i=L(e);if(!S.test(e))null===(t=null==(a=i.querySelector(T))?void 0:a.parentNode)||void 0===t||t.removeChild(a);if(!N.test(e))null===(n=null==(a=i.querySelector(w))?void 0:a.parentNode)||void 0===n||n.removeChild(a);return i.querySelectorAll(b);case T:case w:var s=D(e).querySelectorAll(o);return N.test(e)&&S.test(e)?s[0].parentNode.childNodes:s;default:return R?R(e):(a=D(e,w).querySelector(w)).childNodes;var a}}I&&I.content&&(R=function(e){return I.innerHTML=e,I.content.childNodes});var _=/<(![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=e.match(_),n=t?t[1]:void 0;return v(P(e),null,n)}}));
//# sourceMappingURL=html-dom-parser.min.js.map

@@ -8,2 +8,6 @@ /**

export declare const CASE_SENSITIVE_TAG_NAMES_MAP: Record<string, string>;
export declare const CARRIAGE_RETURN = "\r";
export declare const CARRIAGE_RETURN_REGEX: RegExp;
export declare const CARRIAGE_RETURN_PLACEHOLDER: string;
export declare const CARRIAGE_RETURN_PLACEHOLDER_REGEX: RegExp;
//# sourceMappingURL=constants.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CASE_SENSITIVE_TAG_NAMES_MAP = exports.CASE_SENSITIVE_TAG_NAMES = void 0;
exports.CARRIAGE_RETURN_PLACEHOLDER_REGEX = exports.CARRIAGE_RETURN_PLACEHOLDER = exports.CARRIAGE_RETURN_REGEX = exports.CARRIAGE_RETURN = exports.CASE_SENSITIVE_TAG_NAMES_MAP = exports.CASE_SENSITIVE_TAG_NAMES = void 0;
/**

@@ -46,2 +46,6 @@ * SVG elements are case-sensitive.

}, {});
exports.CARRIAGE_RETURN = '\r';
exports.CARRIAGE_RETURN_REGEX = new RegExp(exports.CARRIAGE_RETURN, 'g');
exports.CARRIAGE_RETURN_PLACEHOLDER = "__HTML_DOM_PARSER_CARRIAGE_RETURN_PLACEHOLDER_".concat(Date.now(), "__");
exports.CARRIAGE_RETURN_PLACEHOLDER_REGEX = new RegExp(exports.CARRIAGE_RETURN_PLACEHOLDER, 'g');
//# sourceMappingURL=constants.js.map

@@ -57,3 +57,3 @@ "use strict";

function escapeSpecialCharacters(html) {
return html.replace(/\r/g, '\\r');
return html.replace(constants_1.CARRIAGE_RETURN_REGEX, constants_1.CARRIAGE_RETURN_PLACEHOLDER);
}

@@ -67,3 +67,3 @@ /**

function revertEscapedCharacters(text) {
return text.replace(/\\r/g, '\r');
return text.replace(constants_1.CARRIAGE_RETURN_PLACEHOLDER_REGEX, constants_1.CARRIAGE_RETURN);
}

@@ -70,0 +70,0 @@ /**

{
"name": "html-dom-parser",
"version": "5.0.11",
"version": "5.0.12",
"description": "HTML to DOM parser.",

@@ -62,12 +62,12 @@ "author": "Mark <mark@remarkablemark.org>",

"devDependencies": {
"@commitlint/cli": "19.6.0",
"@commitlint/cli": "19.6.1",
"@commitlint/config-conventional": "19.6.0",
"@eslint/compat": "1.2.3",
"@eslint/compat": "1.2.4",
"@eslint/eslintrc": "3.2.0",
"@eslint/js": "9.16.0",
"@eslint/js": "9.17.0",
"@rollup/plugin-alias": "5.1.1",
"@rollup/plugin-commonjs": "28.0.1",
"@rollup/plugin-node-resolve": "15.3.0",
"@rollup/plugin-commonjs": "28.0.2",
"@rollup/plugin-node-resolve": "16.0.0",
"@rollup/plugin-terser": "0.4.4",
"@rollup/plugin-typescript": "12.1.1",
"@rollup/plugin-typescript": "12.1.2",
"@size-limit/preset-big-lib": "11.1.6",

@@ -77,7 +77,7 @@ "@types/chai": "4.3.16",

"@types/mocha": "10.0.10",
"@types/node": "22.10.1",
"@typescript-eslint/eslint-plugin": "8.17.0",
"@typescript-eslint/parser": "8.17.0",
"@types/node": "22.10.2",
"@typescript-eslint/eslint-plugin": "8.18.0",
"@typescript-eslint/parser": "8.18.0",
"chai": "4.5.0",
"eslint": "9.16.0",
"eslint": "9.17.0",
"eslint-plugin-prettier": "5.2.1",

@@ -95,8 +95,8 @@ "eslint-plugin-simple-import-sort": "12.1.1",

"karma-mocha-reporter": "2.2.5",
"lint-staged": "15.2.10",
"lint-staged": "15.2.11",
"mocha": "11.0.1",
"npm-run-all": "4.1.5",
"nyc": "17.1.0",
"prettier": "3.4.1",
"rollup": "4.28.0",
"prettier": "3.4.2",
"rollup": "4.28.1",
"size-limit": "11.1.6",

@@ -103,0 +103,0 @@ "ts-node": "10.9.2",

@@ -47,1 +47,9 @@ /**

);
export const CARRIAGE_RETURN = '\r';
export const CARRIAGE_RETURN_REGEX = new RegExp(CARRIAGE_RETURN, 'g');
export const CARRIAGE_RETURN_PLACEHOLDER = `__HTML_DOM_PARSER_CARRIAGE_RETURN_PLACEHOLDER_${Date.now()}__`;
export const CARRIAGE_RETURN_PLACEHOLDER_REGEX = new RegExp(
CARRIAGE_RETURN_PLACEHOLDER,
'g',
);
import { Comment, Element, ProcessingInstruction, Text } from 'domhandler';
import type { DOMNode } from '../types';
import { CASE_SENSITIVE_TAG_NAMES_MAP } from './constants';
import {
CARRIAGE_RETURN,
CARRIAGE_RETURN_PLACEHOLDER,
CARRIAGE_RETURN_PLACEHOLDER_REGEX,
CARRIAGE_RETURN_REGEX,
CASE_SENSITIVE_TAG_NAMES_MAP,
} from './constants';

@@ -61,3 +67,3 @@ /**

export function escapeSpecialCharacters(html: string): string {
return html.replace(/\r/g, '\\r');
return html.replace(CARRIAGE_RETURN_REGEX, CARRIAGE_RETURN_PLACEHOLDER);
}

@@ -72,3 +78,3 @@

export function revertEscapedCharacters(text: string): string {
return text.replace(/\\r/g, '\r');
return text.replace(CARRIAGE_RETURN_PLACEHOLDER_REGEX, CARRIAGE_RETURN);
}

@@ -75,0 +81,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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