node-html-parser 4.1.4 → 5.2.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/esm/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import nhp from '../dist/index.js'
2
+
3
+ export const CommentNode = nhp.CommentNode;
4
+ export const HTMLElement = nhp.HTMLElement;
5
+ export const parse = nhp.parse;
6
+ export const valid = nhp.valid;
7
+ export const Node = nhp.Node;
8
+ export const TextNode = nhp.TextNode;
9
+ export const NodeType = nhp.NodeType;
10
+
11
+ export default nhp;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,22 +1,29 @@
1
1
  {
2
2
  "name": "node-html-parser",
3
- "version": "4.1.4",
3
+ "version": "5.2.0",
4
4
  "description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.",
5
5
  "main": "dist/index.js",
6
- "module": "dist/esm/index.js",
7
6
  "types": "dist/index.d.ts",
8
7
  "scripts": {
9
- "test": "mocha",
8
+ "compile": "tsc",
9
+ "build": "npm run lint && npm run clean && npm run compile:cjs && npm run compile:amd",
10
+ "compile:cjs": "tsc -m commonjs",
11
+ "compile:amd": "tsc -t es5 -m amd -d false --outFile ./dist/main.js",
10
12
  "lint": "eslint ./src/*.ts ./src/**/*.ts",
11
- "clean": "del-cli ./dist/",
12
- "ts:cjs": "tsc -m commonjs",
13
- "ts:amd": "tsc -t es5 -m amd -d false --outFile ./dist/main.js",
14
- "ts:esm": "tsc -t es2019 -m esnext -d false --outDir ./dist/esm/",
15
- "build": "npm run lint && npm run clean && npm run ts:cjs && npm run ts:amd && npm run ts:esm",
16
- "dev": "tsc -w & mocha -w ./test/*.js",
17
- "pretest": "tsc -m commonjs",
18
- "release": "yarn build && np",
19
- "prepare": "npm run build"
13
+ "---------------": "",
14
+ "test": "yarn run test:target",
15
+ "test:src": "cross-env TEST_TARGET=src yarn run test",
16
+ "test:dist": "cross-env TEST_TARGET=dist yarn run test",
17
+ "benchmark": "node ./test/benchmark/compare.mjs",
18
+ "--------------- ": "",
19
+ "clean": "npx rimraf ./dist/",
20
+ "clean:global": "yarn run clean && npx rimraf yarn.lock test/yarn.lock test/node_modules node_modules",
21
+ "reset": "yarn run clean:global && yarn install && yarn build",
22
+ "--------------- ": "",
23
+ "test:target": "mocha --recursive \"./test/tests\"",
24
+ "test:ci": "cross-env TEST_TARGET=dist yarn run test:target",
25
+ "posttest": "yarn run benchmark",
26
+ "prepare": "cd test && yarn install"
20
27
  },
21
28
  "keywords": [
22
29
  "parser",
@@ -24,9 +31,17 @@
24
31
  "nodejs",
25
32
  "typescript"
26
33
  ],
34
+ "files": [
35
+ "dist",
36
+ "esm",
37
+ "README.md",
38
+ "LICENSE",
39
+ "CHANGELOG.md"
40
+ ],
27
41
  "author": "Xiaoyi Shi <ashi009@gmail.com>",
28
42
  "contributors": [
29
- "taoqf<tao_qiufeng@126.com>"
43
+ "taoqf <tao_qiufeng@126.com>",
44
+ "Ron S. <ron@nonara.com>"
30
45
  ],
31
46
  "license": "MIT",
32
47
  "publishConfig": {
@@ -45,22 +60,32 @@
45
60
  "@typescript-eslint/parser": "latest",
46
61
  "blanket": "latest",
47
62
  "cheerio": "^1.0.0-rc.5",
48
- "del-cli": "latest",
49
- "eslint": "latest",
63
+ "cross-env": "^7.0.3",
64
+ "eslint": "^7.32.0",
50
65
  "eslint-config-prettier": "latest",
51
66
  "eslint-plugin-import": "latest",
52
67
  "high5": "^1.0.0",
68
+ "html-dom-parser": "^1.0.4",
69
+ "html-parser": "^0.11.0",
70
+ "html5": "^1.0.5",
71
+ "html5parser": "^2.0.2",
72
+ "htmljs-parser": "^2.11.1",
53
73
  "htmlparser": "^1.7.7",
54
74
  "htmlparser-benchmark": "^1.1.3",
55
75
  "htmlparser2": "^6.0.0",
56
76
  "mocha": "latest",
57
77
  "mocha-each": "^2.0.1",
78
+ "neutron-html5parser": "^0.2.0",
58
79
  "np": "latest",
59
80
  "parse5": "^6.0.1",
81
+ "rimraf": "^3.0.2",
82
+ "saxes": "^6.0.0",
60
83
  "should": "latest",
61
84
  "spec": "latest",
85
+ "standard-version": "^9.3.1",
62
86
  "travis-cov": "latest",
63
- "typescript": "next"
87
+ "ts-node": "^10.2.1",
88
+ "typescript": "latest"
64
89
  },
65
90
  "config": {
66
91
  "blanket": {
@@ -84,5 +109,9 @@
84
109
  "url": "https://github.com/taoqf/node-fast-html-parser/issues"
85
110
  },
86
111
  "homepage": "https://github.com/taoqf/node-fast-html-parser",
87
- "sideEffects": false
112
+ "sideEffects": false,
113
+ "exports": {
114
+ "require": "./dist/index.js",
115
+ "import": "./esm/index.js"
116
+ }
88
117
  }
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- test/
2
- dist/
3
- node_modules/
package/.eslintrc.json DELETED
@@ -1,226 +0,0 @@
1
- {
2
- "env": {
3
- "es6": true,
4
- "node": true
5
- },
6
- "extends": [
7
- "eslint:recommended",
8
- "plugin:@typescript-eslint/recommended",
9
- "plugin:@typescript-eslint/recommended-requiring-type-checking",
10
- "plugin:@typescript-eslint/eslint-recommended",
11
- "plugin:import/errors",
12
- "plugin:import/warnings",
13
- "plugin:import/typescript",
14
- "prettier"
15
- ],
16
- "parser": "@typescript-eslint/parser",
17
- "parserOptions": {
18
- "ecmaVersion": 2018,
19
- "sourceType": "module",
20
- "ecmaFeatures": {
21
- "impliedStrict": true,
22
- "jsx": true
23
- },
24
- "project": "tsconfig.json",
25
- "extraFileExtensions": [
26
- ".ts",
27
- ".tsx"
28
- ]
29
- },
30
- "plugins": [
31
- "import",
32
- "@typescript-eslint"
33
- ],
34
- "rules": {
35
- "no-prototype-builtins": "off",
36
- "@typescript-eslint/explicit-module-boundary-types": "off",
37
- "arrow-parens": [
38
- "off"
39
- ],
40
- "brace-style": [
41
- "off",
42
- "stroustrup"
43
- ],
44
- "consistent-return": "off",
45
- "camelcase": "off",
46
- "@typescript-eslint/camelcase": "off",
47
- "curly": [
48
- "error",
49
- "multi-line",
50
- "consistent"
51
- ],
52
- "eol-last": "error",
53
- "linebreak-style": [
54
- "error",
55
- "unix"
56
- ],
57
- "new-parens": "error",
58
- "no-console": "off",
59
- "no-constant-condition": [
60
- "warn",
61
- {
62
- "checkLoops": false
63
- }
64
- ],
65
- "no-caller": "error",
66
- "no-debugger": "warn",
67
- "no-dupe-class-members": "off",
68
- "no-duplicate-imports": "error",
69
- "no-else-return": "warn",
70
- "no-empty": [
71
- "warn",
72
- {
73
- "allowEmptyCatch": true
74
- }
75
- ],
76
- "no-eval": "error",
77
- "no-ex-assign": "warn",
78
- "no-extend-native": "error",
79
- "no-extra-bind": "error",
80
- "no-floating-decimal": "error",
81
- "no-implicit-coercion": "error",
82
- "no-implied-eval": "error",
83
- // Turn off until fix for: https://github.com/typescript-eslint/typescript-eslint/issues/239
84
- "no-inner-declarations": "off",
85
- "no-lone-blocks": "error",
86
- "no-lonely-if": "error",
87
- "no-loop-func": "error",
88
- "no-multi-spaces": "error",
89
- "no-return-assign": "error",
90
- "no-return-await": "warn",
91
- "no-self-compare": "error",
92
- "no-sequences": "error",
93
- "no-template-curly-in-string": "warn",
94
- "no-throw-literal": "error",
95
- "no-unmodified-loop-condition": "warn",
96
- "no-unneeded-ternary": "error",
97
- "no-unused-expressions": [
98
- "warn",
99
- {
100
- "allowShortCircuit": true
101
- }
102
- ],
103
- "no-use-before-define": "off",
104
- "no-useless-call": "error",
105
- "no-useless-catch": "error",
106
- "no-useless-computed-key": "error",
107
- "no-useless-concat": "error",
108
- "no-useless-rename": "error",
109
- "no-useless-return": "error",
110
- "no-var": "error",
111
- "no-with": "error",
112
- "object-shorthand": "off",
113
- "one-var": [
114
- "error",
115
- "never"
116
- ],
117
- "prefer-arrow-callback": "error",
118
- "prefer-const": "error",
119
- "prefer-numeric-literals": "error",
120
- "prefer-object-spread": "error",
121
- "prefer-rest-params": "error",
122
- "prefer-spread": "error",
123
- "prefer-template": "error",
124
- "quotes": "off",
125
- // Turn off until fix for: https://github.com/eslint/eslint/issues/11899
126
- "require-atomic-updates": "off",
127
- "semi": [
128
- "error",
129
- "always"
130
- ],
131
- "semi-style": [
132
- "error",
133
- "last"
134
- ],
135
- "sort-imports": [
136
- "error",
137
- {
138
- "ignoreCase": true,
139
- "ignoreDeclarationSort": true,
140
- "ignoreMemberSort": false,
141
- "memberSyntaxSortOrder": [
142
- "none",
143
- "all",
144
- "multiple",
145
- "single"
146
- ]
147
- }
148
- ],
149
- "yoda": "error",
150
- "import/export": "off",
151
- "import/extensions": [
152
- "error",
153
- "never"
154
- ],
155
- "import/named": "off",
156
- "import/namespace": "off",
157
- "import/newline-after-import": "warn",
158
- "import/no-cycle": "off",
159
- "import/no-dynamic-require": "error",
160
- "import/no-default-export": "off",
161
- "import/no-duplicates": "error",
162
- "import/no-self-import": "error",
163
- "import/no-unresolved": [
164
- "warn",
165
- {
166
- "ignore": [
167
- "vscode"
168
- ]
169
- }
170
- ],
171
- "import/order": [
172
- "warn",
173
- {
174
- "groups": [
175
- "builtin",
176
- "external",
177
- "internal",
178
- [
179
- "index",
180
- "sibling",
181
- "parent"
182
- ]
183
- ]
184
- }
185
- ],
186
- "@typescript-eslint/require-await": "off",
187
- "@typescript-eslint/consistent-type-assertions": "off",
188
- "@typescript-eslint/explicit-function-return-type": "off",
189
- "@typescript-eslint/explicit-member-accessibility": "error",
190
- "@typescript-eslint/interface-name-prefix": "off",
191
- "@typescript-eslint/no-empty-function": [
192
- "warn",
193
- {
194
- "allow": [
195
- "constructors"
196
- ]
197
- }
198
- ],
199
- "@typescript-eslint/no-empty-interface": "off",
200
- "@typescript-eslint/no-explicit-any": "error",
201
- "@typescript-eslint/no-inferrable-types": [
202
- "warn",
203
- {
204
- "ignoreParameters": true,
205
- "ignoreProperties": true
206
- }
207
- ],
208
- "@typescript-eslint/no-misused-promises": [
209
- "error",
210
- {
211
- "checksVoidReturn": false
212
- }
213
- ],
214
- "@typescript-eslint/no-namespace": "off",
215
- "@typescript-eslint/no-non-null-assertion": "off",
216
- "@typescript-eslint/no-parameter-properties": "off",
217
- "@typescript-eslint/no-unused-vars": [
218
- "warn",
219
- {
220
- "args": "none"
221
- }
222
- ],
223
- "@typescript-eslint/no-use-before-define": "off",
224
- "@typescript-eslint/unbound-method": "off" // Too many bugs right now: https://github.com/typescript-eslint/typescript-eslint/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+unbound-method
225
- }
226
- }
package/.mocharc.yaml DELETED
@@ -1 +0,0 @@
1
- require: blanket,should,spec
package/dist/esm/back.js DELETED
@@ -1,3 +0,0 @@
1
- export default function arr_back(arr) {
2
- return arr[arr.length - 1];
3
- }
package/dist/esm/index.js DELETED
@@ -1,7 +0,0 @@
1
- export { default as CommentNode } from './nodes/comment';
2
- export { default as HTMLElement } from './nodes/html';
3
- export { default as parse, default } from './parse';
4
- export { default as valid } from './valid';
5
- export { default as Node } from './nodes/node';
6
- export { default as TextNode } from './nodes/text';
7
- export { default as NodeType } from './nodes/type';
@@ -1,101 +0,0 @@
1
- import NodeType from './nodes/type';
2
- function isTag(node) {
3
- return node && node.nodeType === NodeType.ELEMENT_NODE;
4
- }
5
- function getAttributeValue(elem, name) {
6
- return isTag(elem) ? elem.getAttribute(name) : undefined;
7
- }
8
- function getName(elem) {
9
- return ((elem && elem.rawTagName) || '').toLowerCase();
10
- }
11
- function getChildren(node) {
12
- return node && node.childNodes;
13
- }
14
- function getParent(node) {
15
- return node ? node.parentNode : null;
16
- }
17
- function getText(node) {
18
- return node.text;
19
- }
20
- function removeSubsets(nodes) {
21
- let idx = nodes.length;
22
- let node;
23
- let ancestor;
24
- let replace;
25
- // Check if each node (or one of its ancestors) is already contained in the
26
- // array.
27
- while (--idx > -1) {
28
- node = ancestor = nodes[idx];
29
- // Temporarily remove the node under consideration
30
- nodes[idx] = null;
31
- replace = true;
32
- while (ancestor) {
33
- if (nodes.indexOf(ancestor) > -1) {
34
- replace = false;
35
- nodes.splice(idx, 1);
36
- break;
37
- }
38
- ancestor = getParent(ancestor);
39
- }
40
- // If the node has been found to be unique, re-insert it.
41
- if (replace) {
42
- nodes[idx] = node;
43
- }
44
- }
45
- return nodes;
46
- }
47
- function existsOne(test, elems) {
48
- return elems.some((elem) => {
49
- return isTag(elem) ? test(elem) || existsOne(test, getChildren(elem)) : false;
50
- });
51
- }
52
- function getSiblings(node) {
53
- const parent = getParent(node);
54
- return parent && getChildren(parent);
55
- }
56
- function hasAttrib(elem, name) {
57
- return getAttributeValue(elem, name) !== undefined;
58
- }
59
- function findOne(test, elems) {
60
- let elem = null;
61
- for (let i = 0, l = elems.length; i < l && !elem; i++) {
62
- const el = elems[i];
63
- if (test(el)) {
64
- elem = el;
65
- }
66
- else {
67
- const childs = getChildren(el);
68
- if (childs && childs.length > 0) {
69
- elem = findOne(test, childs);
70
- }
71
- }
72
- }
73
- return elem;
74
- }
75
- function findAll(test, nodes) {
76
- let result = [];
77
- for (let i = 0, j = nodes.length; i < j; i++) {
78
- if (!isTag(nodes[i]))
79
- continue;
80
- if (test(nodes[i]))
81
- result.push(nodes[i]);
82
- const childs = getChildren(nodes[i]);
83
- if (childs)
84
- result = result.concat(findAll(test, childs));
85
- }
86
- return result;
87
- }
88
- export default {
89
- isTag,
90
- getAttributeValue,
91
- getName,
92
- getChildren,
93
- getParent,
94
- getText,
95
- removeSubsets,
96
- existsOne,
97
- getSiblings,
98
- hasAttrib,
99
- findOne,
100
- findAll
101
- };
@@ -1,23 +0,0 @@
1
- import Node from './node';
2
- import NodeType from './type';
3
- export default class CommentNode extends Node {
4
- constructor(rawText, parentNode, range) {
5
- super(parentNode, range);
6
- this.rawText = rawText;
7
- /**
8
- * Node Type declaration.
9
- * @type {Number}
10
- */
11
- this.nodeType = NodeType.COMMENT_NODE;
12
- }
13
- /**
14
- * Get unescaped text value of current node and its children.
15
- * @return {string} text content
16
- */
17
- get text() {
18
- return this.rawText;
19
- }
20
- toString() {
21
- return `<!--${this.rawText}-->`;
22
- }
23
- }