parse5-parser-stream 7.1.2 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
  <br>
17
17
 
18
18
  <p align="center">
19
- 📖 <a href="https://parse5.js.org/modules/parse5_parser_stream.html"><b>Documentation</b></a> 📖
19
+ 📖 <a href="https://parse5.js.org/modules/parse5-parser-stream.html"><b>Documentation</b></a> 📖
20
20
  </p>
21
21
 
22
22
  ---
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { Writable } from 'node:stream';
3
2
  import { Parser, type ParserOptions, type TreeAdapterTypeMap, type DefaultTreeAdapterMap } from 'parse5';
4
3
  /**
@@ -82,4 +81,3 @@ export interface ParserStream<T extends TreeAdapterTypeMap = DefaultTreeAdapterM
82
81
  */
83
82
  on(event: string, handler: (...args: any[]) => void): this;
84
83
  }
85
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Writable } from 'node:stream';
2
2
  import { Parser } from 'parse5';
3
- /* eslint-disable unicorn/consistent-function-scoping -- The rule seems to be broken here. */
4
3
  /**
5
4
  * Streaming HTML parser with scripting support.
6
5
  * A [writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable).
@@ -83,4 +82,3 @@ export class ParserStream extends Writable {
83
82
  super.end(chunk || '', encoding, callback);
84
83
  }
85
84
  }
86
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "name": "parse5-parser-stream",
3
3
  "type": "module",
4
4
  "description": "Streaming HTML parser with scripting support.",
5
- "version": "7.1.2",
5
+ "version": "8.0.0",
6
6
  "author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)",
7
7
  "contributors": "https://github.com/inikulin/parse5/graphs/contributors",
8
- "homepage": "https://github.com/inikulin/parse5",
8
+ "homepage": "https://parse5.js.org",
9
9
  "funding": "https://github.com/inikulin/parse5?sponsor=1",
10
10
  "keywords": [
11
11
  "parse5",
@@ -14,25 +14,23 @@
14
14
  "streaming"
15
15
  ],
16
16
  "license": "MIT",
17
- "main": "dist/cjs/index.js",
17
+ "main": "dist/index.js",
18
18
  "module": "dist/index.js",
19
19
  "types": "dist/index.d.ts",
20
20
  "exports": {
21
- "import": "./dist/index.js",
22
- "require": "./dist/cjs/index.js"
21
+ ".": {
22
+ "default": "./dist/index.js"
23
+ }
23
24
  },
24
25
  "dependencies": {
25
- "parse5": "^7.0.0"
26
- },
27
- "scripts": {
28
- "build:cjs": "tsc --module CommonJS --target ES6 --outDir dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json"
26
+ "parse5": "^8.0.0"
29
27
  },
28
+ "scripts": {},
30
29
  "repository": {
31
30
  "type": "git",
32
31
  "url": "git://github.com/inikulin/parse5.git"
33
32
  },
34
33
  "files": [
35
- "dist/cjs/package.json",
36
34
  "dist/**/*.js",
37
35
  "dist/**/*.d.ts"
38
36
  ]
@@ -1,85 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { Writable } from 'node:stream';
3
- import { Parser, type ParserOptions, type TreeAdapterTypeMap, type DefaultTreeAdapterMap } from 'parse5';
4
- /**
5
- * Streaming HTML parser with scripting support.
6
- * A [writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable).
7
- *
8
- * @example
9
- *
10
- * ```js
11
- * const ParserStream = require('parse5-parser-stream');
12
- * const http = require('http');
13
- * const { finished } = require('node:stream');
14
- *
15
- * // Fetch the page content and obtain it's <head> node
16
- * http.get('http://inikulin.github.io/parse5/', res => {
17
- * const parser = new ParserStream();
18
- *
19
- * finished(parser, () => {
20
- * console.log(parser.document.childNodes[1].childNodes[0].tagName); //> 'head'
21
- * });
22
- *
23
- * res.pipe(parser);
24
- * });
25
- * ```
26
- *
27
- */
28
- export declare class ParserStream<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap> extends Writable {
29
- parser: Parser<T>;
30
- static getFragmentStream<T extends TreeAdapterTypeMap>(fragmentContext?: T['parentNode'] | null, options?: ParserOptions<T>): ParserStream<T>;
31
- private lastChunkWritten;
32
- private writeCallback;
33
- private pendingHtmlInsertions;
34
- /** The resulting document node. */
35
- get document(): T['document'];
36
- getFragment(): T['documentFragment'];
37
- /**
38
- * @param options Parsing options.
39
- */
40
- constructor(options?: ParserOptions<T>, parser?: Parser<T>);
41
- _write(chunk: string, _encoding: string, callback: () => void): void;
42
- end(chunk?: any, encoding?: any, callback?: any): any;
43
- }
44
- export interface ParserStream<T extends TreeAdapterTypeMap = DefaultTreeAdapterMap> {
45
- /**
46
- * Raised when parser encounters a `<script>` element. If this event has listeners, parsing will be suspended once
47
- * it is emitted. So, if `<script>` has the `src` attribute, you can fetch it, execute and then resume parsing just
48
- * like browsers do.
49
- *
50
- * @example
51
- *
52
- * ```js
53
- * const ParserStream = require('parse5-parser-stream');
54
- * const http = require('http');
55
- *
56
- * const parser = new ParserStream();
57
- *
58
- * parser.on('script', (scriptElement, documentWrite, resume) => {
59
- * const src = scriptElement.attrs.find(({ name }) => name === 'src').value;
60
- *
61
- * http.get(src, res => {
62
- * // Fetch the script content, execute it with DOM built around `parser.document` and
63
- * // `document.write` implemented using `documentWrite`.
64
- * ...
65
- * // Then resume parsing.
66
- * resume();
67
- * });
68
- * });
69
- *
70
- * parser.end('<script src="example.com/script.js"></script>');
71
- * ```
72
- *
73
- * @param event Name of the event
74
- * @param handler
75
- */
76
- on(event: 'script', handler: (scriptElement: T['element'], documentWrite: (html: string) => void, resume: () => void) => void): void;
77
- /**
78
- * Base event handler.
79
- *
80
- * @param event Name of the event
81
- * @param handler Event handler
82
- */
83
- on(event: string, handler: (...args: any[]) => void): this;
84
- }
85
- //# sourceMappingURL=index.d.ts.map
package/dist/cjs/index.js DELETED
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParserStream = void 0;
4
- const node_stream_1 = require("node:stream");
5
- const parse5_1 = require("parse5");
6
- /* eslint-disable unicorn/consistent-function-scoping -- The rule seems to be broken here. */
7
- /**
8
- * Streaming HTML parser with scripting support.
9
- * A [writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable).
10
- *
11
- * @example
12
- *
13
- * ```js
14
- * const ParserStream = require('parse5-parser-stream');
15
- * const http = require('http');
16
- * const { finished } = require('node:stream');
17
- *
18
- * // Fetch the page content and obtain it's <head> node
19
- * http.get('http://inikulin.github.io/parse5/', res => {
20
- * const parser = new ParserStream();
21
- *
22
- * finished(parser, () => {
23
- * console.log(parser.document.childNodes[1].childNodes[0].tagName); //> 'head'
24
- * });
25
- *
26
- * res.pipe(parser);
27
- * });
28
- * ```
29
- *
30
- */
31
- class ParserStream extends node_stream_1.Writable {
32
- static getFragmentStream(fragmentContext, options) {
33
- const parser = parse5_1.Parser.getFragmentParser(fragmentContext, options);
34
- const stream = new ParserStream(options, parser);
35
- return stream;
36
- }
37
- /** The resulting document node. */
38
- get document() {
39
- return this.parser.document;
40
- }
41
- getFragment() {
42
- return this.parser.getFragment();
43
- }
44
- /**
45
- * @param options Parsing options.
46
- */
47
- constructor(options, parser = new parse5_1.Parser(options)) {
48
- super({ decodeStrings: false });
49
- this.parser = parser;
50
- this.lastChunkWritten = false;
51
- this.writeCallback = undefined;
52
- this.pendingHtmlInsertions = [];
53
- const resume = () => {
54
- for (let i = this.pendingHtmlInsertions.length - 1; i >= 0; i--) {
55
- this.parser.tokenizer.insertHtmlAtCurrentPos(this.pendingHtmlInsertions[i]);
56
- }
57
- this.pendingHtmlInsertions.length = 0;
58
- //NOTE: keep parsing if we don't wait for the next input chunk
59
- this.parser.tokenizer.resume(this.writeCallback);
60
- };
61
- const documentWrite = (html) => {
62
- if (!this.parser.stopped) {
63
- this.pendingHtmlInsertions.push(html);
64
- }
65
- };
66
- const scriptHandler = (scriptElement) => {
67
- if (this.listenerCount('script') > 0) {
68
- this.parser.tokenizer.pause();
69
- this.emit('script', scriptElement, documentWrite, resume);
70
- }
71
- };
72
- this.parser.scriptHandler = scriptHandler;
73
- }
74
- //WritableStream implementation
75
- _write(chunk, _encoding, callback) {
76
- if (typeof chunk !== 'string') {
77
- throw new TypeError('Parser can work only with string streams.');
78
- }
79
- this.writeCallback = callback;
80
- this.parser.tokenizer.write(chunk, this.lastChunkWritten, this.writeCallback);
81
- }
82
- // TODO [engine:node@>=16]: Due to issues with Node < 16, we are overriding `end` instead of `_final`.
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- end(chunk, encoding, callback) {
85
- this.lastChunkWritten = true;
86
- super.end(chunk || '', encoding, callback);
87
- }
88
- }
89
- exports.ParserStream = ParserStream;
90
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"type":"commonjs"}