Socket
Socket
Sign inDemoInstall

domhandler

Package Overview
Dependencies
1
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.1.0

readme.md

40

lib/index.d.ts
import { Node, Element, DataNode, NodeWithChildren } from "./node";
export { Node, NodeWithChildren, DataNode, Element };
export interface DomHandlerOptions {
/***
* Indicates whether the whitespace in text nodes should be normalized
* (= all whitespace should be replaced with single spaces). The default value is "false".
*/
normalizeWhitespace?: boolean;
/***
* Indicates whether a startIndex property will be added to nodes.
* When the parser is used in a non-streaming fashion, startIndex is an integer
/**
* Add a `startIndex` property to nodes.
* When the parser is used in a non-streaming fashion, `startIndex` is an integer
* indicating the position of the start of the node in the document.
* The default value is "false".
*
* @default false
*/
withStartIndices?: boolean;
/***
* Indicates whether a endIndex property will be added to nodes.
* When the parser is used in a non-streaming fashion, endIndex is an integer
/**
* Add an `endIndex` property to nodes.
* When the parser is used in a non-streaming fashion, `endIndex` is an integer
* indicating the position of the end of the node in the document.
* The default value is "false".
*
* @default false
*/
withEndIndices?: boolean;
/**
* Replace all whitespace with single spaces.
*
* **Note:** Enabling this might break your markup.
*
* @default false
* @deprecated
*/
normalizeWhitespace?: boolean;
}

@@ -34,7 +40,7 @@ interface ParserInterface {

/** Called once parsing has completed. */
private _callback;
private readonly _callback;
/** Settings for the handler. */
private _options;
private readonly _options;
/** Callback whenever a tag is closed. */
private _elementCB;
private readonly _elementCB;
/** Indicated whether parsing has been completed. */

@@ -49,4 +55,2 @@ private _done;

/**
* Initiate a new DomHandler.
*
* @param callback Called once parsing has completed.

@@ -53,0 +57,0 @@ * @param options Settings for the handler.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DomHandler = exports.Element = exports.DataNode = exports.NodeWithChildren = exports.Node = void 0;
var node_1 = require("./node");
exports.Node = node_1.Node;
exports.Element = node_1.Element;
exports.DataNode = node_1.DataNode;
exports.NodeWithChildren = node_1.NodeWithChildren;
Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return node_1.Node; } });
Object.defineProperty(exports, "Element", { enumerable: true, get: function () { return node_1.Element; } });
Object.defineProperty(exports, "DataNode", { enumerable: true, get: function () { return node_1.DataNode; } });
Object.defineProperty(exports, "NodeWithChildren", { enumerable: true, get: function () { return node_1.NodeWithChildren; } });
var reWhitespace = /\s+/g;

@@ -13,8 +14,6 @@ // Default options

withStartIndices: false,
withEndIndices: false
withEndIndices: false,
};
var DomHandler = /** @class */ (function () {
/**
* Initiate a new DomHandler.
*
* @param callback Called once parsing has completed.

@@ -44,5 +43,5 @@ * @param options Settings for the handler.

}
this._callback = callback || null;
this._options = options || defaultOpts;
this._elementCB = elementCB || null;
this._callback = callback !== null && callback !== void 0 ? callback : null;
this._options = options !== null && options !== void 0 ? options : defaultOpts;
this._elementCB = elementCB !== null && elementCB !== void 0 ? elementCB : null;
}

@@ -54,2 +53,3 @@ DomHandler.prototype.onparserinit = function (parser) {

DomHandler.prototype.onreset = function () {
var _a;
this.dom = [];

@@ -59,3 +59,3 @@ this._done = false;

this._lastNode = null;
this._parser = this._parser || null;
this._parser = (_a = this._parser) !== null && _a !== void 0 ? _a : null;
};

@@ -75,3 +75,2 @@ // Signals the handler that parsing is done

this._lastNode = null;
// If(this._tagStack.pop().name !== name) this.handleCallback(Error("Tagname didn't match!"));
var elem = this._tagStack.pop();

@@ -78,0 +77,0 @@ if (!elem || !this._parser) {

import { ElementType } from "domelementtype";
/**
* This object will be used as the prototype for Nodes when creating a
* DOM-Level-1-compliant structure.
*/
export declare class Node {

@@ -19,6 +23,9 @@ type: ElementType;

constructor(type: ElementType);
readonly nodeType: number;
parentNode: NodeWithChildren | null;
previousSibling: Node | null;
nextSibling: Node | null;
get nodeType(): number;
get parentNode(): NodeWithChildren | null;
set parentNode(parent: NodeWithChildren | null);
get previousSibling(): Node | null;
set previousSibling(prev: Node | null);
get nextSibling(): Node | null;
set nextSibling(next: Node | null);
}

@@ -33,3 +40,4 @@ export declare class DataNode extends Node {

constructor(type: ElementType.Comment | ElementType.Text | ElementType.Directive, data: string);
nodeValue: string;
get nodeValue(): string;
set nodeValue(data: string);
}

@@ -48,5 +56,6 @@ export declare class ProcessingInstruction extends DataNode {

constructor(type: ElementType.CDATA | ElementType.Script | ElementType.Style | ElementType.Tag, children: Node[]);
readonly firstChild: Node | null;
readonly lastChild: Node | null;
childNodes: Node[];
get firstChild(): Node | null;
get lastChild(): Node | null;
get childNodes(): Node[];
set childNodes(children: Node[]);
}

@@ -66,4 +75,5 @@ export declare class Element extends NodeWithChildren {

});
tagName: string;
get tagName(): string;
set tagName(name: string);
}
//# sourceMappingURL=node.d.ts.map

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

({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);

@@ -17,2 +17,3 @@ };

Object.defineProperty(exports, "__esModule", { value: true });
exports.Element = exports.NodeWithChildren = exports.ProcessingInstruction = exports.DataNode = exports.Node = void 0;
var nodeTypes = new Map([

@@ -25,6 +26,8 @@ ["tag" /* Tag */, 1],

["cdata" /* CDATA */, 4],
["comment" /* Comment */, 8]
["comment" /* Comment */, 8],
]);
// This object will be used as the prototype for Nodes when creating a
// DOM-Level-1-compliant structure.
/**
* This object will be used as the prototype for Nodes when creating a
* DOM-Level-1-compliant structure.
*/
var Node = /** @class */ (function () {

@@ -51,5 +54,6 @@ /**

get: function () {
return nodeTypes.get(this.type) || 1;
var _a;
return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
},
enumerable: true,
enumerable: false,
configurable: true

@@ -60,3 +64,3 @@ });

get: function () {
return this.parent || null;
return this.parent;
},

@@ -66,3 +70,3 @@ set: function (parent) {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -72,3 +76,3 @@ });

get: function () {
return this.prev || null;
return this.prev;
},

@@ -78,3 +82,3 @@ set: function (prev) {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -84,3 +88,3 @@ });

get: function () {
return this.next || null;
return this.next;
},

@@ -90,3 +94,3 @@ set: function (next) {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -116,3 +120,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -148,5 +152,6 @@ });

get: function () {
return this.children[0] || null;
var _a;
return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
},
enumerable: true,
enumerable: false,
configurable: true

@@ -156,5 +161,7 @@ });

get: function () {
return this.children[this.children.length - 1] || null;
return this.children.length > 0
? this.children[this.children.length - 1]
: null;
},
enumerable: true,
enumerable: false,
configurable: true

@@ -169,3 +176,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -202,3 +209,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -205,0 +212,0 @@ });

{
"name": "domhandler",
"version": "3.0.0",
"version": "3.1.0",
"description": "Handler for htmlparser2 that turns pages into a dom",
"author": "Felix Boehm <me@feedic.com>",
"funding": "https://github.com/fb55/domhandler?sponsor=1",
"license": "BSD-2-Clause",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"sideEffects": false,
"files": [
"lib"
],
"scripts": {
"test": "jest --coverage && npm run lint",
"coverage": "cat coverage/lcov.info | coveralls",
"lint": "eslint src/**/*.ts",
"lint": "eslint src",
"format": "prettier --write '**/*.{ts,md,json}'",

@@ -16,3 +24,3 @@ "build": "tsc",

"type": "git",
"url": "git://github.com/fb55/DomHandler.git"
"url": "git://github.com/fb55/domhandler.git"
},

@@ -30,19 +38,15 @@ "keywords": [

"devDependencies": {
"@types/htmlparser2": "^3.10.1",
"@types/jest": "^24.0.16",
"@types/node": "^12.6.8",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^1.13.0",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.9",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"coveralls": "^3.0.5",
"eslint": "^6.1.0",
"eslint": "^7.9.0",
"eslint-config-prettier": "^6.0.0",
"eslint-config-xo-typescript": "^0.15.0",
"htmlparser2": "^3.9.0",
"jest": "^24.8.0",
"prettier": "^1.18.2",
"ts-jest": "^24.0.2",
"typescript": "^3.5.3"
"htmlparser2": "^4.1.0",
"jest": "^26.0.1",
"prettier": "^2.0.5",
"ts-jest": "^26.1.0",
"typescript": "^4.0.2"
},
"author": "Felix Boehm <me@feedic.com>",
"license": "BSD-2-Clause",
"jest": {

@@ -49,0 +53,0 @@ "preset": "ts-jest",

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc