diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index e8e6ca9..bccddb7 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/Cargo.lock b/Cargo.lock index 14a1d89..9be5f61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -207,7 +207,7 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "kuchikiki" version = "0.8.2" -source = "git+https://github.com/xusd320/kuchikiki.git?rev=c671c7b#c671c7b88bb3256ac74995cda83f37c782f6d4ab" +source = "git+https://github.com/xusd320/kuchikiki.git?rev=f1b69c1#f1b69c1a68d053f0d2c61a886e2977837b0a69ff" dependencies = [ "cssparser", "html5ever", diff --git a/Cargo.toml b/Cargo.toml index f2513d8..d29ce67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" [workspace.dependencies] html5ever = "0.27.0" indexmap = "2.2.6" -kuchikiki = { git = "https://github.com/xusd320/kuchikiki.git", rev = "c671c7b" } +kuchikiki = { git = "https://github.com/xusd320/kuchikiki.git", rev = "f1b69c1" } [profile.release] lto = true diff --git a/README.md b/README.md index 7731942..77630ee 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,20 @@ Clone this node to a new instance, including its all descendants. [index.d.ts:92](https://github.com/umijs/niddle/blob/main/index.d.ts#L92) +##### constructor() + +> **constructor**(): `void` + +The node object, cann't be instantiated in javascript. So call the constructor will throw an error + +###### Returns + +`void` + +###### Defined in + +[index.d.ts:96](https://github.com/umijs/niddle/blob/main/index.d.ts#L96) + ##### getAttribute() > **getAttribute**(`name`): `string` @@ -340,9 +354,11 @@ Remove an attribute of this node by name ##### select() +###### select(selectors) + > **select**(`selectors`): [`NodeRepr`](README.md#noderepr) -Select the the fist node that match the given selector, like document.querySelector. +Select the the fist node that match the given css selector, like document.querySelector. ###### Parameters @@ -358,11 +374,65 @@ Select the the fist node that match the given selector, like document.querySelec [index.d.ts:68](https://github.com/umijs/niddle/blob/main/index.d.ts#L68) +###### select(selectors) + +> **select**(`selectors`): [`NodeRepr`](README.md#noderepr) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `selectors` | `"html"` | + +###### Returns + +[`NodeRepr`](README.md#noderepr) + +###### Defined in + +[index.d.ts:97](https://github.com/umijs/niddle/blob/main/index.d.ts#L97) + +###### select(selectors) + +> **select**(`selectors`): [`NodeRepr`](README.md#noderepr) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `selectors` | `"head"` | + +###### Returns + +[`NodeRepr`](README.md#noderepr) + +###### Defined in + +[index.d.ts:98](https://github.com/umijs/niddle/blob/main/index.d.ts#L98) + +###### select(selectors) + +> **select**(`selectors`): [`NodeRepr`](README.md#noderepr) + +###### Parameters + +| Parameter | Type | +| ------ | ------ | +| `selectors` | `"body"` | + +###### Returns + +[`NodeRepr`](README.md#noderepr) + +###### Defined in + +[index.d.ts:99](https://github.com/umijs/niddle/blob/main/index.d.ts#L99) + ##### selectAll() > **selectAll**(`selectors`): [`NodeRepr`](README.md#noderepr)[] -Select all nodes that match the given selector, like document.querySelectorAll. +Select all nodes that match the given css selector, like document.querySelectorAll. ###### Parameters diff --git a/crates/niddle_napi/src/node_repr/query.rs b/crates/niddle_napi/src/node_repr/query.rs index f890111..c381a8c 100644 --- a/crates/niddle_napi/src/node_repr/query.rs +++ b/crates/niddle_napi/src/node_repr/query.rs @@ -8,13 +8,13 @@ use super::NodeRepr; #[napi] impl NodeRepr { - /// Select the the fist node that match the given selector, like document.querySelector. + /// Select the the fist node that match the given css selector, like document.querySelector. #[napi] pub fn select(&self, selectors: String) -> Option { self.0.select_first(&selectors).ok().map(Into::into) } - /// Select all nodes that match the given selector, like document.querySelectorAll. + /// Select all nodes that match the given css selector, like document.querySelectorAll. #[napi] pub fn select_all(&self, selectors: String) -> Vec { self diff --git a/index.d.ts b/index.d.ts index f995f98..f631c49 100644 --- a/index.d.ts +++ b/index.d.ts @@ -64,9 +64,9 @@ export declare class NodeRepr { removeAttribute(name: string): void /** Remove all attributes of this node */ removeAllAttributes(): void - /** Select the the fist node that match the given selector, like document.querySelector. */ + /** Select the the fist node that match the given css selector, like document.querySelector. */ select(selectors: string): NodeRepr | null - /** Select all nodes that match the given selector, like document.querySelectorAll. */ + /** Select all nodes that match the given css selector, like document.querySelectorAll. */ selectAll(selectors: string): Array /** Get all children nodes of this node. */ getChildren(): Array @@ -91,3 +91,10 @@ export declare class NodeRepr { /** Clone this node to a new instance, including its all descendants. */ cloneRecursive(): NodeRepr } +export declare interface NodeRepr { + /** The node object, cann't be instantiated in javascript. So call the constructor will throw an error */ + constructor(): void; + select(selectors: "html"): NodeRepr; + select(selectors: "head"): NodeRepr; + select(selectors: "body"): NodeRepr; +} diff --git a/package.json b/package.json index 5adacab..bd88691 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,17 @@ ] } }, + "keywords": [ + "htmlparser", + "jquery", + "selector", + "scraper", + "parser", + "dom", + "html", + "rust", + "napi" + ], "license": "MIT", "devDependencies": { "@napi-rs/cli": "^2.18.4", @@ -53,14 +64,14 @@ "artifacts": "napi artifacts", "build": "napi build --platform --release --cargo-name niddle_napi", "build:debug": "napi build --platform --cargo-name niddle_napi", - "prepublishOnly": "yarn patchdts && napi prepublish -t npm", + "prepublishOnly": "yarn patchdts && yarn docs && napi prepublish -t npm", "universal": "napi universal", "version": "napi version", "test": "ava", "patchdts": "cat ./patch.d.ts >> ./index.d.ts", "benchmark": "node ./benchmark/benchmark.mjs", "prepare": "husky install", - "docs": "npx typedoc ./index.d.ts && mv ./docs/README.md ./README.md" + "docs": "npx typedoc && mv ./docs/README.md ./README.md" }, "repository": "https://github.com/umijs/niddle", "packageManager": "yarn@4.3.1",