Skip to content

Commit

Permalink
refactor: deps and docs (#1)
Browse files Browse the repository at this point in the history
* chore: update deps and docs

* chore: remove extar optionalDeps in package.json

* chore: update yarn install
  • Loading branch information
xusd320 authored Jul 22, 2024
1 parent 471a715 commit d737976
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 10 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions crates/niddle_napi/src/node_repr/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeRepr> {
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<NodeRepr> {
self
Expand Down
11 changes: 9 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeRepr>
/** Get all children nodes of this node. */
getChildren(): Array<NodeRepr>
Expand All @@ -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;
}
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
]
}
},
"keywords": [
"htmlparser",
"jquery",
"selector",
"scraper",
"parser",
"dom",
"html",
"rust",
"napi"
],
"license": "MIT",
"devDependencies": {
"@napi-rs/cli": "^2.18.4",
Expand All @@ -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": "[email protected]",
Expand Down

0 comments on commit d737976

Please sign in to comment.