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.3.6 to 4.0.0

4

dist/esm/nodes/html.js

@@ -245,3 +245,3 @@ import he from 'he';

get textContent() {
return this.rawText;
return decode(this.rawText);
}

@@ -424,3 +424,3 @@ set textContent(val) {

}
node.rawText = node.trimmedText;
node.rawText = node.trimmedRawText;
}

@@ -427,0 +427,0 @@ else if (node.nodeType === NodeType.ELEMENT_NODE) {

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

import { decode, encode } from 'he';
/**

@@ -13,7 +14,7 @@ * Node Class as base class for TextNode and HTMLElement.

get textContent() {
return this.rawText;
return decode(this.rawText);
}
set textContent(val) {
this.rawText = val;
this.rawText = encode(val);
}
}

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

import { decode } from 'he';
import Node from './node';
import NodeType from './type';
import Node from './node';
/**

@@ -10,3 +11,2 @@ * TextNode to contain a text element in DOM tree.

super(parentNode);
this.rawText = rawText;
/**

@@ -17,4 +17,25 @@ * Node Type declaration.

this.nodeType = NodeType.TEXT_NODE;
this._rawText = rawText;
}
get rawText() {
return this._rawText;
}
/**
* Set rawText and invalidate trimmed caches
*/
set rawText(text) {
this._rawText = text;
this._trimmedRawText = void 0;
this._trimmedText = void 0;
}
/**
* Returns raw text with all whitespace trimmed except single leading/trailing non-breaking space
*/
get trimmedRawText() {
if (this._trimmedRawText !== undefined)
return this._trimmedRawText;
this._trimmedRawText = trimText(this.rawText);
return this._trimmedRawText;
}
/**
* Returns text with all whitespace trimmed except single leading/trailing non-breaking space

@@ -25,29 +46,3 @@ */

return this._trimmedText;
const text = this.rawText;
let i = 0;
let startPos;
let endPos;
while (i >= 0 && i < text.length) {
if (/\S/.test(text[i])) {
if (startPos === undefined) {
startPos = i;
i = text.length;
}
else {
endPos = i;
i = void 0;
}
}
if (startPos === undefined)
i++;
else
i--;
}
if (startPos === undefined)
startPos = 0;
if (endPos === undefined)
endPos = text.length - 1;
const hasLeadingSpace = startPos > 0 && /[^\S\r\n]/.test(text[startPos - 1]);
const hasTrailingSpace = endPos < (text.length - 1) && /[^\S\r\n]/.test(text[endPos + 1]);
this._trimmedText = (hasLeadingSpace ? ' ' : '') + text.slice(startPos, endPos + 1) + (hasTrailingSpace ? ' ' : '');
this._trimmedText = trimText(this.text);
return this._trimmedText;

@@ -60,7 +55,7 @@ }

get text() {
return this.rawText;
return decode(this.rawText);
}
/**
* Detect if the node contains only white space.
* @return {bool}
* @return {boolean}
*/

@@ -71,4 +66,35 @@ get isWhitespace() {

toString() {
return this.text;
return this.rawText;
}
}
/**
* Trim whitespace except single leading/trailing non-breaking space
*/
function trimText(text) {
let i = 0;
let startPos;
let endPos;
while (i >= 0 && i < text.length) {
if (/\S/.test(text[i])) {
if (startPos === undefined) {
startPos = i;
i = text.length;
}
else {
endPos = i;
i = void 0;
}
}
if (startPos === undefined)
i++;
else
i--;
}
if (startPos === undefined)
startPos = 0;
if (endPos === undefined)
endPos = text.length - 1;
const hasLeadingSpace = startPos > 0 && /[^\S\r\n]/.test(text[startPos - 1]);
const hasTrailingSpace = endPos < (text.length - 1) && /[^\S\r\n]/.test(text[endPos + 1]);
return (hasLeadingSpace ? ' ' : '') + text.slice(startPos, endPos + 1) + (hasTrailingSpace ? ' ' : '');
}

@@ -54,7 +54,7 @@ var __extends = (this && this.__extends) || (function () {

});
define("nodes/text", ["require", "exports", "nodes/type", "nodes/node"], function (require, exports, type_1, node_1) {
define("nodes/text", ["require", "exports", "he", "nodes/node", "nodes/type"], function (require, exports, he_1, node_1, type_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
node_1 = __importDefault(node_1);
type_1 = __importDefault(type_1);
node_1 = __importDefault(node_1);
/**

@@ -68,3 +68,2 @@ * TextNode to contain a text element in DOM tree.

var _this = _super.call(this, parentNode) || this;
_this.rawText = rawText;
/**

@@ -75,4 +74,33 @@ * Node Type declaration.

_this.nodeType = type_1.default.TEXT_NODE;
_this._rawText = rawText;
return _this;
}
Object.defineProperty(TextNode.prototype, "rawText", {
get: function () {
return this._rawText;
},
/**
* Set rawText and invalidate trimmed caches
*/
set: function (text) {
this._rawText = text;
this._trimmedRawText = void 0;
this._trimmedText = void 0;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TextNode.prototype, "trimmedRawText", {
/**
* Returns raw text with all whitespace trimmed except single leading/trailing non-breaking space
*/
get: function () {
if (this._trimmedRawText !== undefined)
return this._trimmedRawText;
this._trimmedRawText = trimText(this.rawText);
return this._trimmedRawText;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TextNode.prototype, "trimmedText", {

@@ -85,29 +113,3 @@ /**

return this._trimmedText;
var text = this.rawText;
var i = 0;
var startPos;
var endPos;
while (i >= 0 && i < text.length) {
if (/\S/.test(text[i])) {
if (startPos === undefined) {
startPos = i;
i = text.length;
}
else {
endPos = i;
i = void 0;
}
}
if (startPos === undefined)
i++;
else
i--;
}
if (startPos === undefined)
startPos = 0;
if (endPos === undefined)
endPos = text.length - 1;
var hasLeadingSpace = startPos > 0 && /[^\S\r\n]/.test(text[startPos - 1]);
var hasTrailingSpace = endPos < (text.length - 1) && /[^\S\r\n]/.test(text[endPos + 1]);
this._trimmedText = (hasLeadingSpace ? ' ' : '') + text.slice(startPos, endPos + 1) + (hasTrailingSpace ? ' ' : '');
this._trimmedText = trimText(this.text);
return this._trimmedText;

@@ -124,3 +126,3 @@ },

get: function () {
return this.rawText;
return he_1.decode(this.rawText);
},

@@ -133,3 +135,3 @@ enumerable: false,

* Detect if the node contains only white space.
* @return {bool}
* @return {boolean}
*/

@@ -143,3 +145,3 @@ get: function () {

TextNode.prototype.toString = function () {
return this.text;
return this.rawText;
};

@@ -149,2 +151,33 @@ return TextNode;

exports.default = TextNode;
/**
* Trim whitespace except single leading/trailing non-breaking space
*/
function trimText(text) {
var i = 0;
var startPos;
var endPos;
while (i >= 0 && i < text.length) {
if (/\S/.test(text[i])) {
if (startPos === undefined) {
startPos = i;
i = text.length;
}
else {
endPos = i;
i = void 0;
}
}
if (startPos === undefined)
i++;
else
i--;
}
if (startPos === undefined)
startPos = 0;
if (endPos === undefined)
endPos = text.length - 1;
var hasLeadingSpace = startPos > 0 && /[^\S\r\n]/.test(text[startPos - 1]);
var hasTrailingSpace = endPos < (text.length - 1) && /[^\S\r\n]/.test(text[endPos + 1]);
return (hasLeadingSpace ? ' ' : '') + text.slice(startPos, endPos + 1) + (hasTrailingSpace ? ' ' : '');
}
});

@@ -256,7 +289,7 @@ define("matcher", ["require", "exports", "nodes/type"], function (require, exports, type_2) {

});
define("nodes/html", ["require", "exports", "he", "css-select", "nodes/node", "nodes/type", "nodes/text", "matcher", "back", "nodes/comment"], function (require, exports, he_1, css_select_1, node_2, type_3, text_1, matcher_1, back_1, comment_1) {
define("nodes/html", ["require", "exports", "he", "css-select", "nodes/node", "nodes/type", "nodes/text", "matcher", "back", "nodes/comment"], function (require, exports, he_2, css_select_1, node_2, type_3, text_1, matcher_1, back_1, comment_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = exports.base_parse = void 0;
he_1 = __importDefault(he_1);
he_2 = __importDefault(he_2);
node_2 = __importDefault(node_2);

@@ -271,3 +304,3 @@ type_3 = __importDefault(type_3);

// clone string
return JSON.parse(JSON.stringify(he_1.default.decode(val)));
return JSON.parse(JSON.stringify(he_2.default.decode(val)));
}

@@ -533,3 +566,3 @@ // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements

get: function () {
return this.rawText;
return decode(this.rawText);
},

@@ -738,3 +771,3 @@ set: function (val) {

}
node.rawText = node.trimmedText;
node.rawText = node.trimmedRawText;
}

@@ -1455,3 +1488,3 @@ else if (node.nodeType === type_3.default.ELEMENT_NODE) {

});
define("nodes/node", ["require", "exports"], function (require, exports) {
define("nodes/node", ["require", "exports", "he"], function (require, exports, he_3) {
"use strict";

@@ -1477,6 +1510,6 @@ Object.defineProperty(exports, "__esModule", { value: true });

get: function () {
return this.rawText;
return he_3.decode(this.rawText);
},
set: function (val) {
this.rawText = val;
this.rawText = he_3.encode(val);
},

@@ -1483,0 +1516,0 @@ enumerable: false,

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

get: function () {
return this.rawText;
return decode(this.rawText);
},

@@ -515,3 +515,3 @@ set: function (val) {

}
node.rawText = node.trimmedText;
node.rawText = node.trimmedRawText;
}

@@ -518,0 +518,0 @@ else if (node.nodeType === type_1.default.ELEMENT_NODE) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var he_1 = require("he");
/**

@@ -21,6 +22,6 @@ * Node Class as base class for TextNode and HTMLElement.

get: function () {
return this.rawText;
return he_1.decode(this.rawText);
},
set: function (val) {
this.rawText = val;
this.rawText = he_1.encode(val);
},

@@ -27,0 +28,0 @@ enumerable: false,

@@ -0,4 +1,4 @@

import HTMLElement from './html';
import Node from './node';
import NodeType from './type';
import Node from './node';
import HTMLElement from './html';
/**

@@ -9,3 +9,2 @@ * TextNode to contain a text element in DOM tree.

export default class TextNode extends Node {
rawText: string;
constructor(rawText: string, parentNode: HTMLElement);

@@ -17,4 +16,15 @@ /**

nodeType: NodeType;
private _rawText;
private _trimmedRawText?;
private _trimmedText?;
get rawText(): string;
/**
* Set rawText and invalidate trimmed caches
*/
set rawText(text: string);
/**
* Returns raw text with all whitespace trimmed except single leading/trailing non-breaking space
*/
get trimmedRawText(): string;
/**
* Returns text with all whitespace trimmed except single leading/trailing non-breaking space

@@ -30,3 +40,3 @@ */

* Detect if the node contains only white space.
* @return {bool}
* @return {boolean}
*/

@@ -33,0 +43,0 @@ get isWhitespace(): boolean;

@@ -21,4 +21,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var he_1 = require("he");
var node_1 = __importDefault(require("./node"));
var type_1 = __importDefault(require("./type"));
var node_1 = __importDefault(require("./node"));
/**

@@ -32,3 +33,2 @@ * TextNode to contain a text element in DOM tree.

var _this = _super.call(this, parentNode) || this;
_this.rawText = rawText;
/**

@@ -39,4 +39,33 @@ * Node Type declaration.

_this.nodeType = type_1.default.TEXT_NODE;
_this._rawText = rawText;
return _this;
}
Object.defineProperty(TextNode.prototype, "rawText", {
get: function () {
return this._rawText;
},
/**
* Set rawText and invalidate trimmed caches
*/
set: function (text) {
this._rawText = text;
this._trimmedRawText = void 0;
this._trimmedText = void 0;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TextNode.prototype, "trimmedRawText", {
/**
* Returns raw text with all whitespace trimmed except single leading/trailing non-breaking space
*/
get: function () {
if (this._trimmedRawText !== undefined)
return this._trimmedRawText;
this._trimmedRawText = trimText(this.rawText);
return this._trimmedRawText;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TextNode.prototype, "trimmedText", {

@@ -49,29 +78,3 @@ /**

return this._trimmedText;
var text = this.rawText;
var i = 0;
var startPos;
var endPos;
while (i >= 0 && i < text.length) {
if (/\S/.test(text[i])) {
if (startPos === undefined) {
startPos = i;
i = text.length;
}
else {
endPos = i;
i = void 0;
}
}
if (startPos === undefined)
i++;
else
i--;
}
if (startPos === undefined)
startPos = 0;
if (endPos === undefined)
endPos = text.length - 1;
var hasLeadingSpace = startPos > 0 && /[^\S\r\n]/.test(text[startPos - 1]);
var hasTrailingSpace = endPos < (text.length - 1) && /[^\S\r\n]/.test(text[endPos + 1]);
this._trimmedText = (hasLeadingSpace ? ' ' : '') + text.slice(startPos, endPos + 1) + (hasTrailingSpace ? ' ' : '');
this._trimmedText = trimText(this.text);
return this._trimmedText;

@@ -88,3 +91,3 @@ },

get: function () {
return this.rawText;
return he_1.decode(this.rawText);
},

@@ -97,3 +100,3 @@ enumerable: false,

* Detect if the node contains only white space.
* @return {bool}
* @return {boolean}
*/

@@ -107,3 +110,3 @@ get: function () {

TextNode.prototype.toString = function () {
return this.text;
return this.rawText;
};

@@ -113,1 +116,32 @@ return TextNode;

exports.default = TextNode;
/**
* Trim whitespace except single leading/trailing non-breaking space
*/
function trimText(text) {
var i = 0;
var startPos;
var endPos;
while (i >= 0 && i < text.length) {
if (/\S/.test(text[i])) {
if (startPos === undefined) {
startPos = i;
i = text.length;
}
else {
endPos = i;
i = void 0;
}
}
if (startPos === undefined)
i++;
else
i--;
}
if (startPos === undefined)
startPos = 0;
if (endPos === undefined)
endPos = text.length - 1;
var hasLeadingSpace = startPos > 0 && /[^\S\r\n]/.test(text[startPos - 1]);
var hasTrailingSpace = endPos < (text.length - 1) && /[^\S\r\n]/.test(text[endPos + 1]);
return (hasLeadingSpace ? ' ' : '') + text.slice(startPos, endPos + 1) + (hasTrailingSpace ? ' ' : '');
}
{
"name": "node-html-parser",
"version": "3.3.6",
"version": "4.0.0",
"description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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