Socket
Socket
Sign inDemoInstall

node-html-parser

Package Overview
Dependencies
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-html-parser - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

55

dist/esm/nodes/html.js

@@ -482,2 +482,57 @@ import he from 'he';

/**
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
* @param selector a DOMString containing a selector list
*/
closest(selector) {
const mapChild = new Map();
let el = this;
let old = null;
function findOne(test, elems) {
let elem = null;
for (let i = 0, l = elems.length; i < l && !elem; i++) {
const el = elems[i];
if (test(el)) {
elem = el;
}
else {
const child = mapChild.get(el);
if (child) {
elem = findOne(test, [child]);
}
}
}
return elem;
}
while (el) {
mapChild.set(el, old);
old = el;
el = el.parentNode;
}
el = this;
while (el) {
const e = selectOne(selector, el, {
xmlMode: true,
adapter: {
...Matcher,
getChildren(node) {
const child = mapChild.get(node);
return child && [child];
},
getSiblings(node) {
return [node];
},
findOne,
findAll() {
return [];
}
}
});
if (e) {
return e;
}
el = el.parentNode;
}
return null;
}
/**
* Append a child node to childNodes

@@ -484,0 +539,0 @@ * @param {Node} node node to append

@@ -19,2 +19,13 @@ var __extends = (this && this.__extends) || (function () {

};
var __assign = (this && this.__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);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {

@@ -737,2 +748,54 @@ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)

/**
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
* @param selector a DOMString containing a selector list
*/
HTMLElement.prototype.closest = function (selector) {
var mapChild = new Map();
var el = this;
var old = null;
function findOne(test, elems) {
var elem = null;
for (var i = 0, l = elems.length; i < l && !elem; i++) {
var el_1 = elems[i];
if (test(el_1)) {
elem = el_1;
}
else {
var child = mapChild.get(el_1);
if (child) {
elem = findOne(test, [child]);
}
}
}
return elem;
}
while (el) {
mapChild.set(el, old);
old = el;
el = el.parentNode;
}
el = this;
while (el) {
var e = css_select_1.selectOne(selector, el, {
xmlMode: true,
adapter: __assign(__assign({}, matcher_1.default), { getChildren: function (node) {
var child = mapChild.get(node);
return child && [child];
},
getSiblings: function (node) {
return [node];
},
findOne: findOne,
findAll: function () {
return [];
} })
});
if (e) {
return e;
}
el = el.parentNode;
}
return null;
};
/**
* Append a child node to childNodes

@@ -739,0 +802,0 @@ * @param {Node} node node to append

@@ -126,2 +126,7 @@ import Node from './node';

/**
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
* @param selector a DOMString containing a selector list
*/
closest(selector: string): Node;
/**
* Append a child node to childNodes

@@ -128,0 +133,0 @@ * @param {Node} node node to append

@@ -17,2 +17,13 @@ "use strict";

})();
var __assign = (this && this.__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);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {

@@ -563,2 +574,54 @@ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)

/**
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
* @param selector a DOMString containing a selector list
*/
HTMLElement.prototype.closest = function (selector) {
var mapChild = new Map();
var el = this;
var old = null;
function findOne(test, elems) {
var elem = null;
for (var i = 0, l = elems.length; i < l && !elem; i++) {
var el_1 = elems[i];
if (test(el_1)) {
elem = el_1;
}
else {
var child = mapChild.get(el_1);
if (child) {
elem = findOne(test, [child]);
}
}
}
return elem;
}
while (el) {
mapChild.set(el, old);
old = el;
el = el.parentNode;
}
el = this;
while (el) {
var e = css_select_1.selectOne(selector, el, {
xmlMode: true,
adapter: __assign(__assign({}, matcher_1.default), { getChildren: function (node) {
var child = mapChild.get(node);
return child && [child];
},
getSiblings: function (node) {
return [node];
},
findOne: findOne,
findAll: function () {
return [];
} })
});
if (e) {
return e;
}
el = el.parentNode;
}
return null;
};
/**
* Append a child node to childNodes

@@ -565,0 +628,0 @@ * @param {Node} node node to append

4

package.json
{
"name": "node-html-parser",
"version": "3.2.0",
"version": "3.3.0",
"description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.",

@@ -18,3 +18,3 @@ "main": "dist/index.js",

"pretest": "tsc -m commonjs",
"release": "np"
"release": "yarn build && np"
},

@@ -21,0 +21,0 @@ "keywords": [

# Fast HTML Parser [![NPM version](https://badge.fury.io/js/node-html-parser.png)](http://badge.fury.io/js/node-html-parser) [![Build Status](https://travis-ci.org/taoqf/node-html-parser.svg?branch=master)](https://travis-ci.org/taoqf/node-html-parser)
Fast HTML Parser is a _very fast_ HTML parser. Which will generate a simplified
DOM tree, with basic element query support.
DOM tree, with element query support.

@@ -115,2 +115,6 @@ Per the design, it intends to parse massive HTML files in lowest price, thus the

### HTMLElement#closest(selector)
Query closest element by css selector.
### HTMLElement#appendChild(node)

@@ -117,0 +121,0 @@

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