Socket
Socket
Sign inDemoInstall

htmlparser2

Package Overview
Dependencies
5
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.0.1 to 8.0.2

24

lib/esm/index.d.ts
import { Parser, ParserOptions } from "./Parser.js";
export { Parser, type ParserOptions };
import { DomHandler, DomHandlerOptions, ChildNode, Element, Document } from "domhandler";
export { DomHandler, type DomHandlerOptions };
declare type Options = ParserOptions & DomHandlerOptions;
export { Parser, type ParserOptions } from "./Parser.js";
import { DomHandlerOptions, ChildNode, Element, Document } from "domhandler";
export { DomHandler, DomHandler as DefaultHandler, type DomHandlerOptions, } from "domhandler";
export type Options = ParserOptions & DomHandlerOptions;
/**

@@ -27,12 +27,11 @@ * Parses the data, returns the resulting document.

*
* @param cb A callback that will be called once parsing has been completed.
* @param callback A callback that will be called once parsing has been completed.
* @param options Optional options for the parser and DOM builder.
* @param elementCb An optional callback that will be called every time a tag has been completed inside of the DOM.
* @param elementCallback An optional callback that will be called every time a tag has been completed inside of the DOM.
*/
export declare function createDomStream(cb: (error: Error | null, dom: ChildNode[]) => void, options?: Options, elementCb?: (element: Element) => void): Parser;
export declare function createDomStream(callback: (error: Error | null, dom: ChildNode[]) => void, options?: Options, elementCallback?: (element: Element) => void): Parser;
export { default as Tokenizer, type Callbacks as TokenizerCallbacks, } from "./Tokenizer.js";
import * as ElementType from "domelementtype";
export { ElementType };
import { getFeed, Feed } from "domutils";
export { getFeed };
export * as ElementType from "domelementtype";
import { Feed } from "domutils";
export { getFeed } from "domutils";
/**

@@ -44,5 +43,4 @@ * Parse a feed.

*/
export declare function parseFeed(feed: string, options?: ParserOptions & DomHandlerOptions): Feed | null;
export declare function parseFeed(feed: string, options?: Options): Feed | null;
export * as DomUtils from "domutils";
export { DomHandler as DefaultHandler };
//# sourceMappingURL=index.d.ts.map
import { Parser } from "./Parser.js";
export { Parser };
export { Parser } from "./Parser.js";
import { DomHandler, } from "domhandler";
export { DomHandler };
export { DomHandler,
// Old name for DomHandler
DomHandler as DefaultHandler, } from "domhandler";
// Helper methods

@@ -33,8 +35,8 @@ /**

*
* @param cb A callback that will be called once parsing has been completed.
* @param callback A callback that will be called once parsing has been completed.
* @param options Optional options for the parser and DOM builder.
* @param elementCb An optional callback that will be called every time a tag has been completed inside of the DOM.
* @param elementCallback An optional callback that will be called every time a tag has been completed inside of the DOM.
*/
export function createDomStream(cb, options, elementCb) {
const handler = new DomHandler(cb, options, elementCb);
export function createDomStream(callback, options, elementCallback) {
const handler = new DomHandler(callback, options, elementCallback);
return new Parser(handler, options);

@@ -47,6 +49,6 @@ }

*/
import * as ElementType from "domelementtype";
export { ElementType };
export * as ElementType from "domelementtype";
import { getFeed } from "domutils";
export { getFeed };
export { getFeed } from "domutils";
const parseFeedDefaultOptions = { xmlMode: true };
/**

@@ -58,8 +60,6 @@ * Parse a feed.

*/
export function parseFeed(feed, options = { xmlMode: true }) {
export function parseFeed(feed, options = parseFeedDefaultOptions) {
return getFeed(parseDOM(feed, options));
}
export * as DomUtils from "domutils";
// Old name for DomHandler
export { DomHandler as DefaultHandler };
//# sourceMappingURL=index.js.map

@@ -94,3 +94,3 @@ import Tokenizer, { Callbacks, QuoteType } from "./Tokenizer.js";

private attribs;
private stack;
private readonly stack;
private readonly foreignContext;

@@ -97,0 +97,0 @@ private readonly cbs;

@@ -147,6 +147,6 @@ import Tokenizer, { QuoteType } from "./Tokenizer.js";

*/
const idx = this.tokenizer.getSectionStart();
this.endIndex = idx - 1;
const index = this.tokenizer.getSectionStart();
this.endIndex = index - 1;
(_b = (_a = this.cbs).ontext) === null || _b === void 0 ? void 0 : _b.call(_a, fromCodePoint(cp));
this.startIndex = idx;
this.startIndex = index;
}

@@ -173,4 +173,4 @@ isVoidElement(name) {

impliesClose.has(this.stack[this.stack.length - 1])) {
const el = this.stack.pop();
(_b = (_a = this.cbs).onclosetag) === null || _b === void 0 ? void 0 : _b.call(_a, el, true);
const element = this.stack.pop();
(_b = (_a = this.cbs).onclosetag) === null || _b === void 0 ? void 0 : _b.call(_a, element, true);
}

@@ -310,4 +310,4 @@ }

getInstructionName(value) {
const idx = value.search(reNameEnd);
let name = idx < 0 ? value : value.substr(0, idx);
const index = value.search(reNameEnd);
let name = index < 0 ? value : value.substr(0, index);
if (this.lowerCaseTagNames) {

@@ -372,3 +372,3 @@ name = name.toLowerCase();

this.endIndex = this.startIndex;
for (let i = this.stack.length; i > 0; this.cbs.onclosetag(this.stack[--i], true))
for (let index = this.stack.length; index > 0; this.cbs.onclosetag(this.stack[--index], true))
;

@@ -411,8 +411,8 @@ }

}
let str = this.buffers[0].slice(start - this.bufferOffset, end - this.bufferOffset);
let slice = this.buffers[0].slice(start - this.bufferOffset, end - this.bufferOffset);
while (end - this.bufferOffset > this.buffers[0].length) {
this.shiftBuffer();
str += this.buffers[0].slice(0, end - this.bufferOffset);
slice += this.buffers[0].slice(0, end - this.bufferOffset);
}
return str;
return slice;
}

@@ -449,3 +449,3 @@ shiftBuffer() {

if (this.ended) {
(_b = (_a = this.cbs).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, Error(".end() after done!"));
(_b = (_a = this.cbs).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, new Error(".end() after done!"));
return;

@@ -452,0 +452,0 @@ }

@@ -10,3 +10,3 @@ import { htmlDecodeTree, xmlDecodeTree, BinTrieFlags, determineBranch, replaceCodePoint, } from "entities/lib/decode.js";

CharCodes[CharCodes["ExclamationMark"] = 33] = "ExclamationMark";
CharCodes[CharCodes["Num"] = 35] = "Num";
CharCodes[CharCodes["Number"] = 35] = "Number";
CharCodes[CharCodes["Amp"] = 38] = "Amp";

@@ -132,2 +132,3 @@ CharCodes[CharCodes["SingleQuote"] = 39] = "SingleQuote";

this.offset = 0;
this.currentSequence = undefined;
this.sequenceIndex = 0;

@@ -401,2 +402,3 @@ this.trieIndex = 0;

this.state = State.Text;
this.baseState = State.Text;
this.sectionStart = this.index + 1;

@@ -573,3 +575,3 @@ }

this.entityResult = 0;
if (c === CharCodes.Num) {
if (c === CharCodes.Number) {
this.state = State.BeforeNumericEntity;

@@ -630,9 +632,11 @@ }

switch (valueLength) {
case 1:
case 1: {
this.emitCodePoint(this.entityTrie[this.entityResult] &
~BinTrieFlags.VALUE_LENGTH);
break;
case 2:
}
case 2: {
this.emitCodePoint(this.entityTrie[this.entityResult + 1]);
break;
}
case 3: {

@@ -743,90 +747,120 @@ this.emitCodePoint(this.entityTrie[this.entityResult + 1]);

const c = this.buffer.charCodeAt(this.index - this.offset);
if (this.state === State.Text) {
this.stateText(c);
switch (this.state) {
case State.Text: {
this.stateText(c);
break;
}
case State.SpecialStartSequence: {
this.stateSpecialStartSequence(c);
break;
}
case State.InSpecialTag: {
this.stateInSpecialTag(c);
break;
}
case State.CDATASequence: {
this.stateCDATASequence(c);
break;
}
case State.InAttributeValueDq: {
this.stateInAttributeValueDoubleQuotes(c);
break;
}
case State.InAttributeName: {
this.stateInAttributeName(c);
break;
}
case State.InCommentLike: {
this.stateInCommentLike(c);
break;
}
case State.InSpecialComment: {
this.stateInSpecialComment(c);
break;
}
case State.BeforeAttributeName: {
this.stateBeforeAttributeName(c);
break;
}
case State.InTagName: {
this.stateInTagName(c);
break;
}
case State.InClosingTagName: {
this.stateInClosingTagName(c);
break;
}
case State.BeforeTagName: {
this.stateBeforeTagName(c);
break;
}
case State.AfterAttributeName: {
this.stateAfterAttributeName(c);
break;
}
case State.InAttributeValueSq: {
this.stateInAttributeValueSingleQuotes(c);
break;
}
case State.BeforeAttributeValue: {
this.stateBeforeAttributeValue(c);
break;
}
case State.BeforeClosingTagName: {
this.stateBeforeClosingTagName(c);
break;
}
case State.AfterClosingTagName: {
this.stateAfterClosingTagName(c);
break;
}
case State.BeforeSpecialS: {
this.stateBeforeSpecialS(c);
break;
}
case State.InAttributeValueNq: {
this.stateInAttributeValueNoQuotes(c);
break;
}
case State.InSelfClosingTag: {
this.stateInSelfClosingTag(c);
break;
}
case State.InDeclaration: {
this.stateInDeclaration(c);
break;
}
case State.BeforeDeclaration: {
this.stateBeforeDeclaration(c);
break;
}
case State.BeforeComment: {
this.stateBeforeComment(c);
break;
}
case State.InProcessingInstruction: {
this.stateInProcessingInstruction(c);
break;
}
case State.InNamedEntity: {
this.stateInNamedEntity(c);
break;
}
case State.BeforeEntity: {
this.stateBeforeEntity(c);
break;
}
case State.InHexEntity: {
this.stateInHexEntity(c);
break;
}
case State.InNumericEntity: {
this.stateInNumericEntity(c);
break;
}
default: {
// `this._state === State.BeforeNumericEntity`
this.stateBeforeNumericEntity(c);
}
}
else if (this.state === State.SpecialStartSequence) {
this.stateSpecialStartSequence(c);
}
else if (this.state === State.InSpecialTag) {
this.stateInSpecialTag(c);
}
else if (this.state === State.CDATASequence) {
this.stateCDATASequence(c);
}
else if (this.state === State.InAttributeValueDq) {
this.stateInAttributeValueDoubleQuotes(c);
}
else if (this.state === State.InAttributeName) {
this.stateInAttributeName(c);
}
else if (this.state === State.InCommentLike) {
this.stateInCommentLike(c);
}
else if (this.state === State.InSpecialComment) {
this.stateInSpecialComment(c);
}
else if (this.state === State.BeforeAttributeName) {
this.stateBeforeAttributeName(c);
}
else if (this.state === State.InTagName) {
this.stateInTagName(c);
}
else if (this.state === State.InClosingTagName) {
this.stateInClosingTagName(c);
}
else if (this.state === State.BeforeTagName) {
this.stateBeforeTagName(c);
}
else if (this.state === State.AfterAttributeName) {
this.stateAfterAttributeName(c);
}
else if (this.state === State.InAttributeValueSq) {
this.stateInAttributeValueSingleQuotes(c);
}
else if (this.state === State.BeforeAttributeValue) {
this.stateBeforeAttributeValue(c);
}
else if (this.state === State.BeforeClosingTagName) {
this.stateBeforeClosingTagName(c);
}
else if (this.state === State.AfterClosingTagName) {
this.stateAfterClosingTagName(c);
}
else if (this.state === State.BeforeSpecialS) {
this.stateBeforeSpecialS(c);
}
else if (this.state === State.InAttributeValueNq) {
this.stateInAttributeValueNoQuotes(c);
}
else if (this.state === State.InSelfClosingTag) {
this.stateInSelfClosingTag(c);
}
else if (this.state === State.InDeclaration) {
this.stateInDeclaration(c);
}
else if (this.state === State.BeforeDeclaration) {
this.stateBeforeDeclaration(c);
}
else if (this.state === State.BeforeComment) {
this.stateBeforeComment(c);
}
else if (this.state === State.InProcessingInstruction) {
this.stateInProcessingInstruction(c);
}
else if (this.state === State.InNamedEntity) {
this.stateInNamedEntity(c);
}
else if (this.state === State.BeforeEntity) {
this.stateBeforeEntity(c);
}
else if (this.state === State.InHexEntity) {
this.stateInHexEntity(c);
}
else if (this.state === State.InNumericEntity) {
this.stateInNumericEntity(c);
}
else {
// `this._state === State.BeforeNumericEntity`
this.stateBeforeNumericEntity(c);
}
this.index++;

@@ -833,0 +867,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
import { Handler, ParserOptions } from "./Parser.js";
import { Writable } from "stream";
import { Writable } from "node:stream";
/**

@@ -13,5 +14,5 @@ * WritableStream makes the `Parser` interface available as a NodeJS stream.

constructor(cbs: Partial<Handler>, options?: ParserOptions);
_write(chunk: string | Buffer, encoding: string, cb: () => void): void;
_final(cb: () => void): void;
_write(chunk: string | Buffer, encoding: string, callback: () => void): void;
_final(callback: () => void): void;
}
//# sourceMappingURL=WritableStream.d.ts.map

@@ -6,4 +6,4 @@ import { Parser } from "./Parser.js";

*/
import { Writable } from "stream";
import { StringDecoder } from "string_decoder";
import { Writable } from "node:stream";
import { StringDecoder } from "node:string_decoder";
// Following the example in https://nodejs.org/api/stream.html#stream_decoding_buffers_in_a_writable_stream

@@ -24,11 +24,11 @@ function isBuffer(_chunk, encoding) {

}
_write(chunk, encoding, cb) {
_write(chunk, encoding, callback) {
this._parser.write(isBuffer(chunk, encoding) ? this._decoder.write(chunk) : chunk);
cb();
callback();
}
_final(cb) {
_final(callback) {
this._parser.end(this._decoder.end());
cb();
callback();
}
}
//# sourceMappingURL=WritableStream.js.map
import { Parser, ParserOptions } from "./Parser.js";
export { Parser, type ParserOptions };
import { DomHandler, DomHandlerOptions, ChildNode, Element, Document } from "domhandler";
export { DomHandler, type DomHandlerOptions };
declare type Options = ParserOptions & DomHandlerOptions;
export { Parser, type ParserOptions } from "./Parser.js";
import { DomHandlerOptions, ChildNode, Element, Document } from "domhandler";
export { DomHandler, DomHandler as DefaultHandler, type DomHandlerOptions, } from "domhandler";
export type Options = ParserOptions & DomHandlerOptions;
/**

@@ -27,12 +27,11 @@ * Parses the data, returns the resulting document.

*
* @param cb A callback that will be called once parsing has been completed.
* @param callback A callback that will be called once parsing has been completed.
* @param options Optional options for the parser and DOM builder.
* @param elementCb An optional callback that will be called every time a tag has been completed inside of the DOM.
* @param elementCallback An optional callback that will be called every time a tag has been completed inside of the DOM.
*/
export declare function createDomStream(cb: (error: Error | null, dom: ChildNode[]) => void, options?: Options, elementCb?: (element: Element) => void): Parser;
export declare function createDomStream(callback: (error: Error | null, dom: ChildNode[]) => void, options?: Options, elementCallback?: (element: Element) => void): Parser;
export { default as Tokenizer, type Callbacks as TokenizerCallbacks, } from "./Tokenizer.js";
import * as ElementType from "domelementtype";
export { ElementType };
import { getFeed, Feed } from "domutils";
export { getFeed };
export * as ElementType from "domelementtype";
import { Feed } from "domutils";
export { getFeed } from "domutils";
/**

@@ -44,5 +43,4 @@ * Parse a feed.

*/
export declare function parseFeed(feed: string, options?: ParserOptions & DomHandlerOptions): Feed | null;
export declare function parseFeed(feed: string, options?: Options): Feed | null;
export * as DomUtils from "domutils";
export { DomHandler as DefaultHandler };
//# sourceMappingURL=index.d.ts.map

@@ -29,8 +29,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultHandler = exports.DomUtils = exports.parseFeed = exports.getFeed = exports.ElementType = exports.Tokenizer = exports.createDomStream = exports.parseDOM = exports.parseDocument = exports.DomHandler = exports.Parser = void 0;
exports.DomUtils = exports.parseFeed = exports.getFeed = exports.ElementType = exports.Tokenizer = exports.createDomStream = exports.parseDOM = exports.parseDocument = exports.DefaultHandler = exports.DomHandler = exports.Parser = void 0;
var Parser_js_1 = require("./Parser.js");
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return Parser_js_1.Parser; } });
var Parser_js_2 = require("./Parser.js");
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return Parser_js_2.Parser; } });
var domhandler_1 = require("domhandler");
Object.defineProperty(exports, "DomHandler", { enumerable: true, get: function () { return domhandler_1.DomHandler; } });
Object.defineProperty(exports, "DefaultHandler", { enumerable: true, get: function () { return domhandler_1.DomHandler; } });
var domhandler_2 = require("domhandler");
Object.defineProperty(exports, "DomHandler", { enumerable: true, get: function () { return domhandler_2.DomHandler; } });
// Old name for DomHandler
Object.defineProperty(exports, "DefaultHandler", { enumerable: true, get: function () { return domhandler_2.DomHandler; } });
// Helper methods

@@ -66,8 +69,8 @@ /**

*
* @param cb A callback that will be called once parsing has been completed.
* @param callback A callback that will be called once parsing has been completed.
* @param options Optional options for the parser and DOM builder.
* @param elementCb An optional callback that will be called every time a tag has been completed inside of the DOM.
* @param elementCallback An optional callback that will be called every time a tag has been completed inside of the DOM.
*/
function createDomStream(cb, options, elementCb) {
var handler = new domhandler_1.DomHandler(cb, options, elementCb);
function createDomStream(callback, options, elementCallback) {
var handler = new domhandler_1.DomHandler(callback, options, elementCallback);
return new Parser_js_1.Parser(handler, options);

@@ -82,6 +85,7 @@ }

*/
var ElementType = __importStar(require("domelementtype"));
exports.ElementType = ElementType;
exports.ElementType = __importStar(require("domelementtype"));
var domutils_1 = require("domutils");
Object.defineProperty(exports, "getFeed", { enumerable: true, get: function () { return domutils_1.getFeed; } });
var domutils_2 = require("domutils");
Object.defineProperty(exports, "getFeed", { enumerable: true, get: function () { return domutils_2.getFeed; } });
var parseFeedDefaultOptions = { xmlMode: true };
/**

@@ -94,3 +98,3 @@ * Parse a feed.

function parseFeed(feed, options) {
if (options === void 0) { options = { xmlMode: true }; }
if (options === void 0) { options = parseFeedDefaultOptions; }
return (0, domutils_1.getFeed)(parseDOM(feed, options));

@@ -97,0 +101,0 @@ }

@@ -94,3 +94,3 @@ import Tokenizer, { Callbacks, QuoteType } from "./Tokenizer.js";

private attribs;
private stack;
private readonly stack;
private readonly foreignContext;

@@ -97,0 +97,0 @@ private readonly cbs;

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

*/
var idx = this.tokenizer.getSectionStart();
this.endIndex = idx - 1;
var index = this.tokenizer.getSectionStart();
this.endIndex = index - 1;
(_b = (_a = this.cbs).ontext) === null || _b === void 0 ? void 0 : _b.call(_a, (0, decode_js_1.fromCodePoint)(cp));
this.startIndex = idx;
this.startIndex = index;
};

@@ -200,4 +200,4 @@ Parser.prototype.isVoidElement = function (name) {

impliesClose.has(this.stack[this.stack.length - 1])) {
var el = this.stack.pop();
(_b = (_a = this.cbs).onclosetag) === null || _b === void 0 ? void 0 : _b.call(_a, el, true);
var element = this.stack.pop();
(_b = (_a = this.cbs).onclosetag) === null || _b === void 0 ? void 0 : _b.call(_a, element, true);
}

@@ -337,4 +337,4 @@ }

Parser.prototype.getInstructionName = function (value) {
var idx = value.search(reNameEnd);
var name = idx < 0 ? value : value.substr(0, idx);
var index = value.search(reNameEnd);
var name = index < 0 ? value : value.substr(0, index);
if (this.lowerCaseTagNames) {

@@ -399,3 +399,3 @@ name = name.toLowerCase();

this.endIndex = this.startIndex;
for (var i = this.stack.length; i > 0; this.cbs.onclosetag(this.stack[--i], true))
for (var index = this.stack.length; index > 0; this.cbs.onclosetag(this.stack[--index], true))
;

@@ -438,8 +438,8 @@ }

}
var str = this.buffers[0].slice(start - this.bufferOffset, end - this.bufferOffset);
var slice = this.buffers[0].slice(start - this.bufferOffset, end - this.bufferOffset);
while (end - this.bufferOffset > this.buffers[0].length) {
this.shiftBuffer();
str += this.buffers[0].slice(0, end - this.bufferOffset);
slice += this.buffers[0].slice(0, end - this.bufferOffset);
}
return str;
return slice;
};

@@ -476,3 +476,3 @@ Parser.prototype.shiftBuffer = function () {

if (this.ended) {
(_b = (_a = this.cbs).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, Error(".end() after done!"));
(_b = (_a = this.cbs).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, new Error(".end() after done!"));
return;

@@ -479,0 +479,0 @@ }

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

CharCodes[CharCodes["ExclamationMark"] = 33] = "ExclamationMark";
CharCodes[CharCodes["Num"] = 35] = "Num";
CharCodes[CharCodes["Number"] = 35] = "Number";
CharCodes[CharCodes["Amp"] = 38] = "Amp";

@@ -136,2 +136,3 @@ CharCodes[CharCodes["SingleQuote"] = 39] = "SingleQuote";

this.offset = 0;
this.currentSequence = undefined;
this.sequenceIndex = 0;

@@ -405,2 +406,3 @@ this.trieIndex = 0;

this.state = State.Text;
this.baseState = State.Text;
this.sectionStart = this.index + 1;

@@ -577,3 +579,3 @@ }

this.entityResult = 0;
if (c === CharCodes.Num) {
if (c === CharCodes.Number) {
this.state = State.BeforeNumericEntity;

@@ -634,9 +636,11 @@ }

switch (valueLength) {
case 1:
case 1: {
this.emitCodePoint(this.entityTrie[this.entityResult] &
~decode_js_1.BinTrieFlags.VALUE_LENGTH);
break;
case 2:
}
case 2: {
this.emitCodePoint(this.entityTrie[this.entityResult + 1]);
break;
}
case 3: {

@@ -747,90 +751,120 @@ this.emitCodePoint(this.entityTrie[this.entityResult + 1]);

var c = this.buffer.charCodeAt(this.index - this.offset);
if (this.state === State.Text) {
this.stateText(c);
switch (this.state) {
case State.Text: {
this.stateText(c);
break;
}
case State.SpecialStartSequence: {
this.stateSpecialStartSequence(c);
break;
}
case State.InSpecialTag: {
this.stateInSpecialTag(c);
break;
}
case State.CDATASequence: {
this.stateCDATASequence(c);
break;
}
case State.InAttributeValueDq: {
this.stateInAttributeValueDoubleQuotes(c);
break;
}
case State.InAttributeName: {
this.stateInAttributeName(c);
break;
}
case State.InCommentLike: {
this.stateInCommentLike(c);
break;
}
case State.InSpecialComment: {
this.stateInSpecialComment(c);
break;
}
case State.BeforeAttributeName: {
this.stateBeforeAttributeName(c);
break;
}
case State.InTagName: {
this.stateInTagName(c);
break;
}
case State.InClosingTagName: {
this.stateInClosingTagName(c);
break;
}
case State.BeforeTagName: {
this.stateBeforeTagName(c);
break;
}
case State.AfterAttributeName: {
this.stateAfterAttributeName(c);
break;
}
case State.InAttributeValueSq: {
this.stateInAttributeValueSingleQuotes(c);
break;
}
case State.BeforeAttributeValue: {
this.stateBeforeAttributeValue(c);
break;
}
case State.BeforeClosingTagName: {
this.stateBeforeClosingTagName(c);
break;
}
case State.AfterClosingTagName: {
this.stateAfterClosingTagName(c);
break;
}
case State.BeforeSpecialS: {
this.stateBeforeSpecialS(c);
break;
}
case State.InAttributeValueNq: {
this.stateInAttributeValueNoQuotes(c);
break;
}
case State.InSelfClosingTag: {
this.stateInSelfClosingTag(c);
break;
}
case State.InDeclaration: {
this.stateInDeclaration(c);
break;
}
case State.BeforeDeclaration: {
this.stateBeforeDeclaration(c);
break;
}
case State.BeforeComment: {
this.stateBeforeComment(c);
break;
}
case State.InProcessingInstruction: {
this.stateInProcessingInstruction(c);
break;
}
case State.InNamedEntity: {
this.stateInNamedEntity(c);
break;
}
case State.BeforeEntity: {
this.stateBeforeEntity(c);
break;
}
case State.InHexEntity: {
this.stateInHexEntity(c);
break;
}
case State.InNumericEntity: {
this.stateInNumericEntity(c);
break;
}
default: {
// `this._state === State.BeforeNumericEntity`
this.stateBeforeNumericEntity(c);
}
}
else if (this.state === State.SpecialStartSequence) {
this.stateSpecialStartSequence(c);
}
else if (this.state === State.InSpecialTag) {
this.stateInSpecialTag(c);
}
else if (this.state === State.CDATASequence) {
this.stateCDATASequence(c);
}
else if (this.state === State.InAttributeValueDq) {
this.stateInAttributeValueDoubleQuotes(c);
}
else if (this.state === State.InAttributeName) {
this.stateInAttributeName(c);
}
else if (this.state === State.InCommentLike) {
this.stateInCommentLike(c);
}
else if (this.state === State.InSpecialComment) {
this.stateInSpecialComment(c);
}
else if (this.state === State.BeforeAttributeName) {
this.stateBeforeAttributeName(c);
}
else if (this.state === State.InTagName) {
this.stateInTagName(c);
}
else if (this.state === State.InClosingTagName) {
this.stateInClosingTagName(c);
}
else if (this.state === State.BeforeTagName) {
this.stateBeforeTagName(c);
}
else if (this.state === State.AfterAttributeName) {
this.stateAfterAttributeName(c);
}
else if (this.state === State.InAttributeValueSq) {
this.stateInAttributeValueSingleQuotes(c);
}
else if (this.state === State.BeforeAttributeValue) {
this.stateBeforeAttributeValue(c);
}
else if (this.state === State.BeforeClosingTagName) {
this.stateBeforeClosingTagName(c);
}
else if (this.state === State.AfterClosingTagName) {
this.stateAfterClosingTagName(c);
}
else if (this.state === State.BeforeSpecialS) {
this.stateBeforeSpecialS(c);
}
else if (this.state === State.InAttributeValueNq) {
this.stateInAttributeValueNoQuotes(c);
}
else if (this.state === State.InSelfClosingTag) {
this.stateInSelfClosingTag(c);
}
else if (this.state === State.InDeclaration) {
this.stateInDeclaration(c);
}
else if (this.state === State.BeforeDeclaration) {
this.stateBeforeDeclaration(c);
}
else if (this.state === State.BeforeComment) {
this.stateBeforeComment(c);
}
else if (this.state === State.InProcessingInstruction) {
this.stateInProcessingInstruction(c);
}
else if (this.state === State.InNamedEntity) {
this.stateInNamedEntity(c);
}
else if (this.state === State.BeforeEntity) {
this.stateBeforeEntity(c);
}
else if (this.state === State.InHexEntity) {
this.stateInHexEntity(c);
}
else if (this.state === State.InNumericEntity) {
this.stateInNumericEntity(c);
}
else {
// `this._state === State.BeforeNumericEntity`
this.stateBeforeNumericEntity(c);
}
this.index++;

@@ -837,0 +871,0 @@ }

/// <reference types="node" />
/// <reference types="node" />
import { Handler, ParserOptions } from "./Parser.js";
import { Writable } from "stream";
import { Writable } from "node:stream";
/**

@@ -13,5 +14,5 @@ * WritableStream makes the `Parser` interface available as a NodeJS stream.

constructor(cbs: Partial<Handler>, options?: ParserOptions);
_write(chunk: string | Buffer, encoding: string, cb: () => void): void;
_final(cb: () => void): void;
_write(chunk: string | Buffer, encoding: string, callback: () => void): void;
_final(callback: () => void): void;
}
//# sourceMappingURL=WritableStream.d.ts.map

@@ -24,4 +24,4 @@ "use strict";

*/
var stream_1 = require("stream");
var string_decoder_1 = require("string_decoder");
var node_stream_1 = require("node:stream");
var node_string_decoder_1 = require("node:string_decoder");
// Following the example in https://nodejs.org/api/stream.html#stream_decoding_buffers_in_a_writable_stream

@@ -40,17 +40,17 @@ function isBuffer(_chunk, encoding) {

var _this = _super.call(this, { decodeStrings: false }) || this;
_this._decoder = new string_decoder_1.StringDecoder();
_this._decoder = new node_string_decoder_1.StringDecoder();
_this._parser = new Parser_js_1.Parser(cbs, options);
return _this;
}
WritableStream.prototype._write = function (chunk, encoding, cb) {
WritableStream.prototype._write = function (chunk, encoding, callback) {
this._parser.write(isBuffer(chunk, encoding) ? this._decoder.write(chunk) : chunk);
cb();
callback();
};
WritableStream.prototype._final = function (cb) {
WritableStream.prototype._final = function (callback) {
this._parser.end(this._decoder.end());
cb();
callback();
};
return WritableStream;
}(stream_1.Writable));
}(node_stream_1.Writable));
exports.WritableStream = WritableStream;
//# sourceMappingURL=WritableStream.js.map
{
"name": "htmlparser2",
"description": "Fast & forgiving HTML/XML parser",
"version": "8.0.1",
"version": "8.0.2",
"author": "Felix Boehm <me@feedic.com>",

@@ -65,17 +65,19 @@ "funding": [

"domelementtype": "^2.3.0",
"domhandler": "^5.0.2",
"domhandler": "^5.0.3",
"domutils": "^3.0.1",
"entities": "^4.3.0"
"entities": "^4.4.0"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^17.0.30",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"jest": "^27.5.1",
"prettier": "^2.6.2",
"ts-jest": "^27.1.4",
"typescript": "^4.6.4"
"@types/jest": "^29.5.0",
"@types/node": "^18.15.5",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-unicorn": "^46.0.0",
"jest": "^29.5.0",
"prettier": "^2.8.6",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
},

@@ -87,3 +89,6 @@ "jest": {

"moduleNameMapper": {
"^(.*)\\.js$": "$1"
"^(.*)\\.js$": [
"$1",
"$1.js"
]
}

@@ -90,0 +95,0 @@ },

# htmlparser2
[![NPM version](http://img.shields.io/npm/v/htmlparser2.svg?style=flat)](https://npmjs.org/package/htmlparser2)
[![Downloads](https://img.shields.io/npm/dm/htmlparser2.svg?style=flat)](https://npmjs.org/package/htmlparser2)
[![Build Status](https://img.shields.io/github/workflow/status/fb55/htmlparser2/Node.js%20Test?label=tests&style=flat)](https://github.com/fb55/htmlparser2/actions?query=workflow%3A%22Node.js+Test%22)
[![Coverage](http://img.shields.io/coveralls/fb55/htmlparser2.svg?style=flat)](https://coveralls.io/r/fb55/htmlparser2)
[![NPM version](https://img.shields.io/npm/v/htmlparser2.svg)](https://npmjs.org/package/htmlparser2)
[![Downloads](https://img.shields.io/npm/dm/htmlparser2.svg)](https://npmjs.org/package/htmlparser2)
[![Node.js CI](https://github.com/fb55/htmlparser2/actions/workflows/nodejs-test.yml/badge.svg)](https://github.com/fb55/htmlparser2/actions/workflows/nodejs-test.yml)
[![Coverage](https://img.shields.io/coveralls/fb55/htmlparser2.svg)](https://coveralls.io/r/fb55/htmlparser2)

@@ -16,3 +16,3 @@ The fast & forgiving HTML/XML parser.

A live demo of `htmlparser2` is available [here](https://astexplorer.net/#/2AmVrGuGVJ).
A live demo of `htmlparser2` is available [on AST Explorer](https://astexplorer.net/#/2AmVrGuGVJ).

@@ -35,4 +35,5 @@ ## Ecosystem

```javascript
const htmlparser2 = require("htmlparser2");
```js
import * as htmlparser2 from "htmlparser2";
const parser = new htmlparser2.Parser({

@@ -55,3 +56,3 @@ onopentag(name, attributes) {

* Note that this can fire at any point within text and you might
* have to stich together multiple pieces.
* have to stitch together multiple pieces.
*/

@@ -74,3 +75,3 @@ console.log("-->", text);

parser.write(
"Xyz <script type='text/javascript'>const foo = '<<bar>>';</ script>"
"Xyz <script type='text/javascript'>const foo = '<<bar>>';</script>"
);

@@ -97,4 +98,5 @@ parser.end();

```javascript
const { WritableStream } = require("htmlparser2/lib/WritableStream");
```js
import { WritableStream } from "htmlparser2/lib/WritableStream";
const parserStream = new WritableStream({

@@ -115,3 +117,3 @@ ontext(text) {

```js
const htmlparser2 = require("htmlparser2");
import * as htmlparser2 from "htmlparser2";

@@ -158,3 +160,3 @@ const dom = htmlparser2.parseDocument(htmlString);

In 2011, this module started as a fork of the `htmlparser` module.
`htmlparser2` was rewritten multiple times and, while it maintains an API that's mostly compatible with `htmlparser` in most cases, the projects don't share any code anymore.
`htmlparser2` was rewritten multiple times and, while it maintains an API that's mostly compatible with `htmlparser`, the projects don't share any code anymore.

@@ -164,4 +166,6 @@ The parser now provides a callback interface inspired by [sax.js](https://github.com/isaacs/sax-js) (originally targeted at [readabilitySAX](https://github.com/fb55/readabilitysax)).

The `DefaultHandler` and the `RssHandler` were renamed to clarify their purpose (to `DomHandler` and `FeedHandler`). The old names are still available when requiring `htmlparser2`, your code should work as expected.
The `DefaultHandler` was renamed to clarify its purpose (to `DomHandler`). The old name is still available when requiring `htmlparser2` and your code should work as expected.
The `RssHandler` was replaced with a `getFeed` function that takes a `DomHandler` DOM and returns a feed object. There is a `parseFeed` helper function that can be used to parse a feed from a string.
## Security contact information

@@ -174,4 +178,4 @@

Available as part of the Tidelift Subscription
Available as part of the Tidelift Subscription.
The maintainers of `htmlparser2` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-htmlparser2?utm_source=npm-htmlparser2&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)

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

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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc