gumbo-html 0.1.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2021 Weidong Fang
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
19
+ OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ CSS selector based on Gumbo HTML parser.
2
+
3
+ ## Installation
4
+ ```
5
+ $ npm install gumbo-html
6
+ ```
7
+
8
+ ## Usage
9
+
10
+ Example:
11
+ ```ts
12
+ import {parse} from 'gumbo-html';
13
+
14
+ const html = `
15
+ <html>
16
+ <p class="foo bar blah">Foo</p>
17
+ <p class="bar">Bar</p>
18
+ </html>
19
+ `
20
+
21
+ const xdoc = parse(html);
22
+
23
+ xdoc.find('.bar').forEach(el => {
24
+ console.log(el.innerText)
25
+ });
26
+ ```
package/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ export declare type NodeType = 'DOCUMENT' | 'ELEMENT' | 'TEXT' | 'CDATA' | 'COMMENT' | 'WHITESPACE' | 'TEMPLATE' | 'UNKNOWN';
2
+
3
+ export declare type XElement = {
4
+ childNodes: XElement[];
5
+ nodeType: NodeType;
6
+ parent: Element | null;
7
+ outerHTML: string;
8
+ innerText: string;
9
+ tagName: string | null;
10
+
11
+ attr: (name: string) => string | undefined;
12
+ attr_s: (name: string) => string;
13
+ find: (selector: string) => XElement[];
14
+ first: (selector: string) => XElement | null;
15
+ first_s: (selector: string) => XElement;
16
+ hasClass: (name: string) => boolean;
17
+ hasAttribute: (name: string) => boolean;
18
+ prev: (selector: string) => XElement | null;
19
+ next: (selector: string) => XElement | null;
20
+ };
21
+
22
+ export declare type XDocument = {
23
+ documentElement: XElement;
24
+ outerHTML: string;
25
+ innerText: string;
26
+ tagName: string | null;
27
+ find: (selector: string) => XElement[]
28
+ first: (selector: string) => XElement | null;
29
+ first_s: (selector: string) => XElement;
30
+ };
31
+
32
+ export declare function parse(html: string): XDocument;
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ const html = require('./html');
2
+ module.exports = html;
package/install.js ADDED
@@ -0,0 +1,15 @@
1
+ const https = require("https");
2
+ const fs = require("fs");
3
+ const os = require("os");
4
+ const path = require("path");
5
+
6
+ const libs = "https://raw.githubusercontent.com/fangwd/gumbo-html/main/libs";
7
+ const url = `${libs}/${process.platform}/${os.arch()}/html.node`;
8
+ const file = fs.createWriteStream(path.join(__dirname, "html.node"));
9
+
10
+ https.get(url, (response) => {
11
+ response.pipe(file);
12
+ file.on("finish", () => {
13
+ file.close();
14
+ });
15
+ });
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "gumbo-html",
3
+ "version": "0.1.0",
4
+ "description": "Node.js CSS Selector Based on Gumbo Parser",
5
+ "main": "index.js",
6
+ "files": [
7
+ "index.js",
8
+ "index.d.ts",
9
+ "install.js",
10
+ "LICENSE",
11
+ "package.json",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "postinstall": "install.js"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/fangwd/gumbo-html.git"
20
+ },
21
+ "keywords": ["Gumbo Parser", "CSS Selector", "HTML Parser"],
22
+ "author": "Weidong Fang",
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://github.com/fangwd/gumbo-html/issues"
26
+ },
27
+ "homepage": "https://github.com/fangwd/gumbo-html"
28
+ }